summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorMarvin Hagemeister <hello@marvinh.dev>2023-05-11 00:13:45 +0200
committerGitHub <noreply@github.com>2023-05-11 00:13:45 +0200
commit5fd74bfa1c5ed514c3e19fdb2e8590fe251d3ee6 (patch)
tree837103ec9540d907391bc549e26854d15bcf36eb /cli/tests
parente72485fb1776d2ffebd90ff716374edfba42d603 (diff)
feat(node): add `Module.runMain()` (#19080)
This PR adds the missing `Module.runMain()` function which is required for tools like `ts-node`. Fixes #19033
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/node_compat/config.jsonc1
-rw-r--r--cli/tests/node_compat/test/fixtures/run-main.js1
-rw-r--r--cli/tests/node_compat/test/parallel/test-module-run-main.js15
3 files changed, 17 insertions, 0 deletions
diff --git a/cli/tests/node_compat/config.jsonc b/cli/tests/node_compat/config.jsonc
index 81463bcaf..87530d4f5 100644
--- a/cli/tests/node_compat/config.jsonc
+++ b/cli/tests/node_compat/config.jsonc
@@ -366,6 +366,7 @@
"test-http-outgoing-message-inheritance.js",
"test-http-outgoing-renderHeaders.js",
"test-http-outgoing-settimeout.js",
+ "test-module-run-main.js",
"test-net-access-byteswritten.js",
"test-net-better-error-messages-listen-path.js",
"test-net-better-error-messages-path.js",
diff --git a/cli/tests/node_compat/test/fixtures/run-main.js b/cli/tests/node_compat/test/fixtures/run-main.js
new file mode 100644
index 000000000..9a081cbba
--- /dev/null
+++ b/cli/tests/node_compat/test/fixtures/run-main.js
@@ -0,0 +1 @@
+globalThis.foo = 42;
diff --git a/cli/tests/node_compat/test/parallel/test-module-run-main.js b/cli/tests/node_compat/test/parallel/test-module-run-main.js
new file mode 100644
index 000000000..8e30de267
--- /dev/null
+++ b/cli/tests/node_compat/test/parallel/test-module-run-main.js
@@ -0,0 +1,15 @@
+// deno-fmt-ignore-file
+// deno-lint-ignore-file
+
+"use strict";
+
+const Module = require("module");
+const assert = require("assert/strict");
+const path = require("path");
+
+const file = path.join(__dirname, "..", "fixtures", "run-main.js");
+process.argv = [process.argv[0], file];
+Module.runMain();
+
+// The required file via `Module.runMain()` sets this global
+assert.equal(globalThis.foo, 42);