1
1
import { deepStrictEqual } from 'node:assert'
2
2
import { EventEmitter , once } from 'node:events'
3
3
import { readdirSync , readFileSync , statSync } from 'node:fs'
4
- import { cpus } from 'node:os'
5
4
import { basename , isAbsolute , join , resolve } from 'node:path'
6
5
import { fileURLToPath } from 'node:url'
7
6
import { Worker } from 'node:worker_threads'
8
- import { parseMeta , handlePipes , normalizeName } from './util.mjs'
7
+ import { parseMeta , handlePipes , normalizeName , colors } from './util.mjs'
9
8
10
9
const basePath = fileURLToPath ( join ( import . meta. url , '../../..' ) )
11
10
const testPath = join ( basePath , 'tests' )
@@ -80,14 +79,14 @@ export class WPTRunner extends EventEmitter {
80
79
}
81
80
}
82
81
83
- return [ ...files ]
82
+ return [ ...files ] . sort ( )
84
83
}
85
84
86
85
async run ( ) {
87
86
const workerPath = fileURLToPath ( join ( import . meta. url , '../worker.mjs' ) )
88
87
/** @type {Set<Worker> } */
89
88
const activeWorkers = new Set ( )
90
- let finishedFiles = 0
89
+ let finishedFiles = 1
91
90
92
91
for ( const test of this . #files) {
93
92
const code = test . includes ( '.sub.' )
@@ -97,10 +96,17 @@ export class WPTRunner extends EventEmitter {
97
96
98
97
if ( this . #status[ basename ( test ) ] ?. skip ) {
99
98
this . #stats. skipped += 1
99
+
100
+ console . log ( '=' . repeat ( 96 ) )
101
+ console . log ( colors ( `[${ finishedFiles } /${ this . #files. length } ] SKIPPED - ${ test } ` , 'yellow' ) )
102
+ console . log ( '=' . repeat ( 96 ) )
103
+
100
104
finishedFiles ++
101
105
continue
102
106
}
103
107
108
+ const start = performance . now ( )
109
+
104
110
const worker = new Worker ( workerPath , {
105
111
workerData : {
106
112
// Code to load before the test harness and tests.
@@ -126,20 +132,26 @@ export class WPTRunner extends EventEmitter {
126
132
}
127
133
} )
128
134
129
- worker . once ( 'exit' , ( ) => {
135
+ try {
130
136
activeWorkers . delete ( worker )
131
137
132
- if ( ++ finishedFiles === this . #files. length ) {
133
- this . handleRunnerCompletion ( )
134
- }
135
- } )
136
-
137
- if ( activeWorkers . size >= cpus ( ) . length ) {
138
138
await once ( worker , 'exit' , {
139
139
signal : AbortSignal . timeout ( timeout )
140
140
} )
141
+
142
+ console . log ( '=' . repeat ( 96 ) )
143
+ console . log ( colors ( `[${ finishedFiles } /${ this . #files. length } ] PASSED - ${ test } ` , 'green' ) )
144
+ console . log ( `Test took ${ ( performance . now ( ) - start ) . toFixed ( 2 ) } ms` )
145
+ console . log ( '=' . repeat ( 96 ) )
146
+
147
+ finishedFiles ++
148
+ } catch ( e ) {
149
+ console . log ( `${ test } timed out after ${ timeout } ms` )
150
+ throw e
141
151
}
142
152
}
153
+
154
+ this . handleRunnerCompletion ( )
143
155
}
144
156
145
157
/**
0 commit comments