From b90efa905f4a584212fa7c4ab9d48d0cdfb50207 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sat, 4 May 2024 12:23:50 -0400 Subject: [PATCH] docs: add `$.escapeArg` (#266) --- README.md | 4 ++++ src/request.test.ts | 20 +++++++++----------- src/test/server.deno.ts | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index dd32ce2..3ee3e83 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,10 @@ If you do not want to escape arguments in a template literal, you can opt out co ```ts const args = "arg1 arg2 arg3"; await $.raw`echo ${args}`; // executes as: echo arg1 arg2 arg3 + +// or escape a specific argument while using $.raw +const args2 = "arg1 arg2"; +await $.raw`echo ${$.escape(args2)} ${args2}`; // executes as: echo "arg1 arg2" arg1 arg2 ``` Providing stdout of one command to another is possible as follows: diff --git a/src/request.test.ts b/src/request.test.ts index 2740d22..74b3bc9 100644 --- a/src/request.test.ts +++ b/src/request.test.ts @@ -45,22 +45,20 @@ async function withServer(action: (serverUrl: URL) => Promise) { return new Response( new ReadableStream({ start(controller) { - return new Promise((resolve, reject) => { + return new Promise((resolve, _reject) => { if (signal.aborted || abortController.signal.aborted) { return; } - const timeoutId = setTimeout(() => { + const abortListener = () => { + clearTimeout(timeoutId); controller.close(); resolve(); - }, ms); - signal.addEventListener("abort", () => { - clearTimeout(timeoutId); - reject(new Error("Client aborted.")); - }); - abortController.signal.addEventListener("abort", () => { - clearTimeout(timeoutId); - reject(new Error("Client aborted.")); - }); + signal.removeEventListener("abort", abortListener); + abortController.signal.removeEventListener("abort", abortListener); + }; + const timeoutId = setTimeout(abortListener, ms); + signal.addEventListener("abort", abortListener); + abortController.signal.addEventListener("abort", abortListener); }); }, cancel(reason) { diff --git a/src/test/server.deno.ts b/src/test/server.deno.ts index a7d5827..1c26a60 100644 --- a/src/test/server.deno.ts +++ b/src/test/server.deno.ts @@ -5,7 +5,7 @@ export const startServer: StartServerHandler = (options) => { const server = Deno.serve({ hostname: "localhost", onListen(details) { - const url = new URL(`http://${details.hostname}:${details.port}/`); + const url = new URL(`http://localhost:${details.port}/`); resolve({ rootUrl: url, shutdown: () => server.shutdown(),