-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
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 all commits
152a8f6
987fe87
7925ff0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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, | ||||||
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. Maybe use:
Suggested change
this way you don't need the self-reference, and eliminate L6-L9 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 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. Then maybe use a fixture? 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. New idea, a variation on (either with shell or by using const child = exec(`echo "require('${key}')" | `${process.execPath}` --`, {shell: true}); |
||||||
[ '--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) => { | ||||||
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); | ||||||
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. 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? |
||||||
}); | ||||||
} |
Uh oh!
There was an error while loading. Please reload this page.