Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions test/wpt/runner/runner/runner.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { deepStrictEqual } from 'node:assert'
import { EventEmitter, once } from 'node:events'
import { readdirSync, readFileSync, statSync } from 'node:fs'
import { cpus } from 'node:os'
import { basename, isAbsolute, join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { Worker } from 'node:worker_threads'
import { parseMeta, handlePipes, normalizeName } from './util.mjs'
import { parseMeta, handlePipes, normalizeName, colors } from './util.mjs'

const basePath = fileURLToPath(join(import.meta.url, '../../..'))
const testPath = join(basePath, 'tests')
Expand Down Expand Up @@ -80,14 +79,14 @@ export class WPTRunner extends EventEmitter {
}
}

return [...files]
return [...files].sort()
}

async run () {
const workerPath = fileURLToPath(join(import.meta.url, '../worker.mjs'))
/** @type {Set<Worker>} */
const activeWorkers = new Set()
let finishedFiles = 0
let finishedFiles = 1

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

if (this.#status[basename(test)]?.skip) {
this.#stats.skipped += 1

console.log('='.repeat(96))
console.log(colors(`[${finishedFiles}/${this.#files.length}] SKIPPED - ${test}`, 'yellow'))
console.log('='.repeat(96))

finishedFiles++
continue
}

const start = performance.now()

const worker = new Worker(workerPath, {
workerData: {
// Code to load before the test harness and tests.
Expand All @@ -126,20 +132,26 @@ export class WPTRunner extends EventEmitter {
}
})

worker.once('exit', () => {
try {
activeWorkers.delete(worker)

if (++finishedFiles === this.#files.length) {
this.handleRunnerCompletion()
}
})

if (activeWorkers.size >= cpus().length) {
await once(worker, 'exit', {
signal: AbortSignal.timeout(timeout)
})

console.log('='.repeat(96))
console.log(colors(`[${finishedFiles}/${this.#files.length}] PASSED - ${test}`, 'green'))
console.log(`Test took ${(performance.now() - start).toFixed(2)}ms`)
console.log('='.repeat(96))

finishedFiles++
} catch (e) {
console.log(`${test} timed out after ${timeout}ms`)
throw e
}
}

this.handleRunnerCompletion()
}

/**
Expand Down
14 changes: 14 additions & 0 deletions test/wpt/runner/runner/util.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import assert from 'node:assert'
import { exit } from 'node:process'
import { inspect } from 'node:util'
import tty from 'node:tty'

/**
* Parse the `Meta:` tags sometimes included in tests.
Expand Down Expand Up @@ -132,3 +134,15 @@ export function normalizeName (name) {
}
})
}

export function colors (str, color) {
assert(Object.hasOwn(inspect.colors, color), `Missing color ${color}`)

if (!tty.WriteStream.prototype.hasColors()) {
return str
}

const [start, end] = inspect.colors[color]

return `\u001b[${start}m${str}\u001b[${end}m`
}
2 changes: 1 addition & 1 deletion test/wpt/start-websockets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { on } from 'events'

if (process.env.CI) {
// TODO(@KhafraDev): figure out *why* these tests are flaky in the CI.
process.exit(0)
// process.exit(0)
}

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