Skip to content

Fix unit test runner #1544

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

Closed
wants to merge 1 commit into from

Conversation

rosen-vladimirov
Copy link
Contributor

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.

Implementation details

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.

Problem

With this change tns dev-test command 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

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.
@rosen-vladimirov rosen-vladimirov self-assigned this Feb 25, 2016
@rosen-vladimirov rosen-vladimirov added this to the 1.6.2 milestone Feb 25, 2016
@rosen-vladimirov
Copy link
Contributor Author

ping @ligaz , @teobugslayer , @hdeshev , @Mitko-Kerezov

@rosen-vladimirov
Copy link
Contributor Author

Closing and retarget to release branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tns test <platform> does not work in case the application is not installed on the device.
1 participant