@@ -4,6 +4,7 @@ require('../common');
4
4
const assert = require ( 'assert' ) ;
5
5
const { spawnSync } = require ( 'child_process' ) ;
6
6
const { join } = require ( 'path' ) ;
7
+ const { readdirSync } = require ( 'fs' ) ;
7
8
const fixtures = require ( '../common/fixtures' ) ;
8
9
const testFixtures = fixtures . path ( 'test-runner' ) ;
9
10
@@ -210,3 +211,135 @@ const testFixtures = fixtures.path('test-runner');
210
211
const stdout = child . stdout . toString ( ) ;
211
212
assert . match ( stdout , / o k 1 - t h i s s h o u l d p a s s / ) ;
212
213
}
214
+
215
+ {
216
+ // --test-shard option validation
217
+ const args = [ '--test' , '--test-shard=1' , join ( testFixtures , 'index.js' ) ] ;
218
+ const child = spawnSync ( process . execPath , args , { cwd : testFixtures } ) ;
219
+
220
+ assert . strictEqual ( child . status , 1 ) ;
221
+ assert . strictEqual ( child . signal , null ) ;
222
+ assert . match ( child . stderr . toString ( ) , / T h e a r g u m e n t ' - - t e s t - s h a r d ' m u s t b e i n t h e f o r m o f < i n d e x > \/ < t o t a l > \. R e c e i v e d ' 1 ' / ) ;
223
+ const stdout = child . stdout . toString ( ) ;
224
+ assert . strictEqual ( stdout , '' ) ;
225
+ }
226
+
227
+ {
228
+ // --test-shard option validation
229
+ const args = [ '--test' , '--test-shard=1/2/3' , join ( testFixtures , 'index.js' ) ] ;
230
+ const child = spawnSync ( process . execPath , args , { cwd : testFixtures } ) ;
231
+
232
+ assert . strictEqual ( child . status , 1 ) ;
233
+ assert . strictEqual ( child . signal , null ) ;
234
+ assert . match ( child . stderr . toString ( ) , / T h e a r g u m e n t ' - - t e s t - s h a r d ' m u s t b e i n t h e f o r m o f < i n d e x > \/ < t o t a l > \. R e c e i v e d ' 1 \/ 2 \/ 3 ' / ) ;
235
+ const stdout = child . stdout . toString ( ) ;
236
+ assert . strictEqual ( stdout , '' ) ;
237
+ }
238
+
239
+ {
240
+ // --test-shard option validation
241
+ const args = [ '--test' , '--test-shard=0/3' , join ( testFixtures , 'index.js' ) ] ;
242
+ const child = spawnSync ( process . execPath , args , { cwd : testFixtures } ) ;
243
+
244
+ assert . strictEqual ( child . status , 1 ) ;
245
+ assert . strictEqual ( child . signal , null ) ;
246
+ assert . match ( child . stderr . toString ( ) , / T h e v a l u e o f " o p t i o n s \. s h a r d \. i n d e x " i s o u t o f r a n g e \. I t m u s t b e > = 1 & & < = 3 \( " o p t i o n s \. s h a r d \. t o t a l " \) \. R e c e i v e d 0 / ) ;
247
+ const stdout = child . stdout . toString ( ) ;
248
+ assert . strictEqual ( stdout , '' ) ;
249
+ }
250
+
251
+ {
252
+ // --test-shard option validation
253
+ const args = [ '--test' , '--test-shard=0xf/20abcd' , join ( testFixtures , 'index.js' ) ] ;
254
+ const child = spawnSync ( process . execPath , args , { cwd : testFixtures } ) ;
255
+
256
+ assert . strictEqual ( child . status , 1 ) ;
257
+ assert . strictEqual ( child . signal , null ) ;
258
+ assert . match ( child . stderr . toString ( ) , / T h e a r g u m e n t ' - - t e s t - s h a r d ' m u s t b e i n t h e f o r m o f < i n d e x > \/ < t o t a l > \. R e c e i v e d ' 0 x f \/ 2 0 a b c d ' / ) ;
259
+ const stdout = child . stdout . toString ( ) ;
260
+ assert . strictEqual ( stdout , '' ) ;
261
+ }
262
+
263
+ {
264
+ // --test-shard option validation
265
+ const args = [ '--test' , '--test-shard=hello' , join ( testFixtures , 'index.js' ) ] ;
266
+ const child = spawnSync ( process . execPath , args , { cwd : testFixtures } ) ;
267
+
268
+ assert . strictEqual ( child . status , 1 ) ;
269
+ assert . strictEqual ( child . signal , null ) ;
270
+ assert . match ( child . stderr . toString ( ) , / T h e a r g u m e n t ' - - t e s t - s h a r d ' m u s t b e i n t h e f o r m o f < i n d e x > \/ < t o t a l > \. R e c e i v e d ' h e l l o ' / ) ;
271
+ const stdout = child . stdout . toString ( ) ;
272
+ assert . strictEqual ( stdout , '' ) ;
273
+ }
274
+
275
+ {
276
+ // --test-shard option, first shard
277
+ const shardsTestPath = join ( testFixtures , 'shards' ) ;
278
+ const allShardsTestsFiles = readdirSync ( shardsTestPath ) . map ( ( file ) => join ( shardsTestPath , file ) ) ;
279
+ const args = [
280
+ '--test' ,
281
+ '--test-shard=1/2' ,
282
+ ...allShardsTestsFiles ,
283
+ ] ;
284
+ const child = spawnSync ( process . execPath , args ) ;
285
+
286
+ assert . strictEqual ( child . status , 0 ) ;
287
+ assert . strictEqual ( child . signal , null ) ;
288
+ assert . strictEqual ( child . stderr . toString ( ) , '' ) ;
289
+ const stdout = child . stdout . toString ( ) ;
290
+ assert . match ( stdout , / # S u b t e s t : a \. c j s t h i s s h o u l d p a s s / ) ;
291
+ assert . match ( stdout , / o k 1 - a \. c j s t h i s s h o u l d p a s s / ) ;
292
+
293
+ assert . match ( stdout , / # S u b t e s t : c \. c j s t h i s s h o u l d p a s s / ) ;
294
+ assert . match ( stdout , / o k 2 - c \. c j s t h i s s h o u l d p a s s / ) ;
295
+
296
+ assert . match ( stdout , / # S u b t e s t : e \. c j s t h i s s h o u l d p a s s / ) ;
297
+ assert . match ( stdout , / o k 3 - e \. c j s t h i s s h o u l d p a s s / ) ;
298
+
299
+ assert . match ( stdout , / # S u b t e s t : g \. c j s t h i s s h o u l d p a s s / ) ;
300
+ assert . match ( stdout , / o k 4 - g \. c j s t h i s s h o u l d p a s s / ) ;
301
+
302
+ assert . match ( stdout , / # S u b t e s t : i \. c j s t h i s s h o u l d p a s s / ) ;
303
+ assert . match ( stdout , / o k 5 - i \. c j s t h i s s h o u l d p a s s / ) ;
304
+
305
+ assert . match ( stdout , / # t e s t s 5 / ) ;
306
+ assert . match ( stdout , / # p a s s 5 / ) ;
307
+ assert . match ( stdout , / # f a i l 0 / ) ;
308
+ assert . match ( stdout , / # s k i p p e d 0 / ) ;
309
+ }
310
+
311
+ {
312
+ // --test-shard option, last shard
313
+ const shardsTestPath = join ( testFixtures , 'shards' ) ;
314
+ const allShardsTestsFiles = readdirSync ( shardsTestPath ) . map ( ( file ) => join ( shardsTestPath , file ) ) ;
315
+ const args = [
316
+ '--test' ,
317
+ '--test-shard=2/2' ,
318
+ ...allShardsTestsFiles ,
319
+ ] ;
320
+ const child = spawnSync ( process . execPath , args ) ;
321
+
322
+ assert . strictEqual ( child . status , 0 ) ;
323
+ assert . strictEqual ( child . signal , null ) ;
324
+ assert . strictEqual ( child . stderr . toString ( ) , '' ) ;
325
+ const stdout = child . stdout . toString ( ) ;
326
+ assert . match ( stdout , / # S u b t e s t : b \. c j s t h i s s h o u l d p a s s / ) ;
327
+ assert . match ( stdout , / o k 1 - b \. c j s t h i s s h o u l d p a s s / ) ;
328
+
329
+ assert . match ( stdout , / # S u b t e s t : d \. c j s t h i s s h o u l d p a s s / ) ;
330
+ assert . match ( stdout , / o k 2 - d \. c j s t h i s s h o u l d p a s s / ) ;
331
+
332
+ assert . match ( stdout , / # S u b t e s t : f \. c j s t h i s s h o u l d p a s s / ) ;
333
+ assert . match ( stdout , / o k 3 - f \. c j s t h i s s h o u l d p a s s / ) ;
334
+
335
+ assert . match ( stdout , / # S u b t e s t : h \. c j s t h i s s h o u l d p a s s / ) ;
336
+ assert . match ( stdout , / o k 4 - h \. c j s t h i s s h o u l d p a s s / ) ;
337
+
338
+ assert . match ( stdout , / # S u b t e s t : j \. c j s t h i s s h o u l d p a s s / ) ;
339
+ assert . match ( stdout , / o k 5 - j \. c j s t h i s s h o u l d p a s s / ) ;
340
+
341
+ assert . match ( stdout , / # t e s t s 5 / ) ;
342
+ assert . match ( stdout , / # p a s s 5 / ) ;
343
+ assert . match ( stdout , / # f a i l 0 / ) ;
344
+ assert . match ( stdout , / # s k i p p e d 0 / ) ;
345
+ }
0 commit comments