Testing an integration
            
            #6826
          
          
        -
| 
         Hi! I'm working on an integration for breadcrumb support for pino(#4192). I've made a temporary repository for some fast testing, I've made the  import {Pino} from "../src/index";
import { EventHint, captureMessage, NodeClient } from "@sentry/node";
import pino from "pino";
import { createTransport, Hub } from '@sentry/core';
import { resolvedSyncPromise } from '@sentry/utils';
import { NodeClientOptions } from "@sentry/node/types/types";
import * as sentryCore from '@sentry/core';
const logger = pino();
export function getDefaultNodeClientOptions(options: Partial<NodeClientOptions> = {}): NodeClientOptions {
  return {
    integrations: [new Pino(logger)],
    transport: () => createTransport({ recordDroppedEvent: () => undefined }, _ => resolvedSyncPromise({})),
    stackParser: () => [],
    instrumenter: 'sentry',
    ...options,
  };
}
describe('basic', () => {
  it('foo', () => {
    let output: null | "beforeSend" = null;
    const options = getDefaultNodeClientOptions({
      beforeSend: (event, hint: EventHint) => {
        output = "beforeSend";
        return null;
      },
    })
    const client = new NodeClient(options);
    const hub = new Hub(client);
    sentryCore.makeMain(hub);
    logger.info({data: {"someData": "yes!"}}, "Log message");
    hub.captureException(new Error("Here is an error"));
    expect(output).toBe("beforeSend");
  });
});However: 
 I just want to test this, but without setting up a sentry project and having lots of side effects when I run the tests. I couldn't really find anything on how I can set up an integration and test it? Are there any good practices?  | 
  
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            Lilja
          
      
      
        Jan 17, 2023 
      
    
    Replies: 1 comment 2 replies
-
| 
         Don't forget  This worked for me: function getDefaultNodeClientOptions(
  options: Partial<NodeClientOptions> = {}
): NodeClientOptions {
  return {
    integrations: [new PinoSentry(logger)],
    transport: () =>
      createTransport({ recordDroppedEvent: () => undefined }, (_) =>
        resolvedSyncPromise({})
      ),
    stackParser: () => [],
    instrumenter: "sentry",
    ...options,
  };
}
let breadcrumbs: null | Breadcrumb[] = null;
const options = getDefaultNodeClientOptions({
  beforeSend: (event) => {
    if (event.breadcrumbs) {
      breadcrumbs = event.breadcrumbs;
    }
    return null;
  },
  dsn: SENTRY_DSN,
});
const client = new NodeClient(options);
const hub = new Hub(client);
sentryCore.makeMain(hub);
sentryCore.getCurrentHub().bindClient(client);
logger.info({ data: { someData: "yes!" } }, "Log message");
hub.captureException(new Error("Here comes the error")); | 
  
Beta Was this translation helpful? Give feedback.
                  
                    2 replies
                  
                
            
      Answer selected by
        Lilja
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Don't forget
dsn!This worked for me: