Skip to content

Commit

Permalink
test(wpt): respect variants
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Feb 20, 2023
1 parent d8d9a96 commit e0fd923
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 37 deletions.
87 changes: 51 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,53 @@ 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'))
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

0 comments on commit e0fd923

Please sign in to comment.