Skip to content

Commit d4817bc

Browse files
Fix hanging commands when webpack and unit tests are used (#3212)
In case you try using npm scripts that come with `nativescript-dev-webpack` and you also have `nativescript-unit-test-runner` in your project, the scripts hang. The problem is that `nativescript-unit-test-runner` has a hook that resolves `testExecutionService`. In its constructor it sets that analytics broker should not be disposed. However, this is incorrect - it should not be disposed only in case we execute tests with livesync enabled. In order to fix this, move the logic in the commands. This way the hook will not change the disposing of the analytics broker, so once CLI process finishes, analytics broker process will be disconnected and CLI's process will die gracefully. Also update submodule, where the following change is applied: Fix execution of hooks outside of process In case you need a hook to be executed outside of process, you should place correct shebang at the beginning of the file and CLI should spawn it. However, this is not working at the moment, as when CLI detects that the hook should be spawned, it just does nothing. The code is incorrectly placed inside the `if` for in process execution. This causes another issue - in case a hook returns a function, which returns falsey value, we decide the hook should be executed outside of process and spawn a new Node.js process to execute the hook. So we execute it twice. Fix the if-else logic, so the hooks will work correctly.
1 parent e181f03 commit d4817bc

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

lib/commands/test.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ function RunTestCommandFactory(platform: string) {
44
return function RunTestCommand(
55
$options: IOptions,
66
$testExecutionService: ITestExecutionService,
7-
$projectData: IProjectData) {
7+
$projectData: IProjectData,
8+
$analyticsService: IAnalyticsService) {
89
$projectData.initializeProjectData();
10+
$analyticsService.setShouldDispose($options.justlaunch || !$options.watch);
911
const projectFilesConfig = helpers.getProjectFilesConfig({ isReleaseBuild: $options.release });
1012
this.execute = (args: string[]): Promise<void> => $testExecutionService.startTestRunner(platform, $projectData, projectFilesConfig);
1113
this.allowedParameters = [];
@@ -16,8 +18,9 @@ $injector.registerCommand("dev-test|android", RunTestCommandFactory('android'));
1618
$injector.registerCommand("dev-test|ios", RunTestCommandFactory('iOS'));
1719

1820
function RunKarmaTestCommandFactory(platform: string) {
19-
return function RunKarmaTestCommand($options: IOptions, $testExecutionService: ITestExecutionService, $projectData: IProjectData) {
21+
return function RunKarmaTestCommand($options: IOptions, $testExecutionService: ITestExecutionService, $projectData: IProjectData, $analyticsService: IAnalyticsService) {
2022
$projectData.initializeProjectData();
23+
$analyticsService.setShouldDispose($options.justlaunch || !$options.watch);
2124
const projectFilesConfig = helpers.getProjectFilesConfig({ isReleaseBuild: $options.release });
2225
this.execute = (args: string[]): Promise<void> => $testExecutionService.startKarmaServer(platform, $projectData, projectFilesConfig);
2326
this.allowedParameters = [];

lib/common

lib/services/test-execution-service.ts

-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ class TestExecutionService implements ITestExecutionService {
2626
private $errors: IErrors,
2727
private $debugService: IDebugService,
2828
private $devicesService: Mobile.IDevicesService,
29-
private $analyticsService: IAnalyticsService,
3029
private $childProcess: IChildProcess) {
31-
this.$analyticsService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
3230
}
3331

3432
public platform: string;

0 commit comments

Comments
 (0)