2016-10-07 17:38:13 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Martin Donath <martin.donath@squidfunk.com>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2016-10-10 13:35:25 +03:00
|
|
|
const path = require("path")
|
2016-10-07 17:38:13 +03:00
|
|
|
const webpack = require("webpack")
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Definition
|
|
|
|
* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
module.exports = karma => {
|
|
|
|
const config = {
|
|
|
|
basePath: "../",
|
|
|
|
frameworks: ["mocha"],
|
|
|
|
|
|
|
|
/* Include babel polyfill to support older browsers */
|
|
|
|
files: [
|
|
|
|
"node_modules/babel-polyfill/dist/polyfill.js",
|
2016-10-10 13:35:25 +03:00
|
|
|
"tests/unit/*.spec.+(js|jsx)"
|
2016-10-07 17:38:13 +03:00
|
|
|
],
|
|
|
|
|
|
|
|
/* Test reporters */
|
|
|
|
reporters: ["spec", "coverage"],
|
|
|
|
|
|
|
|
/* Silence calls to console.log */
|
|
|
|
client: {
|
|
|
|
captureConsole: false
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Preprocess test files */
|
|
|
|
preprocessors: {
|
2016-10-10 13:35:25 +03:00
|
|
|
"tests/unit/*.spec.+(js|jsx)": ["webpack", "sourcemap"]
|
2016-10-07 17:38:13 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Configuration for webpack */
|
|
|
|
webpack: {
|
2016-10-10 13:35:25 +03:00
|
|
|
module: {
|
|
|
|
|
|
|
|
/* Transpile ES6 to ES5 with Babel */
|
|
|
|
loaders: [
|
|
|
|
{
|
|
|
|
loader: "babel-loader",
|
|
|
|
test: /\.jsx?$/
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2016-10-07 17:38:13 +03:00
|
|
|
plugins: [
|
|
|
|
|
2016-10-10 13:35:25 +03:00
|
|
|
/* Don't emit assets that include errors */
|
|
|
|
new webpack.NoErrorsPlugin(),
|
|
|
|
|
|
|
|
/* Provide JSX helper */
|
2016-10-07 17:38:13 +03:00
|
|
|
new webpack.ProvidePlugin({
|
2016-10-10 13:35:25 +03:00
|
|
|
JSX: path.join(process.cwd(), "lib/providers/jsx.js")
|
2016-10-07 17:38:13 +03:00
|
|
|
})
|
|
|
|
],
|
2016-10-10 13:35:25 +03:00
|
|
|
|
|
|
|
/* Module resolver */
|
|
|
|
resolve: {
|
|
|
|
modulesDirectories: [
|
|
|
|
"src/assets/javascripts",
|
|
|
|
"node_modules"
|
|
|
|
],
|
|
|
|
extensions: [
|
|
|
|
"",
|
|
|
|
".js",
|
|
|
|
".jsx"
|
2016-10-07 17:38:13 +03:00
|
|
|
]
|
2016-10-10 13:35:25 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Sourcemap support */
|
|
|
|
devtool: "inline-source-map"
|
2016-10-07 17:38:13 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Suppress messages by webpack */
|
|
|
|
webpackServer: {
|
|
|
|
noInfo: true
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Code coverage */
|
|
|
|
coverageReporter: {
|
|
|
|
dir: "./coverage",
|
|
|
|
reporters: [
|
|
|
|
{ type: "json" }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup for continuous integration */
|
2016-10-10 13:35:25 +03:00
|
|
|
if (process.env.CI) {
|
2016-10-07 17:38:13 +03:00
|
|
|
// TODO TBD
|
|
|
|
|
|
|
|
/* Setup for local development environment */
|
2016-10-10 13:35:25 +03:00
|
|
|
} else if (process.env.WATCH) {
|
2016-10-07 17:38:13 +03:00
|
|
|
delete config.reporters
|
2016-10-10 13:35:25 +03:00
|
|
|
delete config.client.captureConsole
|
2016-10-07 17:38:13 +03:00
|
|
|
|
|
|
|
/* Setup for local testing */
|
|
|
|
} else {
|
|
|
|
config.browsers = ["Chrome"]
|
|
|
|
config.singleRun = true
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Persist configuration */
|
|
|
|
karma.set(config)
|
|
|
|
}
|