@@ -610,7 +610,7 @@ describe('Instrumentation API', () => {
610610 }
611611 } ) ;
612612
613- it ( 'should add unstable_instrumentations export when useInstrumentationAPI is true' , async ( ) => {
613+ it ( 'should add instrumentations export when useInstrumentationAPI is true' , async ( ) => {
614614 const basicContent = fs . readFileSync (
615615 path . join ( fixturesDir , 'basic.tsx' ) ,
616616 'utf8' ,
@@ -626,11 +626,11 @@ describe('Instrumentation API', () => {
626626 'import * as Sentry from "@sentry/react-router";' ,
627627 ) ;
628628 expect ( modifiedContent ) . toContain (
629- 'export const unstable_instrumentations = [Sentry.createSentryServerInstrumentation()];' ,
629+ 'export const instrumentations = [Sentry.createSentryServerInstrumentation()];' ,
630630 ) ;
631631 } ) ;
632632
633- it ( 'should not add unstable_instrumentations export when useInstrumentationAPI is false' , async ( ) => {
633+ it ( 'should not add instrumentations export when useInstrumentationAPI is false' , async ( ) => {
634634 const basicContent = fs . readFileSync (
635635 path . join ( fixturesDir , 'basic.tsx' ) ,
636636 'utf8' ,
@@ -642,18 +642,18 @@ describe('Instrumentation API', () => {
642642
643643 const modifiedContent = fs . readFileSync ( tmpFile , 'utf8' ) ;
644644
645- expect ( modifiedContent ) . not . toContain ( 'unstable_instrumentations ' ) ;
645+ expect ( modifiedContent ) . not . toContain ( 'instrumentations ' ) ;
646646 expect ( modifiedContent ) . not . toContain ( 'createSentryServerInstrumentation' ) ;
647647 } ) ;
648648
649- it ( 'should not duplicate unstable_instrumentations export if already present' , async ( ) => {
649+ it ( 'should not duplicate instrumentations export if already present' , async ( ) => {
650650 const contentWithInstrumentations = `
651651import { ServerRouter } from 'react-router';
652652import * as Sentry from '@sentry/react-router';
653653
654654export default function handleRequest() {}
655655export const handleError = () => {};
656- export const unstable_instrumentations = [Sentry.createSentryServerInstrumentation()];
656+ export const instrumentations = [Sentry.createSentryServerInstrumentation()];
657657` ;
658658
659659 fs . writeFileSync ( tmpFile , contentWithInstrumentations ) ;
@@ -662,8 +662,26 @@ export const unstable_instrumentations = [Sentry.createSentryServerInstrumentati
662662
663663 const modifiedContent = fs . readFileSync ( tmpFile , 'utf8' ) ;
664664
665- const count = ( modifiedContent . match ( / u n s t a b l e _ i n s t r u m e n t a t i o n s / g) || [ ] )
666- . length ;
665+ const count = ( modifiedContent . match ( / \b i n s t r u m e n t a t i o n s \b / g) || [ ] ) . length ;
667666 expect ( count ) . toBe ( 1 ) ;
668667 } ) ;
668+
669+ it ( 'should not duplicate if legacy unstable_instrumentations export is already present' , async ( ) => {
670+ const contentWithLegacy = `
671+ import { ServerRouter } from 'react-router';
672+ import * as Sentry from '@sentry/react-router';
673+
674+ export default function handleRequest() {}
675+ export const handleError = () => {};
676+ export const unstable_instrumentations = [Sentry.createSentryServerInstrumentation()];
677+ ` ;
678+
679+ fs . writeFileSync ( tmpFile , contentWithLegacy ) ;
680+
681+ await instrumentServerEntry ( tmpFile , true ) ;
682+
683+ const modifiedContent = fs . readFileSync ( tmpFile , 'utf8' ) ;
684+
685+ expect ( modifiedContent ) . not . toContain ( 'export const instrumentations =' ) ;
686+ } ) ;
669687} ) ;
0 commit comments