Created
December 2, 2015 23:01
-
-
Save dtothefp/4e282f54ec577b54ec71 to your computer and use it in GitHub Desktop.
Isparta Loader for Webpack, Babel 6, and React
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//webpack config | |
export default { | |
isparta: { | |
embedSource: true, | |
noAutoWrap: true, | |
babel: { | |
presets: ['es2015', 'stage-0', 'react'] | |
} | |
}, | |
module: { | |
preLoaders: [ | |
{ | |
test: /\.jsx?$/, | |
loader: 'isparta', | |
exclude: [ | |
/(test|node_modules)/, | |
addbase(srcDir, scriptDir, 'index.js') //exclude react component mounting | |
] | |
} | |
] | |
} | |
} | |
//bootstrap.test.js | |
const {TEST_FILE} = process.env; | |
const re = TEST_FILE !== null ? new RegExp(`${TEST_FILE}.js`) : /-spec\.js$/; | |
const context = require.context('../integration', true, /-spec\.js$/); | |
context.keys().forEach((key) => { | |
if (re.test(key)) { | |
context(key); | |
} | |
}); | |
const componentsContext = require.context('../../src/js', true, /\.jsx?$/); | |
componentsContext.keys().forEach((key) => { | |
/** | |
* recursively require all source for isparta code coverage | |
* ignore index.js because React component will try to mount before | |
* DOM is available | |
*/ | |
if (!/\.\/index\.jsx?$/.test(key)) { | |
componentsContext(key); | |
} | |
}); | |
//karma.config | |
config.set({ | |
files: [ | |
testPath | |
], | |
preprocessors, | |
reporters: [ 'spec', 'coverage' ], | |
coverageReporter: { | |
reporters: [ | |
{type: 'lcov', dir: 'coverage/', subdir: '.'}, | |
{type: 'json', dir: 'coverage/', subdir: '.'}, | |
{type: 'text-summary'} | |
] | |
}, | |
webpack: webpackConfig, | |
webpackMiddleware: { | |
noInfo: true | |
} | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment