diff options
| author | Leo Kettmeir <crowlkats@toaxl.com> | 2022-05-18 22:00:11 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-18 22:00:11 +0200 |
| commit | 4e1ca1d1787f25ab9f0a72ccf9d8028f70b3a7ed (patch) | |
| tree | 2d0062ec1dd864c7ed98301119ac5f1c133f844a /tools/wpt | |
| parent | 5ad8919d642b646caa3328930dd1a3f290bc587e (diff) | |
refactor: use spawn API across codebase (#14414)
Diffstat (limited to 'tools/wpt')
| -rw-r--r-- | tools/wpt/runner.ts | 30 | ||||
| -rw-r--r-- | tools/wpt/utils.ts | 53 |
2 files changed, 38 insertions, 45 deletions
diff --git a/tools/wpt/runner.ts b/tools/wpt/runner.ts index 5e0285e77..269e6ffd1 100644 --- a/tools/wpt/runner.ts +++ b/tools/wpt/runner.ts @@ -1,5 +1,5 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. -import { delay, join, readLines, ROOT_PATH, toFileUrl } from "../util.js"; +import { delay, join, ROOT_PATH, TextLineStream, toFileUrl } from "../util.js"; import { assert, denoBinary, ManifestTestOptions, runPy } from "./utils.ts"; import { DOMParser } from "https://deno.land/x/deno_dom@v0.1.3-alpha2/deno-dom-wasm.ts"; @@ -32,8 +32,7 @@ export async function runWithTestUtil<T>( const passedTime = performance.now() - start; if (passedTime > 15000) { proc.kill("SIGINT"); - await proc.status(); - proc.close(); + await proc.status; throw new Error("Timed out while trying to start wpt test util."); } } @@ -45,8 +44,7 @@ export async function runWithTestUtil<T>( } finally { if (verbose) console.log("Killing wpt test util."); proc.kill("SIGINT"); - await proc.status(); - proc.close(); + await proc.status; } } @@ -89,21 +87,17 @@ export async function runSingleTest( const startTime = new Date().getTime(); - const cmd = [ - denoBinary(), + const args = [ "run", - ]; - - cmd.push( "-A", "--unstable", - ); + ]; if (inspectBrk) { - cmd.push("--inspect-brk"); + args.push("--inspect-brk"); } - cmd.push( + args.push( "--enable-testing-features-do-not-use", "--location", url.toString(), @@ -113,8 +107,8 @@ export async function runSingleTest( "[]", ); - const proc = Deno.run({ - cmd, + const proc = Deno.spawnChild(denoBinary(), { + args, env: { NO_COLOR: "1", }, @@ -127,7 +121,9 @@ export async function runSingleTest( let harnessStatus = null; - const lines = readLines(proc.stderr); + const lines = proc.stderr.pipeThrough(new TextDecoderStream()).pipeThrough( + new TextLineStream(), + ); for await (const line of lines) { if (line.startsWith("{")) { const data = JSON.parse(line); @@ -144,7 +140,7 @@ export async function runSingleTest( const duration = new Date().getTime() - startTime; - const { code } = await proc.status(); + const { code } = await proc.status; return { status: code, harnessStatus, diff --git a/tools/wpt/utils.ts b/tools/wpt/utils.ts index f64e20f8f..80580928c 100644 --- a/tools/wpt/utils.ts +++ b/tools/wpt/utils.ts @@ -53,7 +53,7 @@ export interface ManifestTestOptions { const MANIFEST_PATH = join(ROOT_PATH, "./tools/wpt/manifest.json"); export async function updateManifest() { - const proc = runPy( + const status = await runPy( [ "wpt", "manifest", @@ -64,8 +64,7 @@ export async function updateManifest() { ...(rebuild ? ["--rebuild"] : []), ], {}, - ); - const status = await proc.status(); + ).status; assert(status.success, "updating wpt manifest should succeed"); } @@ -119,23 +118,26 @@ export function assert(condition: unknown, message: string): asserts condition { } } -export function runPy( +export function runPy<T extends Omit<Deno.SpawnOptions, "cwd">>( args: string[], - options: Omit<Omit<Deno.RunOptions, "cmd">, "cwd">, -): Deno.Process { + options: T, +): Deno.Child<T> { const cmd = Deno.build.os == "windows" ? "python.exe" : "python3"; - return Deno.run({ - cmd: [cmd, ...args], - cwd: join(ROOT_PATH, "./test_util/wpt/"), + return Deno.spawnChild(cmd, { + args, + stdout: "inherit", + stderr: "inherit", ...options, + cwd: join(ROOT_PATH, "./test_util/wpt/"), }); } export async function checkPy3Available() { - const proc = runPy(["--version"], { stdout: "piped" }); - const status = await proc.status(); + const { status, stdout } = await runPy(["--version"], { + stdout: "piped", + }).output(); assert(status.success, "failed to run python --version"); - const output = new TextDecoder().decode(await proc.output()); + const output = new TextDecoder().decode(stdout); assert( output.includes("Python 3."), `The ${ @@ -146,12 +148,12 @@ export async function checkPy3Available() { export async function cargoBuild() { if (binary) return; - const proc = Deno.run({ - cmd: ["cargo", "build", ...(release ? ["--release"] : [])], + const { status } = await Deno.spawn("cargo", { + args: ["build", ...(release ? ["--release"] : [])], cwd: ROOT_PATH, + stdout: "inherit", + stderr: "inherit", }); - const status = await proc.status(); - proc.close(); assert(status.success, "cargo build failed"); } @@ -173,22 +175,17 @@ export async function generateRunInfo(): Promise<unknown> { "darwin": "mac", "linux": "linux", }; - const proc = Deno.run({ - cmd: ["git", "rev-parse", "HEAD"], + const proc = await Deno.spawn("git", { + args: ["rev-parse", "HEAD"], cwd: join(ROOT_PATH, "test_util", "wpt"), - stdout: "piped", + stderr: "inherit", }); - await proc.status(); - const revision = (new TextDecoder().decode(await proc.output())).trim(); - proc.close(); - const proc2 = Deno.run({ - cmd: [denoBinary(), "eval", "console.log(JSON.stringify(Deno.version))"], + const revision = (new TextDecoder().decode(proc.stdout)).trim(); + const proc2 = await Deno.spawn(denoBinary(), { + args: ["eval", "console.log(JSON.stringify(Deno.version))"], cwd: join(ROOT_PATH, "test_util", "wpt"), - stdout: "piped", }); - await proc2.status(); - const version = JSON.parse(new TextDecoder().decode(await proc2.output())); - proc2.close(); + const version = JSON.parse(new TextDecoder().decode(proc2.stdout)); const runInfo = { "os": oses[Deno.build.os], "processor": Deno.build.arch, |
