nativescript-cli icon indicating copy to clipboard operation
nativescript-cli copied to clipboard

Testing broken: webpack 4 vs webpack 3 requirement by karma-webpack 3.0.5

Open freeo opened this issue 4 years ago • 2 comments

Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

✔ Component nativescript has 7.1.2 version and is up to date. ✔ Component @nativescript/core has 7.1.2 version and is up to date. ✖ Component @nativescript/ios is not installed. ✔ Component @nativescript/android has 7.0.1 version and is up to date

Describe the bug

ns test android fails with this karma error: ERROR [preprocess]: Can not load "webpack"! Because webpack 3 can't be installed side by side with webpack 4 (afaik?!). npm install correctly states that the peer dependency for webpack 3 (required by [email protected]) needs to be installed manually.

  "dependencies": {
    "@nativescript/core": "~7.1.0",
    "@nativescript/theme": "~2.3.0",
    "@nativescript/unit-test-runner": "^1.0.2"
  },
  "devDependencies": {
    "@nativescript/android": "7.0.1",
    "@nativescript/webpack": "~4.0.0",
    "@types/karma-chai": "0.1.2",
    "@types/mocha": "8.2.0",
    "chai": "4.2.0",
    "karma": "6.0.0",
    "karma-chai": "0.1.0",
    "karma-mocha": "2.0.1",
    "karma-nativescript-launcher": "0.4.0",
    "karma-webpack": "3.0.5",
    "mocha": "8.2.1",
    "typescript": "~3.9.0"
  },

To Reproduce

ns create karmaissue --template @nativescript/[email protected]
cd karmaissue
ns test init --framework mocha
ns test android

Expected behavior Sample test runs (karma doesn't throw an error)

freeo avatar Jan 15 '21 15:01 freeo

Your issue might be karma 6.

See this issue https://github.com/angular/angular-cli/issues/19815

Try using "karma": "5.2.3"

I was able to get testing working following these steps:

  • ns create testapp --ng
  • ns test init --framework jasmine
  • ns test android -- received error message Can not load "webpack"!
  • switch to karma 5.2.3
  • ns test android
  • this time the sample test ran

cwolff-wells avatar Jan 19 '21 15:01 cwolff-wells

Hi! I am unable to make testing work on a fresh project Environment (Intel) Mac Mini 2018 with macOS macOS 11.2.3 (20D91)

$ node --version
v15.14.0
$ npm --version
7.11.1
$ ns --version
8.0.1

Steps to create a fresh TypeScript project and setup testing with mocha

ns create --ts MyApp

pushd MyApp > /dev/null

# Workaround for for npm 7 peer deps
echo "legacy-peer-deps=true" > .npmrc
ns clean
npm i

ns platform add android
ns test init --framework=mocha
ns test android --justlaunch # tried without this flag with the same result

popd > /dev/null

The test command results in the following error

Searching for devices...
[@nativescript/webpack] Warn: 
 Cannot find NativeScript CLI path. Make sure --env.nativescriptLibPath is passed
24 04 2021 14:10:18.742:ERROR [plugin]: Cannot find plugin "/Users/adriann/Developer/SANDBOX/MyApp/node_modules/karma-webpack".
  Did you forget to install it?
  npm install /Users/adriann/Developer/SANDBOX/MyApp/node_modules/karma-webpack --save-dev
24 04 2021 14:10:18.747:ERROR [preprocess]: Can not load "webpack", it is not registered!
  Perhaps you are missing some plugin?
24 04 2021 14:10:18.770:ERROR [karma-server]: Error during file loading or preprocessing
TypeError: process is not a function
    at executeProcessor (/Users/adriann/Developer/SANDBOX/MyApp/node_modules/karma/lib/preprocessor.js:47:11)
    at runProcessors (/Users/adriann/Developer/SANDBOX/MyApp/node_modules/karma/lib/preprocessor.js:60:23)
    at FileList.preprocess [as _preprocess] (/Users/adriann/Developer/SANDBOX/MyApp/node_modules/karma/lib/preprocessor.js:134:11)
    at async Promise.all (index 0)
    at async /Users/adriann/Developer/SANDBOX/MyApp/node_modules/karma/lib/file-list.js:90:11
    at async Promise.all (index 4)
24 04 2021 14:10:18.773:INFO [karma-server]: Karma v5.2.3 server started at http://localhost:9876/
24 04 2021 14:10:18.773:INFO [launcher]: Launching browsers android with concurrency unlimited
24 04 2021 14:10:18.774:ERROR [karma-server]: Error: Found 2 load errors
    at Server.<anonymous> (/Users/adriann/Developer/SANDBOX/MyApp/node_modules/karma/lib/server.js:213:27)
    at Object.onceWrapper (node:events:475:28)
    at Server.emit (node:events:381:22)
    at emitListeningNT (node:net:1345:10)
    at processTicksAndRejections (node:internal/process/task_queues:80:21)
Test run failed.

This replicates for both android and ios.

As suggested above, I tried installing karma@5 instead, but with the same result:

npm install karma@5
ns clean
npm i
ns test android

adrian-niculescu avatar Apr 24 '21 11:04 adrian-niculescu