@@ -69,7 +69,18 @@ let JEST_TESTS: string[] | undefined;
6969// to reexec itself here
7070if ( CI && ! process . env . JEST_LIST_TESTS_INNER ) {
7171 try {
72- const stdout = execFileSync ( 'pnpm' , [ 'exec' , 'jest' , '--listTests' , '--json' ] , {
72+ const listTestArguments = [ 'exec' , 'jest' , '--listTests' , '--json' ] ;
73+
74+ if ( process . env . MERGE_BASE ) {
75+ console . log ( 'MERGE_BASE detected:' , process . env . MERGE_BASE ) ;
76+ listTestArguments . push (
77+ '--changedSince' ,
78+ process . env . MERGE_BASE ,
79+ '--passWithNoTests'
80+ ) ;
81+ }
82+
83+ const stdout = execFileSync ( 'pnpm' , listTestArguments , {
7384 stdio : 'pipe' ,
7485 encoding : 'utf-8' ,
7586 env : { ...process . env , JEST_LIST_TESTS_INNER : '1' } ,
@@ -108,6 +119,10 @@ function getTestsForGroup(
108119 allTests : ReadonlyArray < string > ,
109120 testStats : Record < string , number >
110121) : string [ ] {
122+ if ( allTests . length === 0 ) {
123+ return [ ] ;
124+ }
125+
111126 const speculatedSuiteDuration = Object . values ( testStats ) . reduce ( ( a , b ) => a + b , 0 ) ;
112127 const targetDuration = speculatedSuiteDuration / nodeTotal ;
113128
@@ -122,8 +137,13 @@ function getTestsForGroup(
122137 const tests = new Map < string , number > ( ) ;
123138 const SUITE_P50_DURATION_MS = 1500 ;
124139
140+ const allTestsSet = new Set ( allTests ) ;
141+
125142 // First, iterate over all of the tests we have stats for.
126143 Object . entries ( testStats ) . forEach ( ( [ test , duration ] ) => {
144+ if ( ! allTestsSet . has ( test ) ) {
145+ return ;
146+ }
127147 if ( duration <= 0 ) {
128148 throw new Error ( `Test duration is <= 0 for ${ test } ` ) ;
129149 }
@@ -199,8 +219,8 @@ function getTestsForGroup(
199219 }
200220 }
201221
202- if ( ! groups [ nodeIndex ] ) {
203- throw new Error ( `No tests found for node ${ nodeIndex } ` ) ;
222+ if ( ! groups [ nodeIndex ] ?. length ) {
223+ return [ '<rootDir>/__no_tests_for_this_shard__' ] ;
204224 }
205225 return groups [ nodeIndex ] . map ( test => `<rootDir>/${ test } ` ) ;
206226}
@@ -285,6 +305,7 @@ const config: Config.InitialOptions = {
285305 // window/cookies state.
286306 '@sentry/toolbar' : '<rootDir>/tests/js/sentry-test/mocks/sentryToolbarMock.js' ,
287307 } ,
308+ passWithNoTests : ! ! process . env . MERGE_BASE ,
288309 setupFiles : [
289310 '<rootDir>/static/app/utils/silence-react-unsafe-warnings.ts' ,
290311 'jest-canvas-mock' ,
@@ -333,8 +354,7 @@ const config: Config.InitialOptions = {
333354 */
334355 clearMocks : true ,
335356
336- // To disable the sentry jest integration, set this to 'jsdom'
337- testEnvironment : '@sentry/jest-environment/jsdom' ,
357+ testEnvironment : '<rootDir>/tests/js/sentry-test/jest-environment.js' ,
338358 testEnvironmentOptions : {
339359 globalsCleanup : 'on' ,
340360 sentryConfig : {
0 commit comments