Skip to content

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

Merged
merged 1 commit into from
Feb 26, 2016
Merged

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

@rosen-vladimirov
Copy link
Contributor Author

ping @ligaz , @teobugslayer , @hdeshev , @Mitko-Kerezov - I've retarget the PR to release branch, so we can release it in 1.6.2

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

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.

Copy link
Contributor Author

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 :)

@rosen-vladimirov rosen-vladimirov force-pushed the vladimirov/fix-unit-test-runner2 branch from a47ea31 to dd45772 Compare February 26, 2016 06:57
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 force-pushed the vladimirov/fix-unit-test-runner2 branch from dd45772 to 8a5d082 Compare February 26, 2016 07:40
@ligaz
Copy link

ligaz commented Feb 26, 2016

👍

rosen-vladimirov added a commit that referenced this pull request Feb 26, 2016
@rosen-vladimirov rosen-vladimirov merged commit f456ecf into release Feb 26, 2016
@rosen-vladimirov rosen-vladimirov deleted the vladimirov/fix-unit-test-runner2 branch February 26, 2016 08:39
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.

2 participants