@@ -98,10 +98,9 @@ const tests = allTests.filter((name) => {
9898} ) ;
9999
100100// Remove tests that are not part of this shard.
101- const shardedTests = tests . filter ( ( name , i ) => shardId === null || i % nbShards == shardId ) ;
102- const testsToRun = allSetups . concat ( shardedTests ) ;
101+ const testsToRun = tests . filter ( ( name , i ) => shardId === null || i % nbShards == shardId ) ;
103102
104- if ( shardedTests . length === 0 ) {
103+ if ( testsToRun . length === 0 ) {
105104 console . log ( `No tests would be ran, aborting.` ) ;
106105 process . exit ( 1 ) ;
107106}
@@ -114,7 +113,7 @@ console.log(testsToRun.join('\n'));
114113if ( testsToRun . length == allTests . length ) {
115114 console . log ( `Running ${ testsToRun . length } tests` ) ;
116115} else {
117- console . log ( `Running ${ testsToRun . length } tests (${ allTests . length + allSetups . length } total)` ) ;
116+ console . log ( `Running ${ testsToRun . length } tests (${ allTests . length } total)` ) ;
118117}
119118
120119setGlobalVariable ( 'argv' , argv ) ;
@@ -132,8 +131,14 @@ Promise.all([findFreePort(), findFreePort()]).then(async ([httpPort, httpsPort])
132131 const registryProcess = await createNpmRegistry ( httpPort , httpPort ) ;
133132 const secureRegistryProcess = await createNpmRegistry ( httpPort , httpsPort , true ) ;
134133 try {
134+ for ( const [ setupIndex , setup ] of allSetups . entries ( ) ) {
135+ printHeader ( setup , setupIndex , allSetups . length , 'setup' ) ;
136+ await runSetup ( ( lastTestRun = setup ) ) ;
137+ }
138+
135139 for ( const [ testIndex , test ] of testsToRun . entries ( ) ) {
136- await runTest ( ( lastTestRun = test ) , testIndex ) ;
140+ printHeader ( test , testIndex , testsToRun . length , 'test' ) ;
141+ await runTest ( ( lastTestRun = test ) ) ;
137142 }
138143 } finally {
139144 registryProcess . kill ( ) ;
@@ -164,7 +169,7 @@ Promise.all([findFreePort(), findFreePort()]).then(async ([httpPort, httpsPort])
164169
165170function normalizeTestStep ( relativeName : string ) {
166171 // Make sure this is a windows compatible path.
167- let absoluteName = path . join ( e2eRoot , relativeName ) ;
172+ let absoluteName = path . join ( e2eRoot , relativeName ) . replace ( / \. t s $ / , '' ) ;
168173 if ( / ^ w i n / . test ( process . platform ) ) {
169174 absoluteName = absoluteName . replace ( / \\ / g, path . posix . sep ) ;
170175 }
@@ -174,7 +179,18 @@ function normalizeTestStep(relativeName: string) {
174179 return { absoluteName, currentFileName } ;
175180}
176181
177- async function runTest ( relativeName : string , testIndex : number ) {
182+ async function runSetup ( relativeName : string ) {
183+ const { absoluteName, currentFileName } = normalizeTestStep ( relativeName ) ;
184+ const start = + new Date ( ) ;
185+
186+ const module = require ( absoluteName ) ;
187+
188+ await ( typeof module === 'function' ? module : module . default ) ( ) ;
189+
190+ printFooter ( currentFileName , start ) ;
191+ }
192+
193+ async function runTest ( relativeName : string ) {
178194 const { absoluteName, currentFileName } = normalizeTestStep ( relativeName ) ;
179195 const start = + new Date ( ) ;
180196
@@ -192,8 +208,6 @@ async function runTest(relativeName: string, testIndex: number) {
192208 throw new Error ( 'Invalid test module.' ) ;
193209 } ;
194210
195- printHeader ( currentFileName , testIndex ) ;
196-
197211 let clean = true ;
198212 let previousDir = process . cwd ( ) ;
199213 try {
@@ -207,19 +221,18 @@ async function runTest(relativeName: string, testIndex: number) {
207221
208222 console . log ( '----' ) ;
209223
210- // If we're not in a setup, change the directory back to where it was before the test.
224+ // Change the directory back to where it was before the test.
211225 // This allows tests to chdir without worrying about keeping the original directory.
212- if ( ! allSetups . includes ( relativeName ) && previousDir ) {
226+ if ( previousDir ) {
213227 process . chdir ( previousDir ) ;
214228
215229 // Restore env variables before each test.
216230 console . log ( ' Restoring original environment variables...' ) ;
217231 process . env = originalEnvVariables ;
218232 }
219233
220- // Only clean after a real test, not a setup step. Also skip cleaning if the test
221- // requested an exception.
222- if ( ! allSetups . includes ( relativeName ) && clean ) {
234+ // Skip cleaning if the test requested an exception.
235+ if ( clean ) {
223236 logStack . push ( new logging . NullLogger ( ) ) ;
224237 try {
225238 await gitClean ( ) ;
@@ -236,19 +249,17 @@ async function runTest(relativeName: string, testIndex: number) {
236249 }
237250}
238251
239- function printHeader ( testName : string , testIndex : number ) {
240- const text = `${ testIndex + 1 } of ${ testsToRun . length } ` ;
241- const fullIndex =
242- ( testIndex < allSetups . length
243- ? testIndex
244- : ( testIndex - allSetups . length ) * nbShards + shardId + allSetups . length ) + 1 ;
245- const length = tests . length + allSetups . length ;
252+ function printHeader ( testName : string , testIndex : number , count : number , type : 'setup' | 'test' ) {
253+ const text = `${ testIndex + 1 } of ${ count } ` ;
254+ const fullIndex = testIndex * nbShards + shardId + 1 ;
246255 const shard =
247- shardId === null
256+ shardId === null || type !== 'test'
248257 ? ''
249- : colors . yellow ( ` [${ shardId } :${ nbShards } ]` + colors . bold ( ` (${ fullIndex } /${ length } )` ) ) ;
258+ : colors . yellow ( ` [${ shardId } :${ nbShards } ]` + colors . bold ( ` (${ fullIndex } /${ tests . length } )` ) ) ;
250259 console . log (
251- colors . green ( `Running "${ colors . bold . blue ( testName ) } " (${ colors . bold . white ( text ) } ${ shard } )...` ) ,
260+ colors . green (
261+ `Running ${ type } "${ colors . bold . blue ( testName ) } " (${ colors . bold . white ( text ) } ${ shard } )...` ,
262+ ) ,
252263 ) ;
253264}
254265
0 commit comments