Skip to content

Commit bead23d

Browse files
fix: enable debugging of unit test runner process
When CLI executes unit tests (for the NativeScript application), it forks a new Node.js process and communicates with it via IPC. However, the Node.js fork method has an issue when you want to debug your main process - it passes the `--inspect[-brk]` option to the forked process as well. The main process had already used the port, so debugging fails. In order to fix this, replace the `fork` with `spawn`.
1 parent 6167820 commit bead23d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

.vscode/launch.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
"request": "launch",
1010
"cwd": "${workspaceRoot}",
1111
"sourceMaps": true,
12+
// In case you want to debug child processes started from CLI:
13+
// "autoAttachChildProcesses": true,
1214
"name": "Launch CLI (Node 6+)",
1315
"program": "${workspaceRoot}/lib/nativescript-cli.js",
1416

1517
// example commands
1618
"args": [ "create", "cliapp"]
19+
// "args": [ "test", "android", "--justlaunch"]
1720
// "args": [ "platform", "add", "[email protected]", "--path", "cliapp"]
1821
// "args": [ "platform", "remove", "android", "--path", "cliapp"]
1922
// "args": [ "plugin", "add", "nativescript-barcodescanner", "--path", "cliapp"]

lib/services/test-execution-service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ class TestExecutionService implements ITestExecutionService {
171171
});
172172

173173
const karmaConfig = this.getKarmaConfiguration(platform, projectData),
174-
karmaRunner = this.$childProcess.fork(path.join(__dirname, "karma-execution.js")),
174+
// In case you want to debug the unit test runner, add "--inspect-brk=<port>" as a first element in the array of args.
175+
karmaRunner = this.$childProcess.spawn(process.execPath, [ path.join(__dirname, "karma-execution.js")], { stdio: ["inherit", "inherit", "inherit", "ipc"] }),
175176
launchKarmaTests = async (karmaData: any) => {
176177
this.$logger.trace("## Unit-testing: Parent process received message", karmaData);
177178
let port: string;

0 commit comments

Comments
 (0)