@@ -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 ) ;
@@ -132,8 +131,14 @@ Promise.all([findFreePort(), findFreePort()]).then(async ([httpPort, httpsPort])
132
131
const registryProcess = await createNpmRegistry ( httpPort , httpPort ) ;
133
132
const secureRegistryProcess = await createNpmRegistry ( httpPort , httpsPort , true ) ;
134
133
try {
134
+ for ( const [ setupIndex , setup ] of allSetups . entries ( ) ) {
135
+ printHeader ( setup , setupIndex , allSetups . length , 'setup' ) ;
136
+ await runSetup ( ( lastTestRun = setup ) ) ;
137
+ }
138
+
135
139
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 ) ) ;
137
142
}
138
143
} finally {
139
144
registryProcess . kill ( ) ;
@@ -164,7 +169,7 @@ Promise.all([findFreePort(), findFreePort()]).then(async ([httpPort, httpsPort])
164
169
165
170
function normalizeTestStep ( relativeName : string ) {
166
171
// 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 $ / , '' ) ;
168
173
if ( / ^ w i n / . test ( process . platform ) ) {
169
174
absoluteName = absoluteName . replace ( / \\ / g, path . posix . sep ) ;
170
175
}
@@ -174,7 +179,18 @@ function normalizeTestStep(relativeName: string) {
174
179
return { absoluteName, currentFileName } ;
175
180
}
176
181
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 ) {
178
194
const { absoluteName, currentFileName } = normalizeTestStep ( relativeName ) ;
179
195
const start = + new Date ( ) ;
180
196
@@ -192,8 +208,6 @@ async function runTest(relativeName: string, testIndex: number) {
192
208
throw new Error ( 'Invalid test module.' ) ;
193
209
} ;
194
210
195
- printHeader ( currentFileName , testIndex ) ;
196
-
197
211
let clean = true ;
198
212
let previousDir = process . cwd ( ) ;
199
213
try {
@@ -207,19 +221,18 @@ async function runTest(relativeName: string, testIndex: number) {
207
221
208
222
console . log ( '----' ) ;
209
223
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.
211
225
// This allows tests to chdir without worrying about keeping the original directory.
212
- if ( ! allSetups . includes ( relativeName ) && previousDir ) {
226
+ if ( previousDir ) {
213
227
process . chdir ( previousDir ) ;
214
228
215
229
// Restore env variables before each test.
216
230
console . log ( ' Restoring original environment variables...' ) ;
217
231
process . env = originalEnvVariables ;
218
232
}
219
233
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 ) {
223
236
logStack . push ( new logging . NullLogger ( ) ) ;
224
237
try {
225
238
await gitClean ( ) ;
@@ -236,19 +249,17 @@ async function runTest(relativeName: string, testIndex: number) {
236
249
}
237
250
}
238
251
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 ;
246
255
const shard =
247
- shardId === null
256
+ shardId === null || type !== 'test'
248
257
? ''
249
- : colors . yellow ( ` [${ shardId } :${ nbShards } ]` + colors . bold ( ` (${ fullIndex } /${ length } )` ) ) ;
258
+ : colors . yellow ( ` [${ shardId } :${ nbShards } ]` + colors . bold ( ` (${ fullIndex } /${ tests . length } )` ) ) ;
250
259
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
+ ) ,
252
263
) ;
253
264
}
254
265
0 commit comments