Skip to content

Default unit testing failing on hello world #1310

Open
@benjlin

Description

@benjlin

When attempting to run unit testing on the default template app it crashes with

bens-mbp:test benjlin$ tns test ios
Searching for devices...
01 05 2018 07:27:07.314:WARN [karma]: No captured browser, open http://localhost:9876/
01 05 2018 07:27:07.328:INFO [karma]: Karma v2.0.2 server started at http://0.0.0.0:9876/
01 05 2018 07:27:07.329:INFO [launcher]: Launching browser ios with unlimited concurrency
01 05 2018 07:27:07.357:INFO [launcher]: Starting browser NativeScript Unit Test Runner
Executing before-prepare hook from /Users/benjlin/Documents/Code/Nativescript/test/hooks/before-prepare/nativescript-dev-typescript.js
Found peer TypeScript 2.6.2
Preparing project...
01 05 2018 07:27:10.721:INFO [watcher]: Changed file "/Users/benjlin/Documents/Code/Nativescript/test/app/app.component.js".
01 05 2018 07:27:10.722:INFO [watcher]: Changed file "/Users/benjlin/Documents/Code/Nativescript/test/app/app.module.js".
01 05 2018 07:27:10.723:INFO [watcher]: Changed file "/Users/benjlin/Documents/Code/Nativescript/test/app/main.aot.js".
01 05 2018 07:27:10.725:INFO [watcher]: Changed file "/Users/benjlin/Documents/Code/Nativescript/test/app/main.js".
01 05 2018 07:27:10.977:WARN [karma]: No captured browser, open http://localhost:9876/
01 05 2018 07:27:14.197:INFO [Chrome 65.0.3325 (Mac OS X 10.13.4)]: Connected on socket hD-sUKklfXQ2LEbmAAAA with id manual-3472
Project successfully prepared (ios)
Executing after-prepare hook from /Users/benjlin/Documents/Code/Nativescript/test/hooks/after-prepare/nativescript-unit-test-runner.js
Executing before-liveSync hook from /Users/benjlin/Documents/Code/Nativescript/test/hooks/before-liveSync/nativescript-angular-sync.js
Skipping prepare.
Successfully transferred all files.
Refreshing application...
Successfully synced application org.nativescript.test on device AD2FE2D6-4E3F-41B8-AE8C-460BE9C15843.
Executing before-watch hook from /Users/benjlin/Documents/Code/Nativescript/test/hooks/before-watch/nativescript-dev-typescript.js
Found peer TypeScript 2.6.2
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:54:28: NSUTR: fetching http://127.0.0.1:9876/context.json
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:54:28: NSUTR: fetching http://192.168.86.105:9876/context.json
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:54:28: NSUTR: fetching http://169.254.100.211:9876/context.json
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:60:32: NSUTR: found karma at 127.0.0.1
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:97:20: NSUTR: connecting to karma at http://127.0.0.1:9876
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:60:32: NSUTR: found karma at 192.168.86.105
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:60:32: NSUTR: found karma at 169.254.100.211
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:116:24: NSUTR: successfully connected to karma
01 05 2018 07:27:24.238:INFO [NativeScript / 11.3 (11.3; iPhone)]: Connected on socket pi1YRlwENESpccmzAAAB with id NativeScriptUnit-2789
Chrome 65.0.3325 (Mac OS X 10.13.4) ERROR
  {
    "message": "An error was thrown in afterAll\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined",
    "str": "An error was thrown in afterAll\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined"
  }
Chrome 65.0.3325 (Mac OS X 10.13.4): Executed 1 of 1 ERROR (0.01 secs / 0 secs)
01 05 2018 07:27:24.414:INFO [watcher]: Changed file "/Users/benjlin/Documents/Code/Nativescript/test/app/app.component.js".
01 05 2018 07:27:24.578:INFO [watcher]: Changed file "/Users/benjlin/Documents/Code/Nativescript/test/app/app.module.js".
01 05 2018 07:27:24.679:INFO [watcher]: Changed file "/Users/benjlin/Documents/Code/Nativescript/test/app/main.js".
01 05 2018 07:27:24.680:INFO [watcher]: Changed file "/Users/benjlin/Documents/Code/Nativescript/test/app/main.aot.js".
01 05 2018 07:27:24.934:INFO [karma]: Delaying execution, these browsers are not ready: NativeScript / 11.3 (11.3; iPhone)
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:159:20: NSUTR: downloading http://127.0.0.1:9876/context.json
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:200:32: NSUTR: eval script /base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?daba65c98fa088349a3e9d7df843a63405ccfc15
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:200:32: NSUTR: eval script /base/node_modules/karma-jasmine/lib/boot.js?945a38bf4e45ad2770eb94868231905a04a0bd3e
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:200:32: NSUTR: eval script /base/node_modules/karma-jasmine/lib/adapter.js?3e6cdea3167f037eeb11034f8eb9ce63b21a8105
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:196:32: NSUTR: require script /base/app/tests/example.js?d4cad4cd203df70666c986cd09ce402b21d89b39 from ../../tests/example.js
Chrome 65.0.3325 (Mac OS X 10.13.4): Executed 1 of 1 ERROR (0.01 secs / 0 secs)
Chrome 65.0.3325 (Mac OS X 10.13.4): Executed 1 of 1 ERROR (0.01 secs / 0 secs)
NativeScript / 11.3 (11.3; iPhone): Executed 1 of 1 SUCCESS (0.014 secs / 0 secs)
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:258:24: NSUTR: completeAck
Chrome 65.0.3325 (Mac OS X 10.13.4) ERROR
  {
    "message": "An error was thrown in afterAll\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined",
    "str": "An error was thrown in afterAll\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined"
  }
Chrome 65.0.3325 (Mac OS X 10.13.4): Executed 1 of 1 ERROR (0.004 secs / 0 secs)
7:27:25 AM - Compilation complete. Watching for file changes.



NativeScript / 11.3 (11.3; iPhone) ERROR
  Disconnected
Chrome 65.0.3325 (Mac OS X 10.13.4): Executed 1 of 1 ERROR (0.004 secs / 0 secs)
^CExecuting after-watch hook from /Users/benjlin/Documents/Code/Nativescript/test/hooks/after-watch/nativescript-dev-typescript.js
Stopping tsc watch

Steps to replicate

  1. run tns create HelloWorld --template nativescript-template-ng-tutorial
  2. cd ./HelloWorld
  3. tns run ios
  4. tns test init
  5. Select Jasmin as the test framework
  6. admire the failed test.

the same error occurs running both android and ios

I suspect that it is something to do with the default Karma configuration file generated

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/**/*.js',
    ],


    // 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: {
    },


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


    // 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']
      }
    },

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions