-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
test: add a test to make sure the modules can be required independently #24402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
152a8f6
987fe87
7925ff0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
This patch adds a test that makes sure all the modules (internal or not) can be independently required - that is, when there is circular dependency, one module does not rely on another module being loaded first to initialize, instead it should lazily load that dependency after initialization.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| 'use strict'; | ||
|
|
||
| // This tests that all the native modules can be loaded independently | ||
| // Flags: --expose-internals | ||
|
|
||
| if (process.argv[3]) { | ||
| require(process.argv[3]); | ||
| return; | ||
| } | ||
|
|
||
| require('../common'); | ||
| const { | ||
| cachableBuiltins | ||
| } = require('internal/bootstrap/cache'); | ||
| const { fork } = require('child_process'); | ||
| const assert = require('assert'); | ||
|
|
||
| for (const key of cachableBuiltins) { | ||
| run(key); | ||
| } | ||
|
|
||
| function run(key) { | ||
| const child = fork(__filename, | ||
| [ '--expose-internals', key ], | ||
| { silent: true } | ||
| ); | ||
|
|
||
| let stdout = ''; | ||
| let stderr = ''; | ||
| child.stdout.on('data', (data) => (stdout += data.toString())); | ||
| child.stderr.on('data', (data) => (stderr += data.toString())); | ||
| child.on('close', (code) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||
| if (code === 0) { | ||
| return; | ||
| } | ||
| console.log(`Failed to require ${key}`) | ||
| console.log('----- stderr ----') | ||
| console.log(stderr); | ||
| console.log('----- stdout ----') | ||
| console.log(stdout); | ||
| assert.strictEqual(code, 0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Another thought, this will lead to the test failing for the first bad module masking, any other possible fails. Maybe replace with common.mustCall(() => `exit code: ${code} for module: ${key}`);The returned function will never get called, but will make the test fail when the process exits.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @refack In general I think it's fine to just fail when we encounter the first module without a clean dependency graph, and fix them one by one? |
||
| }); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use:
this way you don't need the self-reference, and eliminate L6-L9
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@refack
-eintroduces noise in the dependency graph because that option also leads to additional module loads. Same goes to-p. It somewhat weakens the test.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe use a fixture?
It seems to me like in this case the self referenced part makes the file look awkward. And the usual benefit of having all the test code in one place, is not that beneficial since the child code is just one expression.
But it's just a style nit, and I defer to your decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New idea, a variation on (either with shell or by using
child.stdin):