Skip to content
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

fix: test node-debug #470

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/dev-tools/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ case $MODE in

"node-debug")
echo "Open chrome://inspect/#devices to attach debugger."
(set -x; node --inspect-brk $TEST_SCRIPT node)
(set -x; node $TEST_SCRIPT node-debug)
;;

"dist")
Expand Down
10 changes: 8 additions & 2 deletions modules/dev-tools/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ switch (mode) {
}
break;

case 'node-debug':
runNodeTest(resolveNodeEntry('test'), '', true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean parameters are "evil", no way for reader to know what this means. Use a named option instead?

Suggested change
runNodeTest(resolveNodeEntry('test'), '', true);
runNodeTest(resolveNodeEntry('test'), '', {breakAndInspect: true);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

break;

case 'node':
case 'dist':
runNodeTest(resolveNodeEntry('test')); // Run the tests
Expand Down Expand Up @@ -100,16 +104,18 @@ function resolveBrowserEntry(key: string): string {
throw new Error(`Cannot find entry point ${key}-browser in ocular config.`);
}

function runNodeTest(entry: string, command: string = '') {
function runNodeTest(entry: string, command: string = '', shouldInspect: boolean = false) {
// Save module alias
fs.writeFileSync(
resolve(ocularConfig.ocularPath, '.alias.json'),
JSON.stringify(ocularConfig.aliases)
);

const inspectBrk = shouldInspect ? '--inspect-brk' : '';

if (ocularConfig.esm) {
execShellCommand(
`${command} node --import "${ocularConfig.ocularPath}/dist/helpers/esm-register.js" --es-module-specifier-resolution=node "${entry}"`
`${command} node ${inspectBrk} --import "${ocularConfig.ocularPath}/dist/helpers/esm-register.js" --es-module-specifier-resolution=node "${entry}"`
);
} else {
execShellCommand(
Expand Down
Loading