Skip to content

Commit 2a42bf6

Browse files
committed
POC for basic web platform test integration
1 parent bc35e3f commit 2a42bf6

File tree

6 files changed

+111
-0
lines changed

6 files changed

+111
-0
lines changed

Diff for: WORKSPACE

+11
Original file line numberDiff line numberDiff line change
@@ -604,3 +604,14 @@ new_local_repository(
604604
visibility = ["//visibility:public"],)""",
605605
path = "empty",
606606
)
607+
608+
# ========================================================================================
609+
# Web Platform Tests
610+
611+
http_archive(
612+
name = "wpt",
613+
build_file = "//:build/BUILD.wpt",
614+
integrity = "sha256-2l8wKVITBCYMflmq8qAqWvUPcCdDGwN0r+bMe93Mpww=",
615+
strip_prefix = "wpt-merge_pr_47718",
616+
url = "https://github.com/web-platform-tests/wpt/archive/refs/tags/merge_pr_47718.tar.gz",
617+
)

Diff for: build/BUILD.wpt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
exports_files([
2+
"url/url-origin.any.js",
3+
]);
4+
5+
filegroup(
6+
name = "url",
7+
srcs = glob(
8+
include = ["url/**/*"],
9+
allow_empty = True,
10+
),
11+
visibility = ["//visibility:public"],
12+
)
13+

Diff for: src/workerd/api/wpt/BUILD.bazel

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
load("//:build/kj_test.bzl", "kj_test")
2+
load("//:build/wd_cc_library.bzl", "wd_cc_library")
3+
load("//:build/wd_test.bzl", "wd_test")
4+
5+
[wd_test(
6+
src = f,
7+
args = [
8+
"--experimental",
9+
],
10+
data = [
11+
f.removesuffix(".wd-test") + ".js",
12+
"bar.txt",
13+
"@wpt//:url",
14+
],
15+
) for f in glob(
16+
["**/*.wd-test"],
17+
)]

Diff for: src/workerd/api/wpt/bar.txt

Whitespace-only changes.

Diff for: src/workerd/api/wpt/url-test.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {
2+
strictEqual,
3+
} from 'assert';
4+
5+
globalThis.fetch = async(url) => {
6+
const { default: data } = await import(url);
7+
return {
8+
async json() { return data; },
9+
};
10+
};
11+
12+
globalThis.promise_test = (callback) => {
13+
callback();
14+
};
15+
16+
globalThis.assert_equals = (a, b, c) => {
17+
strictEqual(a,b,c);
18+
};
19+
20+
globalThis.test = (callback, message) => {
21+
try {
22+
callback();
23+
} catch (err) {
24+
const aerr = new AggregateError([err], message);
25+
globalThis.errors.push(aerr);
26+
}
27+
}
28+
29+
globalThis.errors = [];
30+
31+
export const test = {
32+
async test(_, env) {
33+
const foo = await import('url-origin.any.js');
34+
35+
if (globalThis.errors.length > 0) {
36+
for (const err of globalThis.errors) {
37+
console.error(err);
38+
}
39+
throw new Error('Test failed');
40+
}
41+
}
42+
};

Diff for: src/workerd/api/wpt/url-test.wd-test

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Workerd = import "/workerd/workerd.capnp";
2+
3+
const unitTests :Workerd.Config = (
4+
services = [
5+
( name = "url-test-test",
6+
worker = (
7+
modules = [
8+
(name = "worker", esModule = embed "url-test.js"),
9+
(name = "url-origin.any.js",
10+
esModule = embed "../../../../../wpt/url/url-origin.any.js"),
11+
(name = "resources/urltestdata.json",
12+
json = embed "../../../../../wpt/url/resources/urltestdata.json"),
13+
(name = "resources/urltestdata-javascript-only.json",
14+
json = embed "../../../../../wpt/url/resources/urltestdata-javascript-only.json"),
15+
],
16+
bindings = [
17+
(name = "wpt", service = "wpt"),
18+
],
19+
compatibilityDate = "2024-07-01",
20+
compatibilityFlags = ["nodejs_compat_v2"],
21+
)
22+
),
23+
(
24+
name = "wpt",
25+
disk = ".",
26+
)
27+
],
28+
);

0 commit comments

Comments
 (0)