-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POC for basic web platform test integration
- Loading branch information
Showing
7 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
filegroup( | ||
name = "url", | ||
srcs = glob( | ||
include = ["url/**/*"], | ||
allow_empty = True, | ||
), | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("//:build/wd_test.bzl", "wd_test") | ||
|
||
wd_test( | ||
name = "url-test", | ||
src = "url-test.wd-test", | ||
args = ["--experimental"], | ||
data = [ | ||
"url-test.js", | ||
"//src/wpt:wpt-test-harness", | ||
"@wpt//:url", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { strictEqual } from 'assert'; | ||
|
||
// The harness has no exports of it's own but does modify the global | ||
// scope to include the additional stuff the Web Platform Tests expect. | ||
import * as harness from 'harness'; | ||
|
||
export const test = { | ||
async test() { | ||
// The tests will be run when the module is imported. Note that | ||
// there are limitations to this in that the module is not allowed | ||
// to perform any I/O... so any test that requires setTimeout, | ||
// for instance, will fail... this also means we cannot run | ||
// fetch tests from WPT... sad face. | ||
const foo = await import('url-origin.any.js'); | ||
|
||
if (globalThis.errors.length > 0) { | ||
for (const err of globalThis.errors) { | ||
console.error(err); | ||
} | ||
throw new Error('Test failed'); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Workerd = import "/workerd/workerd.capnp"; | ||
|
||
const unitTests :Workerd.Config = ( | ||
services = [ | ||
( name = "url-test-test", | ||
worker = ( | ||
modules = [ | ||
(name = "worker", esModule = embed "url-test.js"), | ||
(name = "harness", | ||
esModule = embed "../../../../../workerd/src/wpt/harness.js"), | ||
(name = "url-origin.any.js", | ||
esModule = embed "../../../../../wpt/url/url-origin.any.js"), | ||
(name = "resources/urltestdata.json", | ||
json = embed "../../../../../wpt/url/resources/urltestdata.json"), | ||
(name = "resources/urltestdata-javascript-only.json", | ||
json = embed "../../../../../wpt/url/resources/urltestdata-javascript-only.json"), | ||
], | ||
bindings = [ | ||
(name = "wpt", service = "wpt"), | ||
], | ||
compatibilityDate = "2024-07-01", | ||
compatibilityFlags = ["nodejs_compat_v2"], | ||
) | ||
), | ||
( | ||
name = "wpt", | ||
disk = ".", | ||
) | ||
], | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
filegroup( | ||
name = "wpt-test-harness", | ||
srcs = glob( | ||
include = ["**/*"], | ||
allow_empty = True, | ||
), | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { strictEqual } from 'node:assert'; | ||
|
||
globalThis.fetch = async (url) => { | ||
const { default: data } = await import(url); | ||
return { | ||
async json() { | ||
return data; | ||
}, | ||
}; | ||
}; | ||
|
||
globalThis.promise_test = (callback) => { | ||
callback(); | ||
}; | ||
|
||
globalThis.assert_equals = (a, b, c) => { | ||
strictEqual(a, b, c); | ||
}; | ||
|
||
globalThis.test = (callback, message) => { | ||
try { | ||
callback(); | ||
} catch (err) { | ||
const aerr = new AggregateError([err], message); | ||
globalThis.errors.push(aerr); | ||
} | ||
}; | ||
|
||
globalThis.errors = []; |