nativescript-angular: Default unit testing failing on hello world
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
- run tns create HelloWorld --template nativescript-template-ng-tutorial
- cd ./HelloWorld
- tns run ios
- tns test init
- Select Jasmin as the test framework
- 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
})
}
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 2
- Comments: 19 (5 by maintainers)
Commits related to this issue
- feat: respect nsconfig file from project and correctly navigate to run tests page Rel to: https://github.com/NativeScript/nativescript-angular/issues/1310 https://github.com/NativeScript/nativescript... — committed to NativeScript/nativescript-unit-test-runner by Fatme 5 years ago
- feat: respect nsconfig file from project and correctly navigate to run tests page Rel to: https://github.com/NativeScript/nativescript-angular/issues/1310 https://github.com/NativeScript/nativescript... — committed to NativeScript/nativescript-unit-test-runner by Fatme 5 years ago
- fix: respect nsconfig file on `tns test` command Rel to: NativeScript/nativescript-angular#1310 NativeScript/nativescript-cli#4244 — committed to NativeScript/nativescript-cli by Fatme 5 years ago
After more digging around I found the reason why tests aren’t working with
srcfolder.The unit-test-runner app has a hardcoded app folder here. However files are in
base/srcinstead ofbase/app. So the test files are not treated as “local” and areeval-ed instead of required.Maybe the solution is to pass the actual
appfolder to the unit-test-app trough theconfig.jsoptions, so that it can correctly determine which files are tests. @rosen-vladimirov - what do you think? I can do a PR if you think this is the correct way to go?Hey folks. I also managed to get the test running by renaming
src->appas @m-abs mentioned. I had to changesrctoappinkarma.config.js,nsconfig.jsonandtsconfig.jsonas well.I ran into this too. I created a new project with
tns create <NAME> --ngand configured testing withtns test init --framework jasmine.This gave the same error as @benjlin reported.
After a while I tried renaming
srctoappand updated mytsconfig.jsonandnsconfig.jsonto match that and that solved the problem. I don’t understand why it worked, but it did.I also experience this issue within my project and recreated it by following the testing documentation for the downloaded playground application. It seems when invoking the tns test <device>, the client disconnects from the karma server because it cannot compile some javascript.
I get the following errors in the console for the browser:
Hi @benjlin, Thank you for contacting us. We will check reported case and will verify if there is a real issue, which could lead to a crash on the application. You can keep track on the issue for further info.
@m-abs,
This should be fixed in next version of {N} CLI, so you need
I’ve managed to resolve this (
exports is not defined) by degradingjasmine-coreto^2.9.0.