@@ -5,6 +5,7 @@ const fixtures = require('../common/fixtures');
5
5
const fs = require ( 'fs' ) ;
6
6
const fsPromises = fs . promises ;
7
7
const path = require ( 'path' ) ;
8
+ const events = require ( 'events' ) ;
8
9
const { inspect } = require ( 'util' ) ;
9
10
const { Worker } = require ( 'worker_threads' ) ;
10
11
@@ -152,21 +153,30 @@ class WPTTestSpec {
152
153
this . filename = filename ;
153
154
154
155
this . requires = new Set ( ) ;
155
- this . failReasons = [ ] ;
156
+ this . failedTests = [ ] ;
157
+ this . flakyTests = [ ] ;
156
158
this . skipReasons = [ ] ;
157
159
for ( const item of rules ) {
158
160
if ( item . requires . length ) {
159
161
for ( const req of item . requires ) {
160
162
this . requires . add ( req ) ;
161
163
}
162
164
}
163
- if ( item . fail ) {
164
- this . failReasons . push ( item . fail ) ;
165
+ if ( Array . isArray ( item . fail ?. expected ) ) {
166
+ this . failedTests . push ( ...item . fail . expected ) ;
167
+ }
168
+ if ( Array . isArray ( item . fail ?. flaky ) ) {
169
+ this . failedTests . push ( ...item . fail . flaky ) ;
170
+ this . flakyTests . push ( ...item . fail . flaky ) ;
165
171
}
166
172
if ( item . skip ) {
167
173
this . skipReasons . push ( item . skip ) ;
168
174
}
169
175
}
176
+
177
+ this . failedTests = [ ...new Set ( this . failedTests ) ] ;
178
+ this . flakyTests = [ ...new Set ( this . flakyTests ) ] ;
179
+ this . skipReasons = [ ...new Set ( this . skipReasons ) ] ;
170
180
}
171
181
172
182
getRelativePath ( ) {
@@ -368,7 +378,7 @@ class WPTRunner {
368
378
369
379
// TODO(joyeecheung): work with the upstream to port more tests in .html
370
380
// to .js.
371
- runJsTests ( ) {
381
+ async runJsTests ( ) {
372
382
let queue = [ ] ;
373
383
374
384
// If the tests are run as `node test/wpt/test-something.js subset.any.js`,
@@ -459,6 +469,8 @@ class WPTRunner {
459
469
) ;
460
470
this . inProgress . delete ( testFileName ) ;
461
471
} ) ;
472
+
473
+ await events . once ( worker , 'exit' ) . catch ( ( ) => { } ) ;
462
474
}
463
475
464
476
process . on ( 'exit' , ( ) => {
@@ -469,34 +481,72 @@ class WPTRunner {
469
481
}
470
482
}
471
483
inspect . defaultOptions . depth = Infinity ;
472
- console . log ( this . results ) ;
484
+ // Sorts the rules to have consistent output
485
+ console . log ( JSON . stringify ( Object . keys ( this . results ) . sort ( ) . reduce (
486
+ ( obj , key ) => {
487
+ obj [ key ] = this . results [ key ] ;
488
+ return obj ;
489
+ } ,
490
+ { }
491
+ ) , null , 2 ) ) ;
473
492
474
493
const failures = [ ] ;
475
494
let expectedFailures = 0 ;
476
495
let skipped = 0 ;
477
- for ( const key of Object . keys ( this . results ) ) {
478
- const item = this . results [ key ] ;
479
- if ( item . fail && item . fail . unexpected ) {
496
+ for ( const [ key , item ] of Object . entries ( this . results ) ) {
497
+ if ( item . fail ?. unexpected ) {
480
498
failures . push ( key ) ;
481
499
}
482
- if ( item . fail && item . fail . expected ) {
500
+ if ( item . fail ? .expected ) {
483
501
expectedFailures ++ ;
484
502
}
485
503
if ( item . skip ) {
486
504
skipped ++ ;
487
505
}
488
506
}
507
+
508
+ const unexpectedPasses = [ ] ;
509
+ for ( const [ key , specMap ] of this . specMap ) {
510
+ // File has no expected failures
511
+ if ( ! specMap . failedTests . length ) {
512
+ continue ;
513
+ }
514
+
515
+ // File was (maybe even conditionally) skipped
516
+ if ( this . results [ key ] ?. skip ) {
517
+ continue ;
518
+ }
519
+
520
+ // Full check: every expected to fail test is present
521
+ if ( specMap . failedTests . some ( ( expectedToFail ) => {
522
+ if ( specMap . flakyTests . includes ( expectedToFail ) ) {
523
+ return false ;
524
+ }
525
+ return this . results [ key ] ?. fail ?. expected ?. includes ( expectedToFail ) !== true ;
526
+ } ) ) {
527
+ unexpectedPasses . push ( key ) ;
528
+ continue ;
529
+ }
530
+ }
531
+
489
532
const ran = total - skipped ;
490
533
const passed = ran - expectedFailures - failures . length ;
491
534
console . log ( `Ran ${ ran } /${ total } tests, ${ skipped } skipped,` ,
492
535
`${ passed } passed, ${ expectedFailures } expected failures,` ,
493
- `${ failures . length } unexpected failures` ) ;
536
+ `${ failures . length } unexpected failures,` ,
537
+ `${ unexpectedPasses . length } unexpected passes` ) ;
494
538
if ( failures . length > 0 ) {
495
539
const file = path . join ( 'test' , 'wpt' , 'status' , `${ this . path } .json` ) ;
496
540
throw new Error (
497
541
`Found ${ failures . length } unexpected failures. ` +
498
542
`Consider updating ${ file } for these files:\n${ failures . join ( '\n' ) } ` ) ;
499
543
}
544
+ if ( unexpectedPasses . length > 0 ) {
545
+ const file = path . join ( 'test' , 'wpt' , 'status' , `${ this . path } .json` ) ;
546
+ throw new Error (
547
+ `Found ${ unexpectedPasses . length } unexpected passes. ` +
548
+ `Consider updating ${ file } for these files:\n${ unexpectedPasses . join ( '\n' ) } ` ) ;
549
+ }
500
550
} ) ;
501
551
}
502
552
@@ -577,8 +627,9 @@ class WPTRunner {
577
627
if ( ! result [ item . status ] [ key ] ) {
578
628
result [ item . status ] [ key ] = [ ] ;
579
629
}
580
- if ( result [ item . status ] [ key ] . indexOf ( item . reason ) === - 1 ) {
581
- result [ item . status ] [ key ] . push ( item . reason ) ;
630
+ const hasName = result [ item . status ] [ key ] . includes ( item . name ) ;
631
+ if ( ! hasName ) {
632
+ result [ item . status ] [ key ] . push ( item . name ) ;
582
633
}
583
634
}
584
635
}
@@ -589,10 +640,10 @@ class WPTRunner {
589
640
590
641
fail ( filename , test , status ) {
591
642
const spec = this . specMap . get ( filename ) ;
592
- const expected = ! ! ( spec . failReasons . length ) ;
643
+ const expected = spec . failedTests . includes ( test . name ) ;
593
644
if ( expected ) {
594
645
console . log ( `[EXPECTED_FAILURE][${ status . toUpperCase ( ) } ] ${ test . name } ` ) ;
595
- console . log ( spec . failReasons . join ( '; ' ) ) ;
646
+ console . log ( test . message || status ) ;
596
647
} else {
597
648
console . log ( `[UNEXPECTED_FAILURE][${ status . toUpperCase ( ) } ] ${ test . name } ` ) ;
598
649
}
@@ -604,6 +655,7 @@ class WPTRunner {
604
655
` ${ require . main . filename } ${ filename } ` ;
605
656
console . log ( `Command: ${ command } \n` ) ;
606
657
this . addTestResult ( filename , {
658
+ name : test . name ,
607
659
expected,
608
660
status : kFail ,
609
661
reason : test . message || status
0 commit comments