diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testdata/coverage/complex_test.ts | 29 | ||||
-rw-r--r-- | tests/testdata/run/warn_on_deprecated_api/main.js | 2 | ||||
-rw-r--r-- | tests/testdata/run/warn_on_deprecated_api/main.out | 1 | ||||
-rw-r--r-- | tests/testdata/run/warn_on_deprecated_api/main.verbose.out | 5 | ||||
-rw-r--r-- | tests/unit/http_test.ts | 25 | ||||
-rw-r--r-- | tests/unit/process_test.ts | 52 |
6 files changed, 53 insertions, 61 deletions
diff --git a/tests/testdata/coverage/complex_test.ts b/tests/testdata/coverage/complex_test.ts index d6e9c2691..6a711a91a 100644 --- a/tests/testdata/coverage/complex_test.ts +++ b/tests/testdata/coverage/complex_test.ts @@ -7,32 +7,29 @@ Deno.test("complex", function () { Deno.test("sub process with stdin", async () => { // ensure launching deno run with stdin doesn't affect coverage const code = "console.log('5')"; - // deno-lint-ignore no-deprecated-deno-api - const p = await Deno.run({ - cmd: [Deno.execPath(), "run", "-"], + const command = new Deno.Command(Deno.execPath(), { + args: ["run", "-"], stdin: "piped", stdout: "piped", }); - const encoder = new TextEncoder(); - await p.stdin.write(encoder.encode(code)); - await p.stdin.close(); - const output = new TextDecoder().decode(await p.output()); - p.close(); + await using child = command.spawn(); + await ReadableStream.from([code]) + .pipeThrough(new TextEncoderStream()) + .pipeTo(child.stdin); + const { stdout } = await child.output(); + const output = new TextDecoder().decode(stdout); if (output.trim() !== "5") { throw new Error("Failed"); } }); -Deno.test("sub process with deno eval", async () => { +Deno.test("sub process with deno eval", () => { // ensure launching deno eval doesn't affect coverage const code = "console.log('5')"; - // deno-lint-ignore no-deprecated-deno-api - const p = await Deno.run({ - cmd: [Deno.execPath(), "eval", code], - stdout: "piped", - }); - const output = new TextDecoder().decode(await p.output()); - p.close(); + const { stdout } = new Deno.Command(Deno.execPath(), { + args: ["eval", code], + }).outputSync(); + const output = new TextDecoder().decode(stdout); if (output.trim() !== "5") { throw new Error("Failed"); } diff --git a/tests/testdata/run/warn_on_deprecated_api/main.js b/tests/testdata/run/warn_on_deprecated_api/main.js index a464be60a..8811df78d 100644 --- a/tests/testdata/run/warn_on_deprecated_api/main.js +++ b/tests/testdata/run/warn_on_deprecated_api/main.js @@ -1,5 +1,6 @@ import { runEcho as runEcho2 } from "http://localhost:4545/run/warn_on_deprecated_api/mod.ts"; +// @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [ Deno.execPath(), @@ -11,6 +12,7 @@ await p.status(); p.close(); async function runEcho() { + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [ Deno.execPath(), diff --git a/tests/testdata/run/warn_on_deprecated_api/main.out b/tests/testdata/run/warn_on_deprecated_api/main.out index ff44c885f..ef85a6f99 100644 --- a/tests/testdata/run/warn_on_deprecated_api/main.out +++ b/tests/testdata/run/warn_on_deprecated_api/main.out @@ -1,5 +1,4 @@ Download http://localhost:4545/run/warn_on_deprecated_api/mod.ts -warning: Use of deprecated "Deno.run()" API. This API will be removed in Deno 2. Run again with DENO_VERBOSE_WARNINGS=1 to get more details. hello world hello world hello world diff --git a/tests/testdata/run/warn_on_deprecated_api/main.verbose.out b/tests/testdata/run/warn_on_deprecated_api/main.verbose.out index 184051de1..e17562eef 100644 --- a/tests/testdata/run/warn_on_deprecated_api/main.verbose.out +++ b/tests/testdata/run/warn_on_deprecated_api/main.verbose.out @@ -1,5 +1,4 @@ Download http://localhost:4545/run/warn_on_deprecated_api/mod.ts -warning: Use of deprecated "Deno.run()" API. This API will be removed in Deno 2. See the Deno 1 to 2 Migration Guide for more information at https://docs.deno.com/runtime/manual/advanced/migrate_deprecations @@ -9,7 +8,6 @@ Stack trace: hint: Use "Deno.Command()" API instead. hello world -warning: Use of deprecated "Deno.run()" API. This API will be removed in Deno 2. See the Deno 1 to 2 Migration Guide for more information at https://docs.deno.com/runtime/manual/advanced/migrate_deprecations @@ -20,7 +18,6 @@ Stack trace: hint: Use "Deno.Command()" API instead. hello world -warning: Use of deprecated "Deno.run()" API. This API will be removed in Deno 2. See the Deno 1 to 2 Migration Guide for more information at https://docs.deno.com/runtime/manual/advanced/migrate_deprecations @@ -31,7 +28,6 @@ Stack trace: hint: Use "Deno.Command()" API instead. hello world -warning: Use of deprecated "Deno.run()" API. This API will be removed in Deno 2. See the Deno 1 to 2 Migration Guide for more information at https://docs.deno.com/runtime/manual/advanced/migrate_deprecations @@ -51,7 +47,6 @@ hello world hello world hello world hello world -warning: Use of deprecated "Deno.run()" API. This API will be removed in Deno 2. See the Deno 1 to 2 Migration Guide for more information at https://docs.deno.com/runtime/manual/advanced/migrate_deprecations diff --git a/tests/unit/http_test.ts b/tests/unit/http_test.ts index 6d3543e44..778cc98fd 100644 --- a/tests/unit/http_test.ts +++ b/tests/unit/http_test.ts @@ -2087,7 +2087,6 @@ Deno.test({ async function client() { const url = `http://${hostname}:${port}/`; const cmd = [ - "curl", "-i", "--request", "GET", @@ -2097,16 +2096,17 @@ Deno.test({ "--header", "Accept-Encoding: deflate, gzip", ]; - const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" }); - const status = await proc.status(); - assert(status.success); - const output = decoder.decode(await proc.output()); + const { success, stdout } = await new Deno.Command("curl", { + args: cmd, + stderr: "null", + }).output(); + assert(success); + const output = decoder.decode(stdout); assert(output.includes("vary: Accept-Encoding\r\n")); assert(output.includes("content-encoding: gzip\r\n")); // Ensure the content-length header is updated. assert(!output.includes(`content-length: ${contentLength}\r\n`)); assert(output.includes("content-length: ")); - proc.close(); } await Promise.all([server(), client()]); @@ -2149,7 +2149,6 @@ Deno.test({ async function client() { const url = `http://${hostname}:${port}/`; const cmd = [ - "curl", "-i", "--request", "GET", @@ -2159,13 +2158,15 @@ Deno.test({ "--header", "Accept-Encoding: deflate, gzip", ]; - const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" }); - const status = await proc.status(); - assert(status.success); - const output = decoder.decode(await proc.output()); + const { success, stdout } = await new Deno.Command("curl", { + args: cmd, + stderr: "null", + stdout: "piped", + }).output(); + assert(success); + const output = decoder.decode(stdout); assert(output.includes("vary: Accept-Encoding\r\n")); assert(output.includes("content-encoding: arbitrary\r\n")); - proc.close(); } await Promise.all([server(), client()]); diff --git a/tests/unit/process_test.ts b/tests/unit/process_test.ts index 383f17f38..0d14c9ce7 100644 --- a/tests/unit/process_test.ts +++ b/tests/unit/process_test.ts @@ -1,3 +1,4 @@ +// deno-lint-ignore-file no-deprecated-deno-api // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. import { assert, @@ -12,7 +13,7 @@ Deno.test( { permissions: { read: true, run: false } }, function runPermissions() { assertThrows(() => { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. Deno.run({ cmd: [Deno.execPath(), "eval", "console.log('hello world')"], }); @@ -23,7 +24,7 @@ Deno.test( Deno.test( { permissions: { run: true, read: true } }, async function runSuccess() { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ // freeze the array to ensure it's not modified cmd: Object.freeze([ @@ -46,7 +47,7 @@ Deno.test( Deno.test( { permissions: { run: true, read: true } }, async function runUrl() { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [ new URL(`file:///${Deno.execPath()}`), @@ -70,7 +71,7 @@ Deno.test( async function runStdinRid0(): Promise< void > { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [Deno.execPath(), "eval", "console.log('hello world')"], stdin: 0, @@ -90,26 +91,23 @@ Deno.test( { permissions: { run: true, read: true } }, function runInvalidStdio() { assertThrows(() => - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. Deno.run({ cmd: [Deno.execPath(), "eval", "console.log('hello world')"], - // @ts-expect-error because Deno.run should throw on invalid stdin. stdin: "a", }) ); assertThrows(() => - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. Deno.run({ cmd: [Deno.execPath(), "eval", "console.log('hello world')"], - // @ts-expect-error because Deno.run should throw on invalid stdout. stdout: "b", }) ); assertThrows(() => - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. Deno.run({ cmd: [Deno.execPath(), "eval", "console.log('hello world')"], - // @ts-expect-error because Deno.run should throw on invalid stderr. stderr: "c", }) ); @@ -119,7 +117,7 @@ Deno.test( Deno.test( { permissions: { run: true, read: true } }, async function runCommandFailedWithCode() { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [Deno.execPath(), "eval", "Deno.exit(41 + 1)"], }); @@ -136,7 +134,7 @@ Deno.test( permissions: { run: true, read: true }, }, async function runCommandFailedWithSignal() { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [ Deno.execPath(), @@ -160,7 +158,7 @@ Deno.test( Deno.test({ permissions: { run: true } }, function runNotFound() { let error; try { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. Deno.run({ cmd: ["this file hopefully doesn't exist"] }); } catch (e) { error = e; @@ -192,7 +190,7 @@ tryExit(); `; Deno.writeFileSync(`${cwd}/${programFile}`, enc.encode(program)); - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cwd, cmd: [Deno.execPath(), "run", "--allow-read", programFile], @@ -216,7 +214,7 @@ Deno.test( async function runStdinPiped(): Promise< void > { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [ Deno.execPath(), @@ -254,7 +252,7 @@ Deno.test( async function runStdoutPiped(): Promise< void > { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [ Deno.execPath(), @@ -291,7 +289,7 @@ Deno.test( async function runStderrPiped(): Promise< void > { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [ Deno.execPath(), @@ -326,7 +324,7 @@ Deno.test( Deno.test( { permissions: { run: true, read: true } }, async function runOutput() { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [ Deno.execPath(), @@ -347,7 +345,7 @@ Deno.test( async function runStderrOutput(): Promise< void > { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [ Deno.execPath(), @@ -377,7 +375,7 @@ Deno.test( write: true, }); - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [ Deno.execPath(), @@ -414,7 +412,7 @@ Deno.test( await Deno.writeTextFile(fileName, "hello"); using file = await Deno.open(fileName); - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [ Deno.execPath(), @@ -439,7 +437,7 @@ Deno.test( Deno.test( { permissions: { run: true, read: true } }, async function runEnv() { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [ Deno.execPath(), @@ -462,7 +460,7 @@ Deno.test( Deno.test( { permissions: { run: true, read: true } }, async function runClose() { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [ Deno.execPath(), @@ -486,7 +484,7 @@ Deno.test( Deno.test( { permissions: { run: true, read: true } }, async function runKillAfterStatus() { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [Deno.execPath(), "eval", 'console.log("hello")'], }); @@ -543,7 +541,7 @@ Deno.test( Deno.test( { permissions: { run: true, read: true } }, async function killSuccess() { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [Deno.execPath(), "eval", "setTimeout(() => {}, 10000)"], }); @@ -567,7 +565,7 @@ Deno.test( ); Deno.test({ permissions: { run: true, read: true } }, function killFailed() { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [Deno.execPath(), "eval", "setTimeout(() => {}, 10000)"], }); @@ -588,7 +586,7 @@ Deno.test( ignore: Deno.build.os === "windows", }, async function non_existent_cwd(): Promise<void> { - // deno-lint-ignore no-deprecated-deno-api + // @ts-ignore `Deno.run()` was soft-removed in Deno 2. const p = Deno.run({ cmd: [ Deno.execPath(), |