diff options
| author | Luca Casonato <lucacasonato@yahoo.com> | 2021-06-06 18:32:06 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-06 18:32:06 +0200 |
| commit | a66f327250d9df77816e80e7d411b232f8b08b11 (patch) | |
| tree | 69f75867a3e0f507d2d62b3a5c2d9b23c9f8a7e5 /tools/wpt/runner.ts | |
| parent | f1deed41e7cc04440a5fb8cdae486ae00513a361 (diff) | |
tests: run wpt scripts with Deno.core.evalContext (#10852)
This means wpts are now run in script context, and there are better
stack traces.
Diffstat (limited to 'tools/wpt/runner.ts')
| -rw-r--r-- | tools/wpt/runner.ts | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/tools/wpt/runner.ts b/tools/wpt/runner.ts index dcc88a123..52768f079 100644 --- a/tools/wpt/runner.ts +++ b/tools/wpt/runner.ts @@ -1,5 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { delay, join, readLines, ROOT_PATH } from "../util.js"; +import { delay, join, readLines, ROOT_PATH, toFileUrl } from "../util.js"; import { assert, ManifestTestOptions, release, runPy } from "./utils.ts"; import { DOMParser } from "https://deno.land/x/deno_dom@v0.1.3-alpha2/deno-dom-wasm.ts"; @@ -140,20 +140,32 @@ async function generateBundle(location: URL): Promise<string> { assert(doc, "document should have been parsed"); const scripts = doc.getElementsByTagName("script"); const scriptContents = []; + let inlineScriptCount = 0; for (const script of scripts) { const src = script.getAttribute("src"); if (src === "/resources/testharnessreport.js") { - scriptContents.push( - await Deno.readTextFile( - join(ROOT_PATH, "./tools/wpt/testharnessreport.js"), - ), + const url = toFileUrl( + join(ROOT_PATH, "./tools/wpt/testharnessreport.js"), ); + const contents = await Deno.readTextFile(url); + scriptContents.push([url.href, contents]); } else if (src) { - const res = await fetch(new URL(src, location)); - scriptContents.push(await res.text()); + const url = new URL(src, location); + const res = await fetch(url); + if (res.ok) { + const contents = await res.text(); + scriptContents.push([url.href, contents]); + } } else { - scriptContents.push(script.textContent); + const url = new URL(`#${inlineScriptCount}`, location); + inlineScriptCount++; + scriptContents.push([url.href, script.textContent]); } } - return scriptContents.join("\n"); + + return scriptContents.map(([url, contents]) => + `Deno.core.evalContext(${JSON.stringify(contents)}, ${ + JSON.stringify(url) + });` + ).join("\n"); } |
