Skip to content

Commit

Permalink
POC for basic web platform test integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Aug 22, 2024
1 parent bc35e3f commit de0330d
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
11 changes: 11 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,14 @@ new_local_repository(
visibility = ["//visibility:public"],)""",
path = "empty",
)

# ========================================================================================
# Web Platform Tests

http_archive(
name = "wpt",
build_file = "//:build/BUILD.wpt",
integrity = "sha256-2l8wKVITBCYMflmq8qAqWvUPcCdDGwN0r+bMe93Mpww=",
strip_prefix = "wpt-merge_pr_47718",
url = "https://github.com/web-platform-tests/wpt/archive/refs/tags/merge_pr_47718.tar.gz",
)
9 changes: 9 additions & 0 deletions build/BUILD.wpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
filegroup(
name = "url",
srcs = glob(
include = ["url/**/*"],
allow_empty = True,
),
visibility = ["//visibility:public"],
)

16 changes: 16 additions & 0 deletions src/workerd/api/wpt/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("//:build/kj_test.bzl", "kj_test")
load("//:build/wd_cc_library.bzl", "wd_cc_library")
load("//:build/wd_test.bzl", "wd_test")

[wd_test(
src = f,
args = [
"--experimental",
],
data = [
f.removesuffix(".wd-test") + ".js",
"@wpt//:url",
],
) for f in glob(
["**/*.wd-test"],
)]
42 changes: 42 additions & 0 deletions src/workerd/api/wpt/url-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
strictEqual,
} from '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 = [];

export const test = {
async test(_, env) {
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');
}
}
};
28 changes: 28 additions & 0 deletions src/workerd/api/wpt/url-test.wd-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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 = "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 = ".",
)
],
);

0 comments on commit de0330d

Please sign in to comment.