summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorKenta Moriuchi <moriken@kimamass.com>2022-10-29 18:25:23 +0900
committerGitHub <noreply@github.com>2022-10-29 18:25:23 +0900
commit59ac110edd1f376bed7fa6bbdbe2ee09c266bf74 (patch)
treeda654d1ecb6141b620141d634d99ca34c6d568db /cli/tests
parentedaceecec771cf0395639175b5a21d20530f6080 (diff)
fix(core): fix APIs not to be affected by `Promise.prototype.then` modification (#16326)
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/unit/flash_test.ts26
-rw-r--r--cli/tests/unit/spawn_test.ts17
2 files changed, 43 insertions, 0 deletions
diff --git a/cli/tests/unit/flash_test.ts b/cli/tests/unit/flash_test.ts
index 375fdb8f3..e2e64dfe3 100644
--- a/cli/tests/unit/flash_test.ts
+++ b/cli/tests/unit/flash_test.ts
@@ -2227,6 +2227,32 @@ Deno.test(
},
);
+Deno.test(
+ { permissions: { net: true } },
+ async function serveWithPromisePrototypeThenOverride() {
+ const originalThen = Promise.prototype.then;
+ try {
+ Promise.prototype.then = () => {
+ throw new Error();
+ };
+ const ac = new AbortController();
+ const listeningPromise = deferred();
+ const server = Deno.serve({
+ handler: (_req) => new Response("ok"),
+ hostname: "localhost",
+ port: 4501,
+ signal: ac.signal,
+ onListen: onListen(listeningPromise),
+ onError: createOnErrorCb(ac),
+ });
+ ac.abort();
+ await server;
+ } finally {
+ Promise.prototype.then = originalThen;
+ }
+ },
+);
+
// https://github.com/denoland/deno/issues/15549
Deno.test(
{ permissions: { net: true } },
diff --git a/cli/tests/unit/spawn_test.ts b/cli/tests/unit/spawn_test.ts
index 149886a1c..10095be95 100644
--- a/cli/tests/unit/spawn_test.ts
+++ b/cli/tests/unit/spawn_test.ts
@@ -812,3 +812,20 @@ Deno.test(
assertStringIncludes(stdoutText, "typescript");
},
);
+
+Deno.test(
+ { permissions: { read: true, run: true } },
+ async function spawnWithPromisePrototypeThenOverride() {
+ const originalThen = Promise.prototype.then;
+ try {
+ Promise.prototype.then = () => {
+ throw new Error();
+ };
+ await Deno.spawn(Deno.execPath(), {
+ args: ["eval", "console.log('hello world')"],
+ });
+ } finally {
+ Promise.prototype.then = originalThen;
+ }
+ },
+);