Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using? If you use the CDN bundles, please specify the exact bundle (e.g. bundle.tracing.min.js) in your SDK setup.
@sentry/nextjs
SDK Version
7.30.0
Framework Version
Next.js 12.3.2
Link to Sentry event
No response
SDK Setup
Sentry.init({enabled: isEnabled,dsn: SENTRY_DSN,environment: SENTRY_ENV,release: BUILD_ID,
ignoreErrors,beforeSend: event=>{const{ type, title, contexts }=event;if(type==='error'&&/^(?:iPhone|Mac|iPad)$/.test(contexts?.device?.family||'')&&(/^TypeError:(?:cancelled|geannuleerd|cancelado|annulleret|avbrutt|avbruten|Abgebrochen)$/i.test(title||''))){returnnull;}integrateWithFullstory(event);returnevent;},integrations: [newIntegrations.BrowserTracing({tracingOrigins: [getApiHost()],beforeNavigate: context=>{constdynamicRouteName=mapSlugToRoute(window.location.pathname);if(dynamicRouteName){return{
...context,name: dynamicRouteName,};}returncontext;},}),]tracesSampler: samplingRate,});Steps to Reproduce
- With Sentry SDK at any version 7.29.0 or earlier, run Jest tests; they pass
- Upgrade
@sentry/nextjs and @sentry/tracing and @sentry/utils to 7.30.0 or later - Run Jest tests; they fail
Expected Result
Our Jest tests pass.
Actual Result
Our Jest tests fail with several tests outputting ReferenceError: fetch is not defined at the line:
returnfetch(resolvePath(url),options)
Actual app works fine, only our Jest tests fail.
Since this failure starts in Sentry SDK 7.30.0, I think it likely has to do with #6500 — in particular the wrapping of fetch and its uses of this check and/or this wrapping utility, interacting poorly with whatever shenanigans Jest gets up to.
Likely relevant: jest.config.js
module.exports={transformIgnorePatterns: ["/node_modules/(?!@grid-is/)"],clearMocks: true,coverageDirectory: './coverage/',testEnvironment: 'jsdom',testMatch: ['**/__tests__/**/*.[jt]s?(x)','**/?(*.)+(spec|test).[tj]s?(x)','**/?(*-)+(test).[tj]s?(x)',],moduleNameMapper: {'\\.(css|scss)$': 'identity-obj-proxy',},reporters: ['default','jest-junit'],testPathIgnorePatterns: ['.next','<rootDir>/migrate/'],setupFiles: ['jest-canvas-mock'],setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect','./jest.setup.js'],globals: {...},};and jest.setup.js contains:
letunignorableConsoleErrorMessages;constoriginalError=global.console.error;constspy=jest.spyOn(global.console,'error');constinfoSpy=jest.spyOn(global.console,'info');// sprintf-like string format compatible with console.logconstsprintf=(str, ...argv)=>{if(!argv.length||!/%[sdif]/.test(str)){return[str, ...argv].join(' ');}returnsprintf(str.replace(/%[sdif]/,function(format){switch(format){case'%s': returnString(argv.shift());case'%d':
case'%i': returnparseInt(argv.shift(),10);case'%f': returnparseFloat(argv.shift(),10);default: returnformat;}}), ...argv);};constignorableConsoleErrorMessages=[/Can'tperformaReactstateupdateonanunmountedcomponent/,/Warning:Acomponentischanginganuncontrolledinputtobecontrolled./,/Warning:Functioncomponentscannotbegivenrefs.Attemptstoaccessthisrefwillfail.DidyoumeantouseReact.forwardRef()?/,];beforeEach(()=>{unignorableConsoleErrorMessages=newSet();spy.mockImplementation((...args)=>{originalError(...args);constmsg=sprintf(...args);for(constregexpofignorableConsoleErrorMessages){if(regexp.test(msg)){return;}}unignorableConsoleErrorMessages.add(msg);});infoSpy.mockImplementation(()=>{});});afterEach(()=>{if(unignorableConsoleErrorMessages.size){thrownewError('Unignorable console.error output from test execution:\n'+Array.from(unignorableConsoleErrorMessages).join('\n'));}});
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using? If you use the CDN bundles, please specify the exact bundle (e.g.
bundle.tracing.min.js) in your SDK setup.@sentry/nextjs
SDK Version
7.30.0
Framework Version
Next.js 12.3.2
Link to Sentry event
No response
SDK Setup
Steps to Reproduce
@sentry/nextjsand@sentry/tracingand@sentry/utilsto 7.30.0 or laterExpected Result
Our Jest tests pass.
Actual Result
Our Jest tests fail with several tests outputting
ReferenceError: fetch is not definedat the line:Actual app works fine, only our Jest tests fail.
Since this failure starts in Sentry SDK 7.30.0, I think it likely has to do with #6500 — in particular the wrapping of fetch and its uses of this check and/or this wrapping utility, interacting poorly with whatever shenanigans Jest gets up to.
Likely relevant:
jest.config.jsand
jest.setup.jscontains: