-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: run wpt scripts with Deno.core.evalContext (#10852)
This means wpts are now run in script context, and there are better stack traces.
- Loading branch information
1 parent
f1deed4
commit a66f327
Showing
4 changed files
with
43 additions
and
29 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 |
---|---|---|
|
@@ -3,10 3,11 @@ import { | |
dirname, | ||
fromFileUrl, | ||
join, | ||
toFileUrl, | ||
} from "https://deno.land/[email protected]/path/mod.ts"; | ||
export { dirname, join }; | ||
export { dirname, fromFileUrl, join, toFileUrl }; | ||
export { existsSync } from "https://deno.land/[email protected]/fs/mod.ts"; | ||
export { readLines } from "https://deno.land/std@0.84.0/io/mod.ts"; | ||
export { readLines } from "https://deno.land/std@0.97.0/io/mod.ts"; | ||
export { delay } from "https://deno.land/[email protected]/async/delay.ts"; | ||
|
||
export const ROOT_PATH = dirname(dirname(fromFileUrl(import.meta.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
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,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/[email protected]/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"); | ||
} |