Skip to content

Commit a4a407c

Browse files
Fix double navigation when showing test results
When `tns test <platform>` is called and results are shown, the results page is refreshed as there's another navigation. The problem is that CLI sets karma's `singleRun` option to true and also when browser is registered, `karma-nativescript-launcher` schedules execution of tests on the new browser. In fact karma itself starts the tests on `browser register` event when the `singleRun` option is true. In our case we have double execution, so we receive the `execute` event two times (it's handled in `nativescript-unit-test-runner`). We've handled the second execution to prevent tests running, but in fact, we should receive single `execute` event. Fix this by passing watch option to `karma-nativescript-launcher`, where we'll not schedule new execution in case watch option is false. This way karma itself will start the tests as `singleRun` option is true. This will fix the double navigation when showing test results.
1 parent 71e65f3 commit a4a407c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/services/test-execution-service.ts

+5
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,20 @@ class TestExecutionService implements ITestExecutionService {
193193
options: {
194194
debugTransport: this.$options.debugTransport,
195195
debugBrk: this.$options.debugBrk,
196+
watch: !!this.$options.watch
196197
}
197198
},
198199
};
200+
199201
if (this.$config.DEBUG || this.$logger.getLevel() === 'TRACE') {
200202
karmaConfig.logLevel = 'DEBUG';
201203
}
204+
202205
if (!this.$options.watch) {
206+
// Setting singleRun to true will automatically start the tests when new browser (device in our case) is registered in karma.
203207
karmaConfig.singleRun = true;
204208
}
209+
205210
if (this.$options.debugBrk) {
206211
karmaConfig.browserNoActivityTimeout = 1000000000;
207212
}

0 commit comments

Comments
 (0)