Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(wpt): respect variants #1951

Merged
merged 1 commit into from
Feb 21, 2023
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
88 changes: 52 additions & 36 deletions test/wpt/runner/runner/runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,27 @@ export class WPTRunner extends EventEmitter {
/** @type {Set<Worker>} */
const activeWorkers = new Set()
let finishedFiles = 1
let total = this.#files.length

for (const test of this.#files) {
const files = this.#files.map((test) => {
const code = test.includes('.sub.')
? handlePipes(readFileSync(test, 'utf-8'), this.#url)
: readFileSync(test, 'utf-8')
const meta = this.resolveMeta(code, test)

if (meta.variant.length) {
total += meta.variant.length - 1
}

return [test, code, meta]
})

for (const [test, code, meta] of files) {
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(colors(`[${finishedFiles}/${total}] SKIPPED - ${test}`, 'yellow'))
console.log('='.repeat(96))

finishedFiles++
Expand All @@ -107,47 +116,54 @@ export class WPTRunner extends EventEmitter {

const start = performance.now()

const worker = new Worker(workerPath, {
workerData: {
// Code to load before the test harness and tests.
initScripts: this.#initScripts,
// The test file.
test: code,
// Parsed META tag information
meta,
url: this.#url,
path: test
for (const variant of meta.variant.length ? meta.variant : ['']) {
const url = new URL(this.#url)
if (variant) {
url.search = variant
}
})
const worker = new Worker(workerPath, {
workerData: {
// Code to load before the test harness and tests.
initScripts: this.#initScripts,
// The test file.
test: code,
// Parsed META tag information
meta,
url: url.href,
path: test
}
})

activeWorkers.add(worker)
// These values come directly from the web-platform-tests
const timeout = meta.timeout === 'long' ? 60_000 : 10_000
activeWorkers.add(worker)
// These values come directly from the web-platform-tests
const timeout = meta.timeout === 'long' ? 60_000 : 10_000

worker.on('message', (message) => {
if (message.type === 'result') {
this.handleIndividualTestCompletion(message, basename(test))
} else if (message.type === 'completion') {
this.handleTestCompletion(worker)
}
})
worker.on('message', (message) => {
if (message.type === 'result') {
this.handleIndividualTestCompletion(message, basename(test))
} else if (message.type === 'completion') {
this.handleTestCompletion(worker)
}
})

try {
activeWorkers.delete(worker)
try {
activeWorkers.delete(worker)

await once(worker, 'exit', {
signal: AbortSignal.timeout(timeout)
})
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))
console.log('='.repeat(96))
console.log(colors(`[${finishedFiles}/${total}] PASSED - ${test}`, 'green'))
if (variant) console.log('Variant:', variant)
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
finishedFiles++
} catch (e) {
console.log(`${test} timed out after ${timeout}ms`)
throw e
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion test/wpt/runner/runner/util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export function parseMeta (fileContents) {
/** @type {string[]} */
global: [],
/** @type {string[]} */
scripts: []
scripts: [],
/** @type {string[]} */
variant: []
}

for (const line of lines) {
Expand All @@ -42,6 +44,8 @@ export function parseMeta (fileContents) {

switch (groups.type) {
case 'variant':
meta[groups.type].push(groups.match)
break
case 'title':
case 'timeout': {
meta[groups.type] = groups.match
Expand Down