2021-01-27 09:06:18 -05:00
|
|
|
#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-net --allow-env --allow-run
|
2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2021-01-27 09:06:18 -05:00
|
|
|
|
|
|
|
// This script is used to run WPT tests for Deno.
|
|
|
|
|
|
|
|
import {
|
|
|
|
runSingleTest,
|
|
|
|
runWithTestUtil,
|
|
|
|
TestCaseResult,
|
|
|
|
TestResult,
|
|
|
|
} from "./wpt/runner.ts";
|
|
|
|
import {
|
|
|
|
assert,
|
|
|
|
autoConfig,
|
|
|
|
cargoBuild,
|
|
|
|
checkPy3Available,
|
2021-07-07 13:56:47 -04:00
|
|
|
escapeLoneSurrogates,
|
2021-01-27 09:06:18 -05:00
|
|
|
Expectation,
|
2021-06-06 12:08:50 -04:00
|
|
|
generateRunInfo,
|
2021-01-27 09:06:18 -05:00
|
|
|
getExpectation,
|
|
|
|
getExpectFailForCase,
|
|
|
|
getManifest,
|
2022-01-06 05:24:37 -05:00
|
|
|
inspectBrk,
|
2021-01-27 09:06:18 -05:00
|
|
|
json,
|
|
|
|
ManifestFolder,
|
|
|
|
ManifestTestOptions,
|
|
|
|
ManifestTestVariation,
|
2023-03-02 17:05:17 -05:00
|
|
|
noIgnore,
|
2021-01-27 09:06:18 -05:00
|
|
|
quiet,
|
|
|
|
rest,
|
|
|
|
runPy,
|
|
|
|
updateManifest,
|
2021-06-06 12:08:50 -04:00
|
|
|
wptreport,
|
2021-01-27 09:06:18 -05:00
|
|
|
} from "./wpt/utils.ts";
|
2023-01-12 19:12:20 -05:00
|
|
|
import { pooledMap } from "../test_util/std/async/pool.ts";
|
2021-06-25 20:02:31 -04:00
|
|
|
import { blue, bold, green, red, yellow } from "../test_util/std/fmt/colors.ts";
|
2023-01-15 15:09:26 -05:00
|
|
|
import { writeAll, writeAllSync } from "../test_util/std/streams/write_all.ts";
|
2021-01-27 09:06:18 -05:00
|
|
|
import { saveExpectation } from "./wpt/utils.ts";
|
|
|
|
|
|
|
|
const command = Deno.args[0];
|
|
|
|
|
|
|
|
switch (command) {
|
|
|
|
case "setup":
|
|
|
|
await checkPy3Available();
|
|
|
|
await updateManifest();
|
|
|
|
await setup();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "run":
|
|
|
|
await cargoBuild();
|
|
|
|
await run();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "update":
|
|
|
|
await cargoBuild();
|
|
|
|
await update();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
console.log(`Possible commands:
|
|
|
|
|
|
|
|
setup
|
2021-01-28 04:10:16 -05:00
|
|
|
Validate that your environment is configured correctly, or help you configure it.
|
2021-01-27 09:06:18 -05:00
|
|
|
|
|
|
|
run
|
|
|
|
Run all tests like specified in \`expectation.json\`.
|
|
|
|
|
|
|
|
update
|
|
|
|
Update the \`expectation.json\` to match the current reality.
|
|
|
|
|
2021-02-19 09:58:19 -05:00
|
|
|
More details at https://deno.land/manual@main/contributing/web_platform_tests
|
2021-01-27 09:06:18 -05:00
|
|
|
|
|
|
|
`);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function setup() {
|
2021-06-14 14:57:02 -04:00
|
|
|
const hostsPath = Deno.build.os == "windows"
|
|
|
|
? `${Deno.env.get("SystemRoot")}\\System32\\drivers\\etc\\hosts`
|
|
|
|
: "/etc/hosts";
|
2021-01-27 09:06:18 -05:00
|
|
|
// TODO(lucacsonato): use this when 1.7.1 is released.
|
|
|
|
// const records = await Deno.resolveDns("web-platform.test", "A");
|
|
|
|
// const etcHostsConfigured = records[0] == "127.0.0.1";
|
2021-06-14 14:57:02 -04:00
|
|
|
const hostsFile = await Deno.readTextFile(hostsPath);
|
2021-01-27 09:06:18 -05:00
|
|
|
const etcHostsConfigured = hostsFile.includes("web-platform.test");
|
|
|
|
|
|
|
|
if (etcHostsConfigured) {
|
2021-06-14 14:57:02 -04:00
|
|
|
console.log(hostsPath + " is already configured.");
|
2021-01-27 09:06:18 -05:00
|
|
|
} else {
|
|
|
|
const autoConfigure = autoConfig ||
|
|
|
|
confirm(
|
2021-06-14 14:57:02 -04:00
|
|
|
`The WPT require certain entries to be present in your ${hostsPath} file. Should these be configured automatically?`,
|
2021-01-27 09:06:18 -05:00
|
|
|
);
|
|
|
|
if (autoConfigure) {
|
2022-08-05 06:48:54 -04:00
|
|
|
const { success, stdout } = await runPy(["wpt", "make-hosts-file"], {
|
2022-05-18 16:00:11 -04:00
|
|
|
stdout: "piped",
|
|
|
|
}).output();
|
2022-08-05 06:48:54 -04:00
|
|
|
assert(success, "wpt make-hosts-file should not fail");
|
2022-05-18 16:00:11 -04:00
|
|
|
const entries = new TextDecoder().decode(stdout);
|
2021-01-27 09:06:18 -05:00
|
|
|
const file = await Deno.open(hostsPath, { append: true }).catch((err) => {
|
|
|
|
if (err instanceof Deno.errors.PermissionDenied) {
|
|
|
|
throw new Error(
|
|
|
|
`Failed to open ${hostsPath} (permission error). Please run this command again with sudo, or configure the entries manually.`,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
});
|
2021-05-10 06:02:47 -04:00
|
|
|
await writeAll(
|
2021-01-27 09:06:18 -05:00
|
|
|
file,
|
|
|
|
new TextEncoder().encode(
|
|
|
|
"\n\n# Configured for Web Platform Tests (Deno)\n" + entries,
|
|
|
|
),
|
|
|
|
);
|
2021-06-14 14:57:02 -04:00
|
|
|
console.log(`Updated ${hostsPath}`);
|
2021-01-27 09:06:18 -05:00
|
|
|
} else {
|
2021-06-14 14:57:02 -04:00
|
|
|
console.log(`Please configure the ${hostsPath} entries manually.`);
|
2021-01-27 09:06:18 -05:00
|
|
|
if (Deno.build.os == "windows") {
|
|
|
|
console.log("To do this run the following command in PowerShell:");
|
|
|
|
console.log("");
|
|
|
|
console.log(" cd test_util/wpt/");
|
|
|
|
console.log(
|
|
|
|
" python.exe wpt make-hosts-file | Out-File $env:SystemRoot\\System32\\drivers\\etc\\hosts -Encoding ascii -Append",
|
|
|
|
);
|
|
|
|
console.log("");
|
|
|
|
} else {
|
|
|
|
console.log("To do this run the following command in your shell:");
|
|
|
|
console.log("");
|
|
|
|
console.log(" cd test_util/wpt/");
|
|
|
|
console.log(
|
|
|
|
" python3 ./wpt make-hosts-file | sudo tee -a /etc/hosts",
|
|
|
|
);
|
|
|
|
console.log("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(green("Setup complete!"));
|
|
|
|
}
|
|
|
|
|
|
|
|
interface TestToRun {
|
|
|
|
path: string;
|
|
|
|
url: URL;
|
|
|
|
options: ManifestTestOptions;
|
|
|
|
expectation: boolean | string[];
|
|
|
|
}
|
|
|
|
|
2023-05-10 15:35:42 -04:00
|
|
|
function getTestTimeout(test: TestToRun) {
|
|
|
|
if (Deno.env.get("CI")) {
|
|
|
|
// Don't give expected failures the full time
|
|
|
|
if (test.expectation === false) {
|
|
|
|
return { long: 60_000, default: 10_000 };
|
|
|
|
}
|
|
|
|
return { long: 4 * 60_000, default: 4 * 60_000 };
|
|
|
|
}
|
|
|
|
|
|
|
|
return { long: 60_000, default: 10_000 };
|
|
|
|
}
|
|
|
|
|
2021-01-27 09:06:18 -05:00
|
|
|
async function run() {
|
2021-06-06 12:08:50 -04:00
|
|
|
const startTime = new Date().getTime();
|
2021-01-27 09:06:18 -05:00
|
|
|
assert(Array.isArray(rest), "filter must be array");
|
2021-05-09 10:32:30 -04:00
|
|
|
const expectation = getExpectation();
|
|
|
|
const tests = discoverTestsToRun(
|
|
|
|
rest.length == 0 ? undefined : rest,
|
|
|
|
expectation,
|
|
|
|
);
|
2021-05-10 06:02:47 -04:00
|
|
|
assertAllExpectationsHaveTests(expectation, tests, rest);
|
2023-05-10 15:35:42 -04:00
|
|
|
const cores = navigator.hardwareConcurrency;
|
|
|
|
console.log(`Going to run ${tests.length} test files on ${cores} cores.`);
|
2021-01-27 09:06:18 -05:00
|
|
|
|
|
|
|
const results = await runWithTestUtil(false, async () => {
|
2023-01-12 19:12:20 -05:00
|
|
|
const results: { test: TestToRun; result: TestResult }[] = [];
|
|
|
|
const inParallel = !(cores === 1 || tests.length === 1);
|
|
|
|
// ideally we would parallelize all tests, but we ran into some flakiness
|
|
|
|
// on the CI, so here we're partitioning based on the start of the test path
|
|
|
|
const partitionedTests = partitionTests(tests);
|
|
|
|
|
|
|
|
const iter = pooledMap(cores, partitionedTests, async (tests) => {
|
|
|
|
for (const test of tests) {
|
|
|
|
if (!inParallel) {
|
|
|
|
console.log(`${blue("-".repeat(40))}\n${bold(test.path)}\n`);
|
|
|
|
}
|
|
|
|
const result = await runSingleTest(
|
|
|
|
test.url,
|
|
|
|
test.options,
|
|
|
|
inParallel ? () => {} : createReportTestCase(test.expectation),
|
|
|
|
inspectBrk,
|
2023-05-10 15:35:42 -04:00
|
|
|
getTestTimeout(test),
|
2023-01-12 19:12:20 -05:00
|
|
|
);
|
|
|
|
results.push({ test, result });
|
|
|
|
if (inParallel) {
|
|
|
|
console.log(`${blue("-".repeat(40))}\n${bold(test.path)}\n`);
|
|
|
|
}
|
|
|
|
reportVariation(result, test.expectation);
|
|
|
|
}
|
|
|
|
});
|
2021-01-27 09:06:18 -05:00
|
|
|
|
2023-01-12 19:12:20 -05:00
|
|
|
for await (const _ of iter) {
|
|
|
|
// ignore
|
2021-01-27 09:06:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
});
|
2021-06-06 12:08:50 -04:00
|
|
|
const endTime = new Date().getTime();
|
2021-01-27 09:06:18 -05:00
|
|
|
|
|
|
|
if (json) {
|
2021-06-02 19:12:28 -04:00
|
|
|
const minifiedResults = [];
|
|
|
|
for (const result of results) {
|
|
|
|
const minified = {
|
|
|
|
file: result.test.path,
|
|
|
|
name:
|
|
|
|
Object.fromEntries(result.test.options.script_metadata ?? []).title ??
|
|
|
|
null,
|
|
|
|
cases: result.result.cases.map((case_) => ({
|
|
|
|
name: case_.name,
|
|
|
|
passed: case_.passed,
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
minifiedResults.push(minified);
|
|
|
|
}
|
|
|
|
await Deno.writeTextFile(json, JSON.stringify(minifiedResults));
|
2021-01-27 09:06:18 -05:00
|
|
|
}
|
2021-06-06 12:08:50 -04:00
|
|
|
|
|
|
|
if (wptreport) {
|
2021-06-23 11:46:15 -04:00
|
|
|
const report = await generateWptReport(results, startTime, endTime);
|
2021-06-06 12:08:50 -04:00
|
|
|
await Deno.writeTextFile(wptreport, JSON.stringify(report));
|
|
|
|
}
|
|
|
|
|
2023-04-13 10:03:15 -04:00
|
|
|
const code = reportFinal(results, endTime - startTime);
|
2021-01-27 09:06:18 -05:00
|
|
|
Deno.exit(code);
|
|
|
|
}
|
|
|
|
|
2021-06-23 11:46:15 -04:00
|
|
|
async function generateWptReport(
|
2021-06-06 12:08:50 -04:00
|
|
|
results: { test: TestToRun; result: TestResult }[],
|
|
|
|
startTime: number,
|
|
|
|
endTime: number,
|
|
|
|
) {
|
|
|
|
const runInfo = await generateRunInfo();
|
|
|
|
const reportResults = [];
|
|
|
|
for (const { test, result } of results) {
|
|
|
|
const status = result.status !== 0
|
|
|
|
? "CRASH"
|
|
|
|
: result.harnessStatus?.status === 0
|
|
|
|
? "OK"
|
|
|
|
: "ERROR";
|
2021-07-12 15:15:07 -04:00
|
|
|
let message;
|
|
|
|
if (result.harnessStatus === null && result.status === 0) {
|
|
|
|
// If the only error is the event loop running out of tasks, using stderr
|
|
|
|
// as the message won't help.
|
|
|
|
message = "Event loop run out of tasks.";
|
|
|
|
} else {
|
|
|
|
message = result.harnessStatus?.message ?? (result.stderr.trim() || null);
|
|
|
|
}
|
2021-06-06 12:08:50 -04:00
|
|
|
const reportResult = {
|
|
|
|
test: test.url.pathname + test.url.search + test.url.hash,
|
|
|
|
subtests: result.cases.map((case_) => {
|
|
|
|
let expected = undefined;
|
|
|
|
if (!case_.passed) {
|
|
|
|
if (typeof test.expectation === "boolean") {
|
|
|
|
expected = test.expectation ? "PASS" : "FAIL";
|
2023-03-03 08:50:18 -05:00
|
|
|
} else if (Array.isArray(test.expectation)) {
|
2021-06-06 12:08:50 -04:00
|
|
|
expected = test.expectation.includes(case_.name) ? "FAIL" : "PASS";
|
2023-03-03 08:50:18 -05:00
|
|
|
} else {
|
|
|
|
expected = "PASS";
|
2021-06-06 12:08:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2021-07-07 13:56:47 -04:00
|
|
|
name: escapeLoneSurrogates(case_.name),
|
2021-06-06 12:08:50 -04:00
|
|
|
status: case_.passed ? "PASS" : "FAIL",
|
2021-07-07 13:56:47 -04:00
|
|
|
message: escapeLoneSurrogates(case_.message),
|
2021-06-06 12:08:50 -04:00
|
|
|
expected,
|
|
|
|
known_intermittent: [],
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
status,
|
2021-07-12 15:15:07 -04:00
|
|
|
message: escapeLoneSurrogates(message),
|
2021-06-06 12:08:50 -04:00
|
|
|
duration: result.duration,
|
|
|
|
expected: status === "OK" ? undefined : "OK",
|
|
|
|
"known_intermittent": [],
|
|
|
|
};
|
|
|
|
reportResults.push(reportResult);
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
"run_info": runInfo,
|
|
|
|
"time_start": startTime,
|
|
|
|
"time_end": endTime,
|
|
|
|
"results": reportResults,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-09 10:32:30 -04:00
|
|
|
// Check that all expectations in the expectations file have a test that will be
|
|
|
|
// run.
|
|
|
|
function assertAllExpectationsHaveTests(
|
|
|
|
expectation: Expectation,
|
|
|
|
testsToRun: TestToRun[],
|
2021-05-10 06:02:47 -04:00
|
|
|
filter?: string[],
|
2021-05-09 10:32:30 -04:00
|
|
|
): void {
|
|
|
|
const tests = new Set(testsToRun.map((t) => t.path));
|
|
|
|
const missingTests: string[] = [];
|
|
|
|
|
|
|
|
function walk(parentExpectation: Expectation, parent: string) {
|
2023-01-16 11:17:18 -05:00
|
|
|
for (const [key, expectation] of Object.entries(parentExpectation)) {
|
2021-05-09 10:32:30 -04:00
|
|
|
const path = `${parent}/${key}`;
|
2021-05-10 06:02:47 -04:00
|
|
|
if (
|
|
|
|
filter &&
|
|
|
|
!filter.find((filter) => path.substring(1).startsWith(filter))
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-05-09 10:32:30 -04:00
|
|
|
if (typeof expectation == "boolean" || Array.isArray(expectation)) {
|
|
|
|
if (!tests.has(path)) {
|
|
|
|
missingTests.push(path);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
walk(expectation, path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
walk(expectation, "");
|
|
|
|
|
|
|
|
if (missingTests.length > 0) {
|
|
|
|
console.log(
|
|
|
|
red(
|
|
|
|
"Following tests are missing in manifest, but are present in expectations:",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
console.log("");
|
|
|
|
console.log(missingTests.join("\n"));
|
|
|
|
Deno.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-27 09:06:18 -05:00
|
|
|
async function update() {
|
|
|
|
assert(Array.isArray(rest), "filter must be array");
|
2023-04-13 10:03:15 -04:00
|
|
|
const startTime = new Date().getTime();
|
2021-01-27 09:06:18 -05:00
|
|
|
const tests = discoverTestsToRun(rest.length == 0 ? undefined : rest, true);
|
|
|
|
console.log(`Going to run ${tests.length} test files.`);
|
|
|
|
|
|
|
|
const results = await runWithTestUtil(false, async () => {
|
|
|
|
const results = [];
|
|
|
|
|
|
|
|
for (const test of tests) {
|
|
|
|
console.log(`${blue("-".repeat(40))}\n${bold(test.path)}\n`);
|
|
|
|
const result = await runSingleTest(
|
|
|
|
test.url,
|
|
|
|
test.options,
|
|
|
|
json ? () => {} : createReportTestCase(test.expectation),
|
2022-01-06 05:24:37 -05:00
|
|
|
inspectBrk,
|
2023-03-02 17:05:17 -05:00
|
|
|
{ long: 60_000, default: 10_000 },
|
2021-01-27 09:06:18 -05:00
|
|
|
);
|
|
|
|
results.push({ test, result });
|
|
|
|
reportVariation(result, test.expectation);
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
});
|
2023-04-13 10:03:15 -04:00
|
|
|
const endTime = new Date().getTime();
|
2021-01-27 09:06:18 -05:00
|
|
|
|
|
|
|
if (json) {
|
|
|
|
await Deno.writeTextFile(json, JSON.stringify(results));
|
|
|
|
}
|
|
|
|
|
|
|
|
const resultTests: Record<
|
|
|
|
string,
|
2021-07-12 15:15:07 -04:00
|
|
|
{ passed: string[]; failed: string[]; testSucceeded: boolean }
|
2021-01-27 09:06:18 -05:00
|
|
|
> = {};
|
|
|
|
for (const { test, result } of results) {
|
2021-05-09 10:32:30 -04:00
|
|
|
if (!resultTests[test.path]) {
|
|
|
|
resultTests[test.path] = {
|
2021-01-27 09:06:18 -05:00
|
|
|
passed: [],
|
|
|
|
failed: [],
|
2021-07-12 15:15:07 -04:00
|
|
|
testSucceeded: result.status === 0 && result.harnessStatus !== null,
|
2021-01-27 09:06:18 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
for (const case_ of result.cases) {
|
|
|
|
if (case_.passed) {
|
2021-05-09 10:32:30 -04:00
|
|
|
resultTests[test.path].passed.push(case_.name);
|
2021-01-27 09:06:18 -05:00
|
|
|
} else {
|
2021-05-09 10:32:30 -04:00
|
|
|
resultTests[test.path].failed.push(case_.name);
|
2021-01-27 09:06:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const currentExpectation = getExpectation();
|
|
|
|
|
2023-03-02 17:05:17 -05:00
|
|
|
for (const [path, result] of Object.entries(resultTests)) {
|
2023-01-16 11:17:18 -05:00
|
|
|
const { passed, failed, testSucceeded } = result;
|
2021-01-27 09:06:18 -05:00
|
|
|
let finalExpectation: boolean | string[];
|
2021-07-12 15:15:07 -04:00
|
|
|
if (failed.length == 0 && testSucceeded) {
|
2021-01-27 09:06:18 -05:00
|
|
|
finalExpectation = true;
|
2021-07-12 15:15:07 -04:00
|
|
|
} else if (failed.length > 0 && passed.length > 0 && testSucceeded) {
|
2021-01-27 09:06:18 -05:00
|
|
|
finalExpectation = failed;
|
|
|
|
} else {
|
|
|
|
finalExpectation = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
insertExpectation(
|
|
|
|
path.slice(1).split("/"),
|
|
|
|
currentExpectation,
|
|
|
|
finalExpectation,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
saveExpectation(currentExpectation);
|
|
|
|
|
2023-04-13 10:03:15 -04:00
|
|
|
reportFinal(results, endTime - startTime);
|
2021-01-27 09:06:18 -05:00
|
|
|
|
|
|
|
console.log(blue("Updated expectation.json to match reality."));
|
|
|
|
|
|
|
|
Deno.exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
function insertExpectation(
|
|
|
|
segments: string[],
|
|
|
|
currentExpectation: Expectation,
|
|
|
|
finalExpectation: boolean | string[],
|
|
|
|
) {
|
|
|
|
const segment = segments.shift();
|
|
|
|
assert(segment, "segments array must never be empty");
|
|
|
|
if (segments.length > 0) {
|
|
|
|
if (
|
|
|
|
!currentExpectation[segment] ||
|
|
|
|
Array.isArray(currentExpectation[segment]) ||
|
|
|
|
typeof currentExpectation[segment] === "boolean"
|
|
|
|
) {
|
|
|
|
currentExpectation[segment] = {};
|
|
|
|
}
|
|
|
|
insertExpectation(
|
|
|
|
segments,
|
|
|
|
currentExpectation[segment] as Expectation,
|
|
|
|
finalExpectation,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
currentExpectation[segment] = finalExpectation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function reportFinal(
|
|
|
|
results: { test: TestToRun; result: TestResult }[],
|
2023-04-13 10:03:15 -04:00
|
|
|
duration: number,
|
2021-01-27 09:06:18 -05:00
|
|
|
): number {
|
|
|
|
const finalTotalCount = results.length;
|
|
|
|
let finalFailedCount = 0;
|
|
|
|
const finalFailed: [string, TestCaseResult][] = [];
|
|
|
|
let finalExpectedFailedAndFailedCount = 0;
|
|
|
|
const finalExpectedFailedButPassedTests: [string, TestCaseResult][] = [];
|
|
|
|
const finalExpectedFailedButPassedFiles: string[] = [];
|
2021-06-05 13:29:41 -04:00
|
|
|
const finalFailedFiles: string[] = [];
|
2021-01-27 09:06:18 -05:00
|
|
|
for (const { test, result } of results) {
|
2021-06-05 13:29:41 -04:00
|
|
|
const {
|
|
|
|
failed,
|
|
|
|
failedCount,
|
|
|
|
expectedFailedButPassed,
|
|
|
|
expectedFailedAndFailedCount,
|
|
|
|
} = analyzeTestResult(
|
2021-01-27 09:06:18 -05:00
|
|
|
result,
|
|
|
|
test.expectation,
|
|
|
|
);
|
2021-07-12 15:15:07 -04:00
|
|
|
if (result.status !== 0 || result.harnessStatus === null) {
|
2021-01-27 09:06:18 -05:00
|
|
|
if (test.expectation === false) {
|
|
|
|
finalExpectedFailedAndFailedCount += 1;
|
|
|
|
} else {
|
|
|
|
finalFailedCount += 1;
|
2021-06-05 13:29:41 -04:00
|
|
|
finalFailedFiles.push(test.path);
|
2021-01-27 09:06:18 -05:00
|
|
|
}
|
|
|
|
} else if (failedCount > 0) {
|
|
|
|
finalFailedCount += 1;
|
|
|
|
for (const case_ of failed) {
|
|
|
|
finalFailed.push([test.path, case_]);
|
|
|
|
}
|
|
|
|
for (const case_ of expectedFailedButPassed) {
|
|
|
|
finalExpectedFailedButPassedTests.push([test.path, case_]);
|
|
|
|
}
|
2021-06-05 13:29:41 -04:00
|
|
|
} else if (
|
|
|
|
test.expectation === false &&
|
|
|
|
expectedFailedAndFailedCount != result.cases.length
|
|
|
|
) {
|
|
|
|
finalExpectedFailedButPassedFiles.push(test.path);
|
2021-01-27 09:06:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const finalPassedCount = finalTotalCount - finalFailedCount;
|
|
|
|
|
|
|
|
console.log(bold(blue("=".repeat(40))));
|
|
|
|
|
|
|
|
if (finalFailed.length > 0) {
|
|
|
|
console.log(`\nfailures:\n`);
|
|
|
|
}
|
|
|
|
for (const result of finalFailed) {
|
|
|
|
console.log(
|
|
|
|
` ${JSON.stringify(`${result[0]} - ${result[1].name}`)}`,
|
|
|
|
);
|
|
|
|
}
|
2021-06-05 13:29:41 -04:00
|
|
|
if (finalFailedFiles.length > 0) {
|
|
|
|
console.log(`\nfile failures:\n`);
|
|
|
|
}
|
|
|
|
for (const result of finalFailedFiles) {
|
|
|
|
console.log(
|
|
|
|
` ${JSON.stringify(result)}`,
|
|
|
|
);
|
|
|
|
}
|
2021-01-27 09:06:18 -05:00
|
|
|
if (finalExpectedFailedButPassedTests.length > 0) {
|
|
|
|
console.log(`\nexpected test failures that passed:\n`);
|
|
|
|
}
|
|
|
|
for (const result of finalExpectedFailedButPassedTests) {
|
|
|
|
console.log(
|
|
|
|
` ${JSON.stringify(`${result[0]} - ${result[1].name}`)}`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (finalExpectedFailedButPassedFiles.length > 0) {
|
|
|
|
console.log(`\nexpected file failures that passed:\n`);
|
|
|
|
}
|
|
|
|
for (const result of finalExpectedFailedButPassedFiles) {
|
|
|
|
console.log(` ${JSON.stringify(result)}`);
|
|
|
|
}
|
|
|
|
|
2021-06-05 13:29:41 -04:00
|
|
|
const failed = (finalFailedCount > 0) ||
|
|
|
|
(finalExpectedFailedButPassedFiles.length > 0);
|
|
|
|
|
2021-01-27 09:06:18 -05:00
|
|
|
console.log(
|
|
|
|
`\nfinal result: ${
|
2021-06-05 13:29:41 -04:00
|
|
|
failed ? red("failed") : green("ok")
|
2023-04-13 10:03:15 -04:00
|
|
|
}. ${finalPassedCount} passed; ${finalFailedCount} failed; ${finalExpectedFailedAndFailedCount} expected failure; total ${finalTotalCount} (${duration}ms)\n`,
|
2021-01-27 09:06:18 -05:00
|
|
|
);
|
|
|
|
|
2021-06-05 13:29:41 -04:00
|
|
|
return failed ? 1 : 0;
|
2021-01-27 09:06:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function analyzeTestResult(
|
|
|
|
result: TestResult,
|
|
|
|
expectation: boolean | string[],
|
|
|
|
): {
|
|
|
|
failed: TestCaseResult[];
|
|
|
|
failedCount: number;
|
|
|
|
passedCount: number;
|
|
|
|
totalCount: number;
|
|
|
|
expectedFailedButPassed: TestCaseResult[];
|
|
|
|
expectedFailedButPassedCount: number;
|
|
|
|
expectedFailedAndFailedCount: number;
|
|
|
|
} {
|
|
|
|
const failed = result.cases.filter(
|
|
|
|
(t) => !getExpectFailForCase(expectation, t.name) && !t.passed,
|
|
|
|
);
|
|
|
|
const expectedFailedButPassed = result.cases.filter(
|
|
|
|
(t) => getExpectFailForCase(expectation, t.name) && t.passed,
|
|
|
|
);
|
|
|
|
const expectedFailedButPassedCount = expectedFailedButPassed.length;
|
|
|
|
const failedCount = failed.length + expectedFailedButPassedCount;
|
|
|
|
const expectedFailedAndFailedCount = result.cases.filter(
|
|
|
|
(t) => getExpectFailForCase(expectation, t.name) && !t.passed,
|
|
|
|
).length;
|
|
|
|
const totalCount = result.cases.length;
|
|
|
|
const passedCount = totalCount - failedCount - expectedFailedAndFailedCount;
|
|
|
|
|
|
|
|
return {
|
|
|
|
failed,
|
|
|
|
failedCount,
|
|
|
|
passedCount,
|
|
|
|
totalCount,
|
|
|
|
expectedFailedButPassed,
|
|
|
|
expectedFailedButPassedCount,
|
|
|
|
expectedFailedAndFailedCount,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function reportVariation(result: TestResult, expectation: boolean | string[]) {
|
2021-07-12 15:15:07 -04:00
|
|
|
if (result.status !== 0 || result.harnessStatus === null) {
|
2023-06-29 09:24:01 -04:00
|
|
|
if (result.stderr) {
|
|
|
|
console.log(`test stderr:\n${result.stderr}\n`);
|
|
|
|
}
|
2021-01-27 09:06:18 -05:00
|
|
|
|
|
|
|
const expectFail = expectation === false;
|
2021-07-12 15:15:07 -04:00
|
|
|
const failReason = result.status !== 0
|
|
|
|
? "runner failed during test"
|
|
|
|
: "the event loop run out of tasks during the test";
|
2021-01-27 09:06:18 -05:00
|
|
|
console.log(
|
|
|
|
`\nfile result: ${
|
|
|
|
expectFail ? yellow("failed (expected)") : red("failed")
|
2023-04-13 10:03:15 -04:00
|
|
|
}. ${failReason} (${formatDuration(result.duration)})\n`,
|
2021-01-27 09:06:18 -05:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
failed,
|
|
|
|
failedCount,
|
|
|
|
passedCount,
|
|
|
|
totalCount,
|
|
|
|
expectedFailedButPassed,
|
|
|
|
expectedFailedButPassedCount,
|
|
|
|
expectedFailedAndFailedCount,
|
|
|
|
} = analyzeTestResult(result, expectation);
|
|
|
|
|
|
|
|
if (failed.length > 0) {
|
|
|
|
console.log(`\nfailures:`);
|
|
|
|
}
|
|
|
|
for (const result of failed) {
|
|
|
|
console.log(`\n${result.name}\n${result.message}\n${result.stack}`);
|
|
|
|
}
|
|
|
|
|
2021-06-05 13:29:41 -04:00
|
|
|
if (failedCount > 0) {
|
2021-01-27 09:06:18 -05:00
|
|
|
console.log(`\nfailures:\n`);
|
|
|
|
}
|
|
|
|
for (const result of failed) {
|
|
|
|
console.log(` ${JSON.stringify(result.name)}`);
|
|
|
|
}
|
|
|
|
if (expectedFailedButPassedCount > 0) {
|
|
|
|
console.log(`\nexpected failures that passed:\n`);
|
|
|
|
}
|
|
|
|
for (const result of expectedFailedButPassed) {
|
|
|
|
console.log(` ${JSON.stringify(result.name)}`);
|
|
|
|
}
|
2023-06-29 09:24:01 -04:00
|
|
|
if (result.stderr) {
|
|
|
|
console.log("\ntest stderr:\n" + result.stderr);
|
|
|
|
}
|
2021-01-27 09:06:18 -05:00
|
|
|
console.log(
|
|
|
|
`\nfile result: ${
|
|
|
|
failedCount > 0 ? red("failed") : green("ok")
|
2023-04-13 10:03:15 -04:00
|
|
|
}. ${passedCount} passed; ${failedCount} failed; ${expectedFailedAndFailedCount} expected failure; total ${totalCount} (${
|
|
|
|
formatDuration(result.duration)
|
|
|
|
})\n`,
|
2021-01-27 09:06:18 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function createReportTestCase(expectation: boolean | string[]) {
|
|
|
|
return function reportTestCase({ name, status }: TestCaseResult) {
|
|
|
|
const expectFail = getExpectFailForCase(expectation, name);
|
|
|
|
let simpleMessage = `test ${name} ... `;
|
|
|
|
switch (status) {
|
|
|
|
case 0:
|
|
|
|
if (expectFail) {
|
|
|
|
simpleMessage += red("ok (expected fail)");
|
|
|
|
} else {
|
|
|
|
simpleMessage += green("ok");
|
|
|
|
if (quiet) {
|
|
|
|
// don't print `ok` tests if --quiet is enabled
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (expectFail) {
|
|
|
|
simpleMessage += yellow("failed (expected)");
|
|
|
|
} else {
|
|
|
|
simpleMessage += red("failed");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (expectFail) {
|
|
|
|
simpleMessage += yellow("failed (expected)");
|
|
|
|
} else {
|
|
|
|
simpleMessage += red("failed (timeout)");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (expectFail) {
|
|
|
|
simpleMessage += yellow("failed (expected)");
|
|
|
|
} else {
|
|
|
|
simpleMessage += red("failed (incomplete)");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-05-10 06:02:47 -04:00
|
|
|
writeAllSync(Deno.stdout, new TextEncoder().encode(simpleMessage + "\n"));
|
2021-01-27 09:06:18 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function discoverTestsToRun(
|
|
|
|
filter?: string[],
|
|
|
|
expectation: Expectation | string[] | boolean = getExpectation(),
|
|
|
|
): TestToRun[] {
|
|
|
|
const manifestFolder = getManifest().items.testharness;
|
|
|
|
|
|
|
|
const testsToRun: TestToRun[] = [];
|
|
|
|
|
|
|
|
function walk(
|
|
|
|
parentFolder: ManifestFolder,
|
|
|
|
parentExpectation: Expectation | string[] | boolean,
|
|
|
|
prefix: string,
|
|
|
|
) {
|
2023-01-16 11:17:18 -05:00
|
|
|
for (const [key, entry] of Object.entries(parentFolder)) {
|
2021-01-27 09:06:18 -05:00
|
|
|
if (Array.isArray(entry)) {
|
|
|
|
for (
|
|
|
|
const [path, options] of entry.slice(
|
|
|
|
1,
|
|
|
|
) as ManifestTestVariation[]
|
|
|
|
) {
|
|
|
|
if (!path) continue;
|
|
|
|
const url = new URL(path, "http://web-platform.test:8000");
|
2021-05-10 06:02:47 -04:00
|
|
|
if (
|
|
|
|
!url.pathname.endsWith(".any.html") &&
|
2021-08-16 08:29:54 -04:00
|
|
|
!url.pathname.endsWith(".window.html") &&
|
2021-10-08 11:44:38 -04:00
|
|
|
!url.pathname.endsWith(".worker.html") &&
|
|
|
|
!url.pathname.endsWith(".worker-module.html")
|
2021-05-10 06:02:47 -04:00
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-10-10 15:46:15 -04:00
|
|
|
// These tests require an HTTP2 compatible server.
|
|
|
|
if (url.pathname.includes(".h2.")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Streaming fetch requests need a server that supports chunked
|
|
|
|
// encoding, which the WPT test server does not. Unfortunately this
|
|
|
|
// also disables some useful fetch tests.
|
|
|
|
if (url.pathname.includes("request-upload")) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-05-09 10:32:30 -04:00
|
|
|
const finalPath = url.pathname + url.search;
|
|
|
|
|
|
|
|
const split = finalPath.split("/");
|
|
|
|
const finalKey = split[split.length - 1];
|
|
|
|
|
|
|
|
const expectation = Array.isArray(parentExpectation) ||
|
|
|
|
typeof parentExpectation == "boolean"
|
|
|
|
? parentExpectation
|
|
|
|
: parentExpectation[finalKey];
|
|
|
|
|
|
|
|
if (expectation === undefined) continue;
|
|
|
|
|
2022-09-27 17:32:17 -04:00
|
|
|
if (typeof expectation === "object") {
|
|
|
|
if (typeof expectation.ignore !== "undefined") {
|
|
|
|
assert(
|
|
|
|
typeof expectation.ignore === "boolean",
|
|
|
|
"test entry's `ignore` key must be a boolean",
|
|
|
|
);
|
2023-03-02 17:05:17 -05:00
|
|
|
if (expectation.ignore === true && !noIgnore) continue;
|
2022-09-27 17:32:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-03 08:50:18 -05:00
|
|
|
if (!noIgnore) {
|
|
|
|
assert(
|
|
|
|
Array.isArray(expectation) || typeof expectation == "boolean",
|
|
|
|
"test entry must not have a folder expectation",
|
|
|
|
);
|
|
|
|
}
|
2021-05-09 10:32:30 -04:00
|
|
|
|
|
|
|
if (
|
|
|
|
filter &&
|
|
|
|
!filter.find((filter) => finalPath.substring(1).startsWith(filter))
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-01-27 09:06:18 -05:00
|
|
|
testsToRun.push({
|
2021-05-09 10:32:30 -04:00
|
|
|
path: finalPath,
|
2021-01-27 09:06:18 -05:00
|
|
|
url,
|
|
|
|
options,
|
|
|
|
expectation,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
2021-05-09 10:32:30 -04:00
|
|
|
const expectation = Array.isArray(parentExpectation) ||
|
|
|
|
typeof parentExpectation == "boolean"
|
|
|
|
? parentExpectation
|
|
|
|
: parentExpectation[key];
|
|
|
|
|
|
|
|
if (expectation === undefined) continue;
|
|
|
|
|
|
|
|
walk(entry, expectation, `${prefix}/${key}`);
|
2021-01-27 09:06:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
walk(manifestFolder, expectation, "");
|
|
|
|
|
|
|
|
return testsToRun;
|
|
|
|
}
|
2023-01-12 19:12:20 -05:00
|
|
|
|
|
|
|
function partitionTests(tests: TestToRun[]): TestToRun[][] {
|
|
|
|
const testsByKey: { [key: string]: TestToRun[] } = {};
|
|
|
|
for (const test of tests) {
|
2023-05-10 15:35:42 -04:00
|
|
|
// Run all WebCryptoAPI tests in parallel
|
|
|
|
if (test.path.includes("/WebCryptoAPI")) {
|
|
|
|
testsByKey[test.path] = [test];
|
|
|
|
continue;
|
|
|
|
}
|
2023-01-12 19:12:20 -05:00
|
|
|
// Paths looks like: /fetch/corb/img-html-correctly-labeled.sub-ref.html
|
|
|
|
const key = test.path.split("/")[1];
|
|
|
|
if (!(key in testsByKey)) {
|
|
|
|
testsByKey[key] = [];
|
|
|
|
}
|
|
|
|
testsByKey[key].push(test);
|
|
|
|
}
|
|
|
|
return Object.values(testsByKey);
|
|
|
|
}
|
2023-04-13 10:03:15 -04:00
|
|
|
|
|
|
|
function formatDuration(duration: number): string {
|
|
|
|
if (duration >= 5000) {
|
|
|
|
return red(`${duration}ms`);
|
|
|
|
} else if (duration >= 1000) {
|
|
|
|
return yellow(`${duration}ms`);
|
|
|
|
} else {
|
|
|
|
return `${duration}ms`;
|
|
|
|
}
|
|
|
|
}
|