nativescript-dev-webpack icon indicating copy to clipboard operation
nativescript-dev-webpack copied to clipboard

unit testing with webpack

Open HtaSophia opened this issue 6 years ago • 2 comments

I did update tns to version 5.4 and I tried to run the test with the project created by nativescript cli. However, karma did not work in the browser.

The following error appears: global is not defined.

image

image

I tried the commands: npm i nativescript-dev-webpack@latest --save-dev

./node_modules/.bin/update-ns-webpack --deps --configs

Versions: "karma": "4.1.0", "karma-chrome-launcher": "^2.2.0", "karma-jasmine": "2.0.1", "karma-nativescript-launcher": "0.4.0", "karma-webpack": "3.0.5", "nativescript-dev-typescript": "~0.9.0", "nativescript-dev-webpack": "^0.22.0"

In the webpack.config: output: { pathinfo: false, path: dist, sourceMapFilename, libraryTarget: "commonjs2", filename: "[name].js", globalObject: "global", hashSalt }

HtaSophia avatar May 16 '19 18:05 HtaSophia

@HtaSophia,

NativeScript CLI runs unit tests on device or emulator, not in browser. Karma supports a mode to run outside a browser in a JavaScript-only environment and that is what NativeScript CLI do.

Just execute

tns test ios

This will start an emulator if there aren't connected devices, run the tests on emulator/device and report back the results. No need from additional actions in order to see the results from tests.

Fatme avatar May 16 '19 19:05 Fatme

I was already running the tests correctly and it works. However, I think the karma have more meaningful output on browser like the task's names and his result.

The output of the tests in the terminal is very limited.

image

HtaSophia avatar May 17 '19 16:05 HtaSophia