Nativescript-cli: `tns test <platform> --watch` does not work

Created on 11 Oct 2016  路  8Comments  路  Source: NativeScript/nativescript-cli

These are the versions of the software that I have:

  • OSX El Capitan
  • tns --version: 2.3.0
  • nativescript-angular: 1.0.1
  • nativescript-unit-test-runner: ^0.3.3
  • tns-core-modules: 2.3.0

This is how I set up the project:

$ tns create my_new_project --ng
$ cd my_new_project
$ tns platform add ios
$ tns platform add android
$ tns test init
    >> Choose jasmine

Without changing any code, I start running tests...

On Android, the tests run and the output ends like this:

$ tns test android --emulator --watch
...
NativeScript / 23 (6.0; Android SDK built for x86) ERROR
  Disconnectedundefined

The tests do not rerun when I make changes. I see that the changes are detected but the tests don't run:

11 10 2016 11:21:04.478:INFO [watcher]: Changed file "/Users/cmermingas/tns_projects/my_new_project/app/tests/example.js".
11 10 2016 11:21:04.732:WARN [karma]: No captured browser, open http://localhost:9876/

If I open a browser, then I get:

11 10 2016 11:22:13.347:INFO [Chrome 53.0.2785 (Mac OS X 10.11.6)]: Connected on socket /#x5V6NG4VxeYe-eglAAAB with id manual-6010
11 10 2016 11:22:21.380:INFO [watcher]: Changed file "/Users/cmermingas/tns_projects/my_new_project/app/tests/example.js".
Chrome 53.0.2785 (Mac OS X 10.11.6) ERROR
  Uncaught ReferenceError: require is not defined
  at app/app.component.js:2

But I understand that I don't need a browser connected here as I do when I am testing a regular web app, correct?

On iOS, I get something similar. The tests run and the output ends like this:

$ tns test ios --emulator --watch
...
NativeScript / 10.0 (10.0; iPhone) ERROR
  Disconnectedundefined

And when I change the code, the tests don't rerun.

feature unit testing livesync

Most helpful comment

I'm also getting the same behavior as @cmermingas when running tns test android --watch under windows 10. Everything else looks to be the same version as @cmermingas is using.

All 8 comments

Currently the watch option is available only when using run, debug and livesync commands.

Cool. The docs are not in sync:

http://docs.nativescript.org/tooling/testing#re-run-tests-on-code-change

screen shot 2016-10-12 at 9 39 50 am

Thank you!

@cmermingas Hey, my mistake. The documentation is correct. This is a valid issue. I updated the label.

I'm also getting the same behavior as @cmermingas when running tns test android --watch under windows 10. Everything else looks to be the same version as @cmermingas is using.

Same issue with @cmermingas, @jeffswitzer on Windows 10 Creator

  • tns --version: 2.5.0
  • nativescript-angular: 1.4.0
  • nativescript-unit-test-runner: ^0.3.4
  • tns-core-modules: 2.5.2

Real Device: Android 5.1 on Galaxy S6

1

My Karma config

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',


    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [
      'app/**/*.ts'
    ],


    // list of files to exclude
    exclude: [
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
       'app/**/*.ts': ['typescript', 'coverage']
    },

    typescriptPreprocessor: {
      // options passed to the typescript compiler 
      options: {
        sourceMap: false, // (optional) Generates corresponding .map file. 
        target: 'ES5', // (optional) Specify ECMAScript target version: 'ES3' (default), or 'ES5' 
        module: 'amd', // (optional) Specify module code generation: 'commonjs' or 'amd' 
        noImplicitAny: true, // (optional) Warn on expressions and declarations with an implied 'any' type. 
        noResolve: true, // (optional) Skip resolution and preprocessing. 
        removeComments: true, // (optional) Do not emit comments to output. 
        concatenateOutput: false // (optional) Concatenate and emit output to single file. By default true if module option is omited, otherwise false. 
      },
      // transforming the filenames 
      transformPath: function(path) {
        return path.replace(/\.ts$/, '.js');
      }
    },

    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress', 'coverage'],


    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: [],

    customLaunchers: {
      android: {
        base: 'NS',
        platform: 'android'
      },
      ios: {
        base: 'NS',
        platform: 'ios'
      },
      ios_simulator: {
        base: 'NS',
        platform: 'ios',
        arguments: ['--emulator']
      }
    },

    coverageReporter: {
      // specify a common output directory
      dir: './coverage',
      reporters: [
          { type: 'lcov', subdir: '.' },
          { type: 'cobertura', subdir: '.' }
      ],
      includeAllSources: true
    },

    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: true
  })
}

Don't know why, it seems working well on my android emulator

1

@phattranky it works for you because you have singleRun: true

Closing in favor of https://github.com/NativeScript/nativescript-cli/issues/2739

Was this page helpful?
0 / 5 - 0 ratings