summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2021-12-11 15:56:45 +0100
committerGitHub <noreply@github.com>2021-12-11 15:56:45 +0100
commit0dec9b4381e0aa1d4b75ab5837cb75598f19c727 (patch)
tree960f9bd48c5b733317c5592d9843f315883413f8 /cli/tests
parent13d7d5722771bf8c4de7083dc0f964dfffcb318a (diff)
fix: op_set_exit_code (#13034)
Fixes "op_set_exit_code" by sharing a single "Arc" between all workers (via "op state") instead of having a "global" value stored in "deno_runtime" crate. As a consequence setting an exit code is always scoped to a tree of workers, instead of being overridable if there are multiple worker tree (like in "deno test --jobs" subcommand). Refactored "cli/main.rs" functions to return "Result<i32, AnyError>" instead of "Result<(), AnyError>" so they can return exit code.
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/run_tests.rs6
-rw-r--r--cli/tests/testdata/set_exit_code_in_worker.ts13
-rw-r--r--cli/tests/testdata/set_exit_code_worker.js4
3 files changed, 23 insertions, 0 deletions
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs
index fbdc01ad7..dd4482423 100644
--- a/cli/tests/integration/run_tests.rs
+++ b/cli/tests/integration/run_tests.rs
@@ -907,6 +907,12 @@ itest!(set_exit_code_2 {
exit_code: 42,
});
+itest!(set_exit_code_in_worker {
+ args: "run --no-check --unstable --allow-read set_exit_code_in_worker.ts",
+ output: "empty.out",
+ exit_code: 42,
+});
+
itest!(heapstats {
args: "run --quiet --unstable --v8-flags=--expose-gc heapstats.js",
output: "heapstats.js.out",
diff --git a/cli/tests/testdata/set_exit_code_in_worker.ts b/cli/tests/testdata/set_exit_code_in_worker.ts
new file mode 100644
index 000000000..1df6a76d0
--- /dev/null
+++ b/cli/tests/testdata/set_exit_code_in_worker.ts
@@ -0,0 +1,13 @@
+import { deferred } from "../../../test_util/std/async/deferred.ts";
+
+const worker = new Worker(
+ new URL("set_exit_code_worker.js", import.meta.url).href,
+ { type: "module", deno: { namespace: true } },
+);
+
+const promise1 = deferred();
+worker.onmessage = (_e) => {
+ promise1.resolve();
+};
+await promise1;
+worker.terminate();
diff --git a/cli/tests/testdata/set_exit_code_worker.js b/cli/tests/testdata/set_exit_code_worker.js
new file mode 100644
index 000000000..d1c0123d1
--- /dev/null
+++ b/cli/tests/testdata/set_exit_code_worker.js
@@ -0,0 +1,4 @@
+// Set exit code
+Deno.core.opSync("op_set_exit_code", 42);
+
+self.postMessage("ok");