Running Mocha + Istanbul + Babel

后端 未结 3 1789
暗喜
暗喜 2020-12-07 16:54

I\'m having some issues while running istanbul with mocha and the babel compiler..

all my tests are runnning just fine, but after all the tests done it shows me this

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 17:01

    As of now 17.4.2016 this coverage reporting stuff is still a bit messy and with my React-project that has .jsx files and a helper file the coverage reporting script looks like this:

    istanbul cover node_modules/mocha/bin/_mocha -- \
       --compilers js:babel-core/register \
       --require ./test/testhelper.js  \
       \"test/**/*@(.js|.jsx)\"
    

    So it wouldn't be too easy the current version 0.4.3 of Istanbul doesn't work with Babel so you have to use the experimental alpha-version:

    npm install istanbul@1.0.0-alpha.2 --save-dev
    

    And then you need .istanbul.yml -file so that Istanbul recognizes the .jsx-files with these lines:

    instrumentation:
      root: .
      extensions: ['.js', '.jsx']
    

    And now it should work. Also as a small bonus if you want to add coverage reporting with Travis and Coveralls you should:

    1. enable the project in https://coveralls.io
    2. add coveralls npm i coveralls --save-dev
    3. add this to your .travis.yml:

      script:
        - npm --silent test
        - cat ./c
      coverage/lcov.info | coveralls
      

    And now you can put that cool badge to your README. Neato!

提交回复
热议问题