Skip to content

Commit

Permalink
chore: add test for worker shutting down during npm import (denoland#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Jun 10, 2024
1 parent 31154ff commit 3be0a1e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/specs/npm/worker_shutdown_during_npm_import/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"tempDir": true,
"tests": {
"with_lock": {
"args": "run -A --quiet --lock=deno.lock main.ts",
"output": "main.out"
},
"without_lock": {
"args": "run -A --quiet main.ts",
"output": "main.out"
}
}
}
4 changes: 4 additions & 0 deletions tests/specs/npm/worker_shutdown_during_npm_import/main.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[UNORDERED_START]
1
2
[UNORDERED_END]
6 changes: 6 additions & 0 deletions tests/specs/npm/worker_shutdown_during_npm_import/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
new Worker(new URL("./worker1.ts", import.meta.url), {
type: "module",
});
new Worker(new URL("./worker2.ts", import.meta.url), {
type: "module",
});
11 changes: 11 additions & 0 deletions tests/specs/npm/worker_shutdown_during_npm_import/specifiers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default [
"npm:chalk@4",
"npm:[email protected]",
"npm:[email protected]",
"npm:ajv",
"npm:has",
"npm:picocolors",
"npm:@denotest/esm-basic",
"npm:@denotest/add",
"npm:@denotest/subtract",
];
7 changes: 7 additions & 0 deletions tests/specs/npm/worker_shutdown_during_npm_import/worker1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import specifiers from "./specifiers.ts";
await new Promise((resolve) => setTimeout(() => resolve(), 20));

await Promise.all(specifiers.map((specifier) => import(specifier)));

console.log(1);
self.close();
7 changes: 7 additions & 0 deletions tests/specs/npm/worker_shutdown_during_npm_import/worker2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import specifiers from "./specifiers.ts";
// start importing, but close after waiting a short amount of time
specifiers.map((specifier) => import(specifier));
await new Promise((resolve) => setTimeout(() => resolve(), 20));
console.log(2);
self.close();
console.log("WILL NOT BE PRINTED");

0 comments on commit 3be0a1e

Please sign in to comment.