-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
60 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 |
---|---|---|
@@ -1,12 +1,4 @@ | ||
load("//:build/wd_test.bzl", "wd_test") | ||
load("//src/workerd/api/wpt:generate-tests.bzl", "gen_wpt_tests") | ||
|
||
wd_test( | ||
name = "url-test", | ||
src = "url-test.wd-test", | ||
args = ["--experimental"], | ||
data = [ | ||
"url-test.js", | ||
"//src/wpt:wpt-test-harness", | ||
"@wpt//:url", | ||
], | ||
) | ||
gen_wpt_tests(glob(["**/*.js"])) |
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,62 @@ | ||
load("@bazel_skylib//rules:write_file.bzl", "write_file") | ||
load("//:build/wd_test.bzl", "wd_test") | ||
|
||
# 0 - name of the service | ||
# 1 - es module file path (ex: url-test for url-test.js) | ||
WPT_TEST_TEMPLATE = """ | ||
using Workerd = import "/workerd/workerd.capnp"; | ||
const unitTests :Workerd.Config = ( | ||
services = [ | ||
( name = "{}", | ||
worker = ( | ||
modules = [ | ||
(name = "worker", esModule = embed "{}.js"), | ||
(name = "harness", | ||
esModule = embed "../../../../../workerd/src/wpt/harness.js"), | ||
(name = "url-origin.any.js", | ||
esModule = embed "../../../../../wpt/url/url-origin.any.js"), | ||
(name = "url-constructor.any.js", | ||
esModule = embed "../../../../../wpt/url/url-constructor.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 = ".", | ||
) | ||
], | ||
);""" | ||
|
||
# Example: generate_wd_test_file("url-test") | ||
def generate_wd_test_file(name): | ||
return WPT_TEST_TEMPLATE.format(name, name) | ||
|
||
def gen_wpt_tests(files): | ||
for file in files: | ||
name = file.removesuffix(".js") | ||
src = "{}.wd-test".format(name) | ||
write_file( | ||
name = name + "@rule", | ||
out = src, | ||
content = [generate_wd_test_file(name)], | ||
) | ||
wd_test( | ||
name = name, | ||
src = src, | ||
args = ["--experimental"], | ||
data = [ | ||
file, | ||
"//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 |
---|---|---|
@@ -1,23 +1,17 @@ | ||
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 = { | ||
export const urlConstructor = { | ||
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'); | ||
harness.prepare(); | ||
await import('url-constructor.any.js'); | ||
harness.validate(); | ||
}, | ||
}; | ||
|
||
if (globalThis.errors.length > 0) { | ||
for (const err of globalThis.errors) { | ||
console.error(err); | ||
} | ||
throw new Error('Test failed'); | ||
} | ||
export const urlOrigin = { | ||
async test() { | ||
harness.prepare(); | ||
await import('url-origin.any.js'); | ||
harness.validate(); | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
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