aurelia / cli

The Aurelia 1 command line tool. Use the CLI to create projects, scaffold components, and bundle your app for release.
MIT License
407 stars 133 forks source link

Karma Unit Test Failures: Cannot find 'babel-plugin-instanbul' #1016

Open LilSebastian5000 opened 5 years ago

LilSebastian5000 commented 5 years ago

I'm submitting a bug report

Please tell us about your environment:

Current behavior: Karma tests fail to run with the following error:

Error: Cannot find module 'babel-plugin-istanbul' from 'C:\Users\xxx\Documents\aurelia_cli_2019\cli\aurelia-starter-test' If you want to resolve "istanbul", use "module:istanbul"

I found this issue: https://github.com/aurelia/cli/issues/996 and saw that the latest karma-webpack version is incorrect, so I installed "4.0.0-rc.3" as suggested. This did not fix the issue. I also noticed someone mentioned that the following would need to be added to karma.conf.js, but this also did not fix the issue:

  config.set({
    ...
    coverageIstanbulReporter: {
      ...
      skipFilesWithNoCoverage: true
    },
  })
}
LilSebastian5000 commented 5 years ago

Was able to fix this issue by adding the following to my package.json (NOT included with aurelia-cli):

"babel-plugin-istanbul": "5.1.1"

That got rid of my initial error. From there, I got the same error that was mentioned in #996 , and was able to fix it by adding this to my webpack.conf.js:

node: {fs: 'empty'},

I'm not sure if that has any negative effect on a deployed app in the long-run.

**Note, I did not end up needing "coverageIstanbulReporter" in my karma.conf.js in order to fix this issue.

3cp commented 5 years ago

The webpack setup comes with both au karma and au jest. Maybe you can use jest for the time being.

LilSebastian5000 commented 5 years ago

The webpack setup comes with both au karma and au jest. Maybe you can use jest for the time being.

Thanks for the suggestion, that may be a good tool to look into in the future!

I'm not quite sure the effort involved in converting an application from Karma to Jest without looking into it further, so I've been trying to stick with what we have for now because we have a large application with a high user base and over 1000 tests run through Karma, so if we can get away with as little changes as possible while upgrading everything, the better off we are.

Luckily seems like those minimal changes I made got it working, hopefully a change will get merged into the next release of aurelia-cli now that I've provided reproducible steps to fix :)

3cp commented 5 years ago

The cli generated webpack skeleton comes with both commands (au karma and au jest) by default.

Try au jest, if all tests pass, nothing needs to be done for the converting :)

3cp commented 5 years ago

This should be fixed by reverting #970.

https://github.com/huochunpeng/cli/commit/3c4d0d6bc8b61554a5fc29f57bd5468412123fb6

☝️Can you try update your webpack.config.js and try au karma again?