Skip to content

Commit eaf4dc9

Browse files
authored
test: more logs in wpt runner (#1933)
1 parent 8b8bfa7 commit eaf4dc9

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

test/wpt/runner/runner/runner.mjs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { deepStrictEqual } from 'node:assert'
22
import { EventEmitter, once } from 'node:events'
33
import { readdirSync, readFileSync, statSync } from 'node:fs'
4-
import { cpus } from 'node:os'
54
import { basename, isAbsolute, join, resolve } from 'node:path'
65
import { fileURLToPath } from 'node:url'
76
import { Worker } from 'node:worker_threads'
8-
import { parseMeta, handlePipes, normalizeName } from './util.mjs'
7+
import { parseMeta, handlePipes, normalizeName, colors } from './util.mjs'
98

109
const basePath = fileURLToPath(join(import.meta.url, '../../..'))
1110
const testPath = join(basePath, 'tests')
@@ -80,14 +79,14 @@ export class WPTRunner extends EventEmitter {
8079
}
8180
}
8281

83-
return [...files]
82+
return [...files].sort()
8483
}
8584

8685
async run () {
8786
const workerPath = fileURLToPath(join(import.meta.url, '../worker.mjs'))
8887
/** @type {Set<Worker>} */
8988
const activeWorkers = new Set()
90-
let finishedFiles = 0
89+
let finishedFiles = 1
9190

9291
for (const test of this.#files) {
9392
const code = test.includes('.sub.')
@@ -97,10 +96,17 @@ export class WPTRunner extends EventEmitter {
9796

9897
if (this.#status[basename(test)]?.skip) {
9998
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+
100104
finishedFiles++
101105
continue
102106
}
103107

108+
const start = performance.now()
109+
104110
const worker = new Worker(workerPath, {
105111
workerData: {
106112
// Code to load before the test harness and tests.
@@ -126,20 +132,26 @@ export class WPTRunner extends EventEmitter {
126132
}
127133
})
128134

129-
worker.once('exit', () => {
135+
try {
130136
activeWorkers.delete(worker)
131137

132-
if (++finishedFiles === this.#files.length) {
133-
this.handleRunnerCompletion()
134-
}
135-
})
136-
137-
if (activeWorkers.size >= cpus().length) {
138138
await once(worker, 'exit', {
139139
signal: AbortSignal.timeout(timeout)
140140
})
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
141151
}
142152
}
153+
154+
this.handleRunnerCompletion()
143155
}
144156

145157
/**

test/wpt/runner/runner/util.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import assert from 'node:assert'
12
import { exit } from 'node:process'
23
import { inspect } from 'node:util'
4+
import tty from 'node:tty'
35

46
/**
57
* Parse the `Meta:` tags sometimes included in tests.
@@ -132,3 +134,15 @@ export function normalizeName (name) {
132134
}
133135
})
134136
}
137+
138+
export function colors (str, color) {
139+
assert(Object.hasOwn(inspect.colors, color), `Missing color ${color}`)
140+
141+
if (!tty.WriteStream.prototype.hasColors()) {
142+
return str
143+
}
144+
145+
const [start, end] = inspect.colors[color]
146+
147+
return `\u001b[${start}m${str}\u001b[${end}m`
148+
}

test/wpt/start-websockets.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { on } from 'events'
66

77
if (process.env.CI) {
88
// TODO(@KhafraDev): figure out *why* these tests are flaky in the CI.
9-
process.exit(0)
9+
// process.exit(0)
1010
}
1111

1212
const serverPath = fileURLToPath(join(import.meta.url, '../server/websocket.mjs'))

0 commit comments

Comments
 (0)