mercredi 22 juin 2016

Using the karma-coverage to test React App and get the Coverage Report

Now I'm using the karam + jasmine + webpack + airbnb for my React App Testing. When using the karma-coverage plugin I just has some prombles.

here's my karma.conf.js

// I had inclue the './src/components/root.js'
// if I just include the ./src/**/*-test.js then the Component js will not be loaded 
// by the `preprocessors`

files: [
  './src/components/root.js',
  './src/**/*-test.js'
],
preprocessors: {

    // i do add this line for has the components/root.js get the coverage report, but 
    './src/components/root.js': ['webpack', 'sourcemap', 'coverage'],
    './src/**/*-test.js': [ 'webpack', 'sourcemap' ]
}
coverageRepoter: {
    type: 'html',
    dir: './coverage'
}

when I just run the karma start then I got the error like this

Uncaught Error: Cannot find module "../root"

at /Users/youngBrain/Desktop/react-karma-webpack-testing/src/components/tests/root-test.js:59 <- webpack:///src/components/tests/root-test.js:4:0 Chrome 51.0.2704 (Mac OS X 10.11.5): Executed 0 of 0 ERROR (1.013 secs / 0 secs)

and my source-tree just like this source-tree

The ./src/components/root.js is just a normal React Component, it was imported in the ./src/components/__tests__/root-test.js by using import Root from '../root'

if I do change the files option in the karma.conf.js to */**/*-test.js I just pass the test, but I can't get the Coverage-Report for my Components.

I think it may because of ../root is an entry for the webpack, but if these file not be transformed with webpack it will not work well for the jsx and some ES6 features.

How Can I Solve This Problem.

Aucun commentaire:

Enregistrer un commentaire