Skip to content

Commit 9639aa4

Browse files
committed
test(wpt): add results to an existing WPT Report
1 parent e0fd923 commit 9639aa4

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

test/wpt/runner/runner/runner.mjs

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
11
import { deepStrictEqual } from 'node:assert'
22
import { EventEmitter, once } from 'node:events'
3-
import { readdirSync, readFileSync, statSync } from 'node:fs'
3+
import { readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
44
import { basename, isAbsolute, join, resolve } from 'node:path'
55
import { fileURLToPath } from 'node:url'
66
import { Worker } from 'node:worker_threads'
77
import { parseMeta, handlePipes, normalizeName, colors } from './util.mjs'
88

9+
const { WPT_REPORT } = process.env
910
const basePath = fileURLToPath(join(import.meta.url, '../../..'))
1011
const testPath = join(basePath, 'tests')
1112
const statusPath = join(basePath, 'status')
1213

14+
// https://github.com/web-platform-tests/wpt/blob/b24eedd/resources/testharness.js#L3705
15+
function sanitizeUnpairedSurrogates (str) {
16+
return str.replace(
17+
/([\ud800-\udbff]+)(?![\udc00-\udfff])|(^|[^\ud800-\udbff])([\udc00-\udfff]+)/g,
18+
function (_, low, prefix, high) {
19+
let output = prefix || '' // Prefix may be undefined
20+
const string = low || high // Only one of these alternates can match
21+
for (let i = 0; i < string.length; i++) {
22+
output += codeUnitStr(string[i])
23+
}
24+
return output
25+
})
26+
}
27+
28+
function codeUnitStr (char) {
29+
return 'U+' + char.charCodeAt(0).toString(16)
30+
}
31+
1332
export class WPTRunner extends EventEmitter {
1433
/** @type {string} */
1534
#folderName
@@ -134,13 +153,29 @@ export class WPTRunner extends EventEmitter {
134153
}
135154
})
136155

156+
let result, report
157+
if (WPT_REPORT) {
158+
report = JSON.parse(readFileSync(WPT_REPORT))
159+
160+
const _foo = new URL(`/${this.#folderName}${test.slice(this.#folderPath.length)}`, 'http://wpt')
161+
_foo.pathname = _foo.pathname.replace(/\.js$/, '.html')
162+
_foo.search = variant
163+
164+
result = {
165+
test: _foo.href.slice(_foo.origin.length),
166+
subtests: [],
167+
status: 'OK'
168+
}
169+
report.results.push(result)
170+
}
171+
137172
activeWorkers.add(worker)
138173
// These values come directly from the web-platform-tests
139174
const timeout = meta.timeout === 'long' ? 60_000 : 10_000
140175

141176
worker.on('message', (message) => {
142177
if (message.type === 'result') {
143-
this.handleIndividualTestCompletion(message, basename(test))
178+
this.handleIndividualTestCompletion(message, basename(test), result)
144179
} else if (message.type === 'completion') {
145180
this.handleTestCompletion(worker)
146181
}
@@ -155,9 +190,14 @@ export class WPTRunner extends EventEmitter {
155190

156191
console.log('='.repeat(96))
157192
console.log(colors(`[${finishedFiles}/${total}] PASSED - ${test}`, 'green'))
193+
if (variant) console.log('Variant:', variant)
158194
console.log(`Test took ${(performance.now() - start).toFixed(2)}ms`)
159195
console.log('='.repeat(96))
160196

197+
if (result?.subtests.length !== 0) {
198+
writeFileSync(WPT_REPORT, JSON.stringify(report))
199+
}
200+
161201
finishedFiles++
162202
} catch (e) {
163203
console.log(`${test} timed out after ${timeout}ms`)
@@ -172,7 +212,7 @@ export class WPTRunner extends EventEmitter {
172212
/**
173213
* Called after a test has succeeded or failed.
174214
*/
175-
handleIndividualTestCompletion (message, fileName) {
215+
handleIndividualTestCompletion (message, fileName, wptResult) {
176216
const { fail, allowUnexpectedFailures, flaky } = this.#status[fileName] ?? this.#status
177217

178218
if (message.type === 'result') {
@@ -181,6 +221,12 @@ export class WPTRunner extends EventEmitter {
181221
if (message.result.status === 1) {
182222
this.#stats.failed += 1
183223

224+
wptResult?.subtests.push({
225+
status: 'FAIL',
226+
name: sanitizeUnpairedSurrogates(message.result.name),
227+
message: sanitizeUnpairedSurrogates(message.result.message)
228+
})
229+
184230
const name = normalizeName(message.result.name)
185231

186232
if (flaky?.includes(name)) {
@@ -196,6 +242,10 @@ export class WPTRunner extends EventEmitter {
196242
console.error(message.result)
197243
}
198244
} else {
245+
wptResult?.subtests.push({
246+
status: 'PASS',
247+
name: sanitizeUnpairedSurrogates(message.result.name)
248+
})
199249
this.#stats.success += 1
200250
}
201251
}

0 commit comments

Comments
 (0)