Skip to content

Commit

Permalink
chore: 045_proxy output stdout & stderr on failure (#23810)
Browse files Browse the repository at this point in the history
Part of #23624
  • Loading branch information
dsherret committed May 14, 2024
1 parent c6189e2 commit 432792a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
6 changes: 0 additions & 6 deletions tests/integration/run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,6 @@ itest!(_044_bad_resource {
exit_code: 1,
});

itest!(_045_proxy {
args: "run -L debug --allow-net --allow-env --allow-run --allow-read --reload --quiet run/045_proxy_test.ts",
output: "run/045_proxy_test.ts.out",
http_server: true,
});

itest!(_046_tsx {
args: "run --quiet --reload run/046_jsx_test.tsx",
output: "run/046_jsx_test.tsx.out",
Expand Down
4 changes: 4 additions & 0 deletions tests/specs/run/045_proxy/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"args": "run -L debug --allow-net --allow-env --allow-run --allow-read --reload --quiet proxy_test.ts",
"output": "proxy_test.ts.out"
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { Server } from "../../../tests/util/std/http/server.ts";
import { assertEquals } from "../../../tests/util/std/assert/mod.ts";
import { Server } from "../../../util/std/http/server.ts";

const addr = Deno.args[1] || "localhost:4555";

Expand Down Expand Up @@ -30,25 +29,33 @@ async function handler(req: Request): Promise<Response> {
});
}

function assertSuccessOutput(output: Deno.CommandOutput) {
if (output.code !== 0) {
console.error("STDOUT", new TextDecoder().decode(output.stdout));
console.error("STDERR", new TextDecoder().decode(output.stderr));
throw new Error(`Expected exit code 0, was ${output.code}`);
}
}

async function testFetch() {
const { code } = await new Deno.Command(Deno.execPath(), {
const output = await new Deno.Command(Deno.execPath(), {
args: [
"run",
"--quiet",
"--reload",
"--allow-net",
"run/045_proxy_client.ts",
"proxy_client.ts",
],
env: {
HTTP_PROXY: `http://${addr}`,
},
}).output();

assertEquals(code, 0);
assertSuccessOutput(output);
}

async function testModuleDownload() {
const { code } = await new Deno.Command(Deno.execPath(), {
const output = await new Deno.Command(Deno.execPath(), {
args: [
"cache",
"--reload",
Expand All @@ -60,29 +67,29 @@ async function testModuleDownload() {
},
}).output();

assertEquals(code, 0);
assertSuccessOutput(output);
}

async function testFetchNoProxy() {
const { code } = await new Deno.Command(Deno.execPath(), {
const output = await new Deno.Command(Deno.execPath(), {
args: [
"run",
"--quiet",
"--reload",
"--allow-net",
"run/045_proxy_client.ts",
"proxy_client.ts",
],
env: {
HTTP_PROXY: "http://not.exising.proxy.server",
NO_PROXY: "localhost",
},
}).output();

assertEquals(code, 0);
assertSuccessOutput(output);
}

async function testModuleDownloadNoProxy() {
const { code } = await new Deno.Command(Deno.execPath(), {
const output = await new Deno.Command(Deno.execPath(), {
args: [
"cache",
"--reload",
Expand All @@ -95,21 +102,22 @@ async function testModuleDownloadNoProxy() {
},
}).output();

assertEquals(code, 0);
assertSuccessOutput(output);
}

async function testFetchProgrammaticProxy() {
const { code } = await new Deno.Command(Deno.execPath(), {
const output = await new Deno.Command(Deno.execPath(), {
args: [
"run",
"--quiet",
"--reload",
"--allow-net=localhost:4545,localhost:4555",
"--unstable",
"run/045_programmatic_proxy_client.ts",
"programmatic_proxy_client.ts",
],
}).output();
assertEquals(code, 0);

assertSuccessOutput(output);
}

proxyServer();
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tools/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ async function ensureNoNewITests() {
"pm_tests.rs": 0,
"publish_tests.rs": 0,
"repl_tests.rs": 0,
"run_tests.rs": 373,
"run_tests.rs": 372,
"shared_library_tests.rs": 0,
"task_tests.rs": 30,
"test_tests.rs": 77,
Expand Down

0 comments on commit 432792a

Please sign in to comment.