-
-
Notifications
You must be signed in to change notification settings - Fork 198
Fix unit test runner #1545
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 unit test runner #1545
Conversation
|
ping @ligaz , @teobugslayer , @hdeshev , @Mitko-Kerezov - I've retarget the PR to release branch, so we can release it in 1.6.2 |
| projectFilesPath: projectFilesPath, | ||
| syncWorkingDirectory: path.join(projectDir, constants.APP_FOLDER_NAME), | ||
| canExecuteFastSync: false, // Always restart the application when change is detected, so tests will be rerun. | ||
| excludedProjectDirsAndFiles: ["**/*.js.map", "**/*.ts"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can extract this array in a constant because I believe it is used in another place as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, yes, I was thinking the same and forgot to do it. Thanks for pointing it :)
a47ea31 to
dd45772
Compare
Fix the following issues in unit test runner: * Tests cannot start when application is not installed on device * Karma does not start when there are no .js files in app dir (initial state of TypeScript projects). * `tns test <platform> --watch` is not working for TypeScript projects * `tns test <platform> --debug-brk` does not debug. Change the way unit-tests are started. The current code was: 1) Start karma server 2) When start method of `karma-nativescript-launcher` is called, it spawns new CLI process (calls `tns dev-test` command with some arguments). 3) The new CLI process writes down some files in `node_modules/nativescript-unit-test-runner` 4) The new CLI process prepares the project. 5) The new CLI process changes the entry point of the application to point to nativescript-unit-test-runner's main-page. 6) The new CLI process calls livesync-base which should restart the application. 7) In case `--watch` option is used, karma launcher will listen for `file_list_modified` event and spawn new CLI process to run the tests. Problems were in all the steps. New way: 1) When `tns test <platform>` is called, first step is to prepare the project. 2) Initialize devices service, so we are sure all devices are detected. 3) Prepare livesync data - here we set canExecuteFastSync to false, so any change will restart the application and tests will be started again. 4) Fork new process, which should start karma server. 5) When `karma-nativescript-launcher`'s start method is called in the forked process, it will send required information to current CLI process. 6) CLI process receives the data and writes the required files in `node_modules/nativescript-unit-test-runner`. 7) CLI process calls livesync. In case --debug-brk is specified, debugService is called instead. 8) karma-nativescript-launcher no longer listens for `file-list-modified` event. CLI is alreday doing this (livesync logic). 9) Entry point of application is change by `nativescript-unit-test-runner` via after-prepare hook. The new behavior depends on the livesync - when app is not installed on the device, it will be installed. In case `--watch` is used, livesync will detect changes, prepare the project and restart the app - this will start the tests again. With this change `tns dev-test` command will stop working. As I consider it not-usable, I've deceided to skip its fixing for later.
dd45772 to
8a5d082
Compare
|
👍 |
…unner2 Fix unit test runner
Fix the following issues in unit test runner:
tns test <platform> --watchis not working for TypeScript projectstns test <platform> --debug-brkdoes not debug.Implementation details
Change the way unit-tests are started. The current code was:
karma-nativescript-launcheris called, it spawns new CLI process (callstns dev-testcommand with some arguments).node_modules/nativescript-unit-test-runner--watchoption is used, karma launcher will listen forfile_list_modifiedevent and spawn new CLI process to run the tests.Problems were in all the steps. New way:
tns test <platform>is called, first step is to prepare the project.karma-nativescript-launcher's start method is called in the forked process, it will send required information to current CLI process.node_modules/nativescript-unit-test-runner.file-list-modifiedevent. CLI is alreday doing this (livesync logic).nativescript-unit-test-runnervia after-prepare hook.The new behavior depends on the livesync - when app is not installed on the device, it will be installed. In case
--watchis used, livesync will detect changes, prepare the project and restart the app - this will start the tests again.Problem
With this change
tns dev-testcommand will stop working. As I consider it not usable, I've decided to skip its fixing for later.Related PRs:
NativeScript/nativescript-unit-test-runner#2
NativeScript/karma-nativescript-launcher#23
Fixes #1513