summaryrefslogtreecommitdiff
path: root/test/parallel/test-module-run-main-monkey-patch.js
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-11-10 16:59:16 +0800
committerAnna Henningsen <anna@addaleax.net>2019-11-19 13:43:59 +0100
commitefce655c0f1671d0e86b5c89092ac93db983ef94 (patch)
tree26af173e687a6c8ee0f26d2857742ffce01729f2 /test/parallel/test-module-run-main-monkey-patch.js
parent0f78dcc86d9af8f742f76505c5a104c6dff17ca9 (diff)
downloadandroid-node-v8-efce655c0f1671d0e86b5c89092ac93db983ef94.tar.gz
android-node-v8-efce655c0f1671d0e86b5c89092ac93db983ef94.tar.bz2
android-node-v8-efce655c0f1671d0e86b5c89092ac93db983ef94.zip
module: reduce circular dependency of internal/modules/cjs/loader
Previously `internal/bootstrap/pre_execution.js` requires `internal/modules/cjs/loader.js` which in turn requires `internal/bootstrap/pre_execution.js`. This patch moves the entry point execution logic out of `pre_execution.js` and puts it into `internal/modules/run_main.js`. It also tests that `Module.runMain` can be monkey-patched before further deprecation/refactoring can be done. Also added an internal assertion `hasLoadedAnyUserCJSModule` for documentation purposes. PR-URL: https://github.com/nodejs/node/pull/30349 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test/parallel/test-module-run-main-monkey-patch.js')
-rw-r--r--test/parallel/test-module-run-main-monkey-patch.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/parallel/test-module-run-main-monkey-patch.js b/test/parallel/test-module-run-main-monkey-patch.js
new file mode 100644
index 0000000000..c9f189abb6
--- /dev/null
+++ b/test/parallel/test-module-run-main-monkey-patch.js
@@ -0,0 +1,18 @@
+'use strict';
+
+// This tests that module.runMain can be monkey patched using --require.
+// TODO(joyeecheung): This probably should be deprecated.
+
+require('../common');
+const { path } = require('../common/fixtures');
+const assert = require('assert');
+const { spawnSync } = require('child_process');
+
+const child = spawnSync(process.execPath, [
+ '--require',
+ path('monkey-patch-run-main.js'),
+ path('semicolon.js'),
+]);
+
+assert.strictEqual(child.status, 0);
+assert(child.stdout.toString().includes('runMain is monkey patched!'));