@@ -98,10 +98,9 @@ const tests = allTests.filter((name) => {
98
98
} ) ;
99
99
100
100
// 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 ) ;
103
102
104
- if ( shardedTests . length === 0 ) {
103
+ if ( testsToRun . length === 0 ) {
105
104
console . log ( `No tests would be ran, aborting.` ) ;
106
105
process . exit ( 1 ) ;
107
106
}
@@ -114,7 +113,7 @@ console.log(testsToRun.join('\n'));
114
113
if ( testsToRun . length == allTests . length ) {
115
114
console . log ( `Running ${ testsToRun . length } tests` ) ;
116
115
} else {
117
- console . log ( `Running ${ testsToRun . length } tests (${ allTests . length + allSetups . length } total)` ) ;
116
+ console . log ( `Running ${ testsToRun . length } tests (${ allTests . length } total)` ) ;
118
117
}
119
118
120
119
setGlobalVariable ( 'argv' , argv ) ;
@@ -131,8 +130,16 @@ Promise.all([findFreePort(), findFreePort()]).then(async ([httpPort, httpsPort])
131
130
let lastTestRun : string | null = null ;
132
131
133
132
try {
133
+ for ( const [ setupIndex , setup ] of allSetups . entries ( ) ) {
134
+ printSetupHeader ( setup , setupIndex , allSetups . length ) ;
135
+
136
+ await runSetup ( ( lastTestRun = setup ) ) ;
137
+ }
138
+
134
139
for ( const [ testIndex , test ] of testsToRun . entries ( ) ) {
135
- await runTest ( ( lastTestRun = test ) , testIndex ) ;
140
+ printTestHeader ( test , testIndex , testsToRun . length ) ;
141
+
142
+ await runTest ( ( lastTestRun = test ) ) ;
136
143
}
137
144
138
145
console . log ( colors . green ( 'Done.' ) ) ;
@@ -162,7 +169,7 @@ Promise.all([findFreePort(), findFreePort()]).then(async ([httpPort, httpsPort])
162
169
163
170
function normalizeTestStep ( relativeName : string ) {
164
171
// Make sure this is a windows compatible path.
165
- let absoluteName = path . join ( e2eRoot , relativeName ) ;
172
+ let absoluteName = path . join ( e2eRoot , relativeName ) . replace ( / \. t s $ / , '' ) ;
166
173
if ( / ^ w i n / . test ( process . platform ) ) {
167
174
absoluteName = absoluteName . replace ( / \\ / g, path . posix . sep ) ;
168
175
}
@@ -172,7 +179,18 @@ function normalizeTestStep(relativeName: string) {
172
179
return { absoluteName, currentFileName } ;
173
180
}
174
181
175
- 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 ) {
176
194
const { absoluteName, currentFileName } = normalizeTestStep ( relativeName ) ;
177
195
const start = + new Date ( ) ;
178
196
@@ -190,8 +208,6 @@ async function runTest(relativeName: string, testIndex: number) {
190
208
throw new Error ( 'Invalid test module.' ) ;
191
209
} ;
192
210
193
- printHeader ( currentFileName , testIndex ) ;
194
-
195
211
let clean = true ;
196
212
let previousDir = process . cwd ( ) ;
197
213
try {
@@ -205,19 +221,18 @@ async function runTest(relativeName: string, testIndex: number) {
205
221
206
222
console . log ( '----' ) ;
207
223
208
- // 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.
209
225
// This allows tests to chdir without worrying about keeping the original directory.
210
- if ( ! allSetups . includes ( relativeName ) && previousDir ) {
226
+ if ( previousDir ) {
211
227
process . chdir ( previousDir ) ;
212
228
213
229
// Restore env variables before each test.
214
230
console . log ( ' Restoring original environment variables...' ) ;
215
231
process . env = originalEnvVariables ;
216
232
}
217
233
218
- // Only clean after a real test, not a setup step. Also skip cleaning if the test
219
- // requested an exception.
220
- if ( ! allSetups . includes ( relativeName ) && clean ) {
234
+ // Skip cleaning if the test requested an exception.
235
+ if ( clean ) {
221
236
logStack . push ( new logging . NullLogger ( ) ) ;
222
237
try {
223
238
await gitClean ( ) ;
@@ -234,19 +249,24 @@ async function runTest(relativeName: string, testIndex: number) {
234
249
}
235
250
}
236
251
237
- function printHeader ( testName : string , testIndex : number ) {
238
- const text = `${ testIndex + 1 } of ${ testsToRun . length } ` ;
239
- const fullIndex =
240
- ( testIndex < allSetups . length
241
- ? testIndex
242
- : ( testIndex - allSetups . length ) * nbShards + shardId + allSetups . length ) + 1 ;
243
- const length = tests . length + allSetups . length ;
252
+ function printSetupHeader ( setupName : string , setupIndex : number , count : number ) {
253
+ const text = `${ setupIndex + 1 } of ${ count } ` ;
254
+ console . log (
255
+ colors . green ( `Running setup "${ colors . bold . blue ( setupName ) } " (${ colors . bold . white ( text ) } )...` ) ,
256
+ ) ;
257
+ }
258
+
259
+ function printTestHeader ( testName : string , testIndex : number , count : number ) {
260
+ const text = `${ testIndex + 1 } of ${ count } ` ;
261
+ const fullIndex = testIndex * nbShards + shardId + 1 ;
244
262
const shard =
245
263
shardId === null
246
264
? ''
247
- : colors . yellow ( ` [${ shardId } :${ nbShards } ]` + colors . bold ( ` (${ fullIndex } /${ length } )` ) ) ;
265
+ : colors . yellow ( ` [${ shardId } :${ nbShards } ]` + colors . bold ( ` (${ fullIndex } /${ tests . length } )` ) ) ;
248
266
console . log (
249
- colors . green ( `Running "${ colors . bold . blue ( testName ) } " (${ colors . bold . white ( text ) } ${ shard } )...` ) ,
267
+ colors . green (
268
+ `Running test "${ colors . bold . blue ( testName ) } " (${ colors . bold . white ( text ) } ${ shard } )...` ,
269
+ ) ,
250
270
) ;
251
271
}
252
272
0 commit comments