Only add frontend code coverage instrumentation when generating coverage report
This commit is contained in:
parent
b26d4d2ac4
commit
fde335bfb7
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"presets": [
|
||||
["latest", { "es2015": { "modules": false } }],
|
||||
"stage-2"
|
||||
],
|
||||
"env": {
|
||||
"coverage": {
|
||||
"plugins": [
|
||||
["istanbul", {
|
||||
"exclude": [
|
||||
"app/assets/javascripts/droplab/**/*",
|
||||
"spec/javascripts/**/*"
|
||||
]
|
||||
}],
|
||||
["transform-define", {
|
||||
"process.env.BABEL_ENV": "coverage"
|
||||
}]
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -277,6 +277,8 @@ rake karma:
|
|||
stage: test
|
||||
<<: *use-db
|
||||
<<: *dedicated-runner
|
||||
variables:
|
||||
BABEL_ENV: "coverage"
|
||||
script:
|
||||
- bundle exec rake karma
|
||||
artifacts:
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Only add code coverage instrumentation when generating coverage report
|
||||
merge_request: 9987
|
||||
author:
|
|
@ -3,17 +3,6 @@ var webpack = require('webpack');
|
|||
var webpackConfig = require('./webpack.config.js');
|
||||
var ROOT_PATH = path.resolve(__dirname, '..');
|
||||
|
||||
// add coverage instrumentation to babel config
|
||||
if (webpackConfig.module && webpackConfig.module.rules) {
|
||||
var babelConfig = webpackConfig.module.rules.find(function (rule) {
|
||||
return rule.loader === 'babel-loader';
|
||||
});
|
||||
|
||||
babelConfig.options = babelConfig.options || {};
|
||||
babelConfig.options.plugins = babelConfig.options.plugins || [];
|
||||
babelConfig.options.plugins.push('istanbul');
|
||||
}
|
||||
|
||||
// remove problematic plugins
|
||||
if (webpackConfig.plugins) {
|
||||
webpackConfig.plugins = webpackConfig.plugins.filter(function (plugin) {
|
||||
|
@ -27,7 +16,8 @@ if (webpackConfig.plugins) {
|
|||
// Karma configuration
|
||||
module.exports = function(config) {
|
||||
var progressReporter = process.env.CI ? 'mocha' : 'progress';
|
||||
config.set({
|
||||
|
||||
var karmaConfig = {
|
||||
basePath: ROOT_PATH,
|
||||
browsers: ['PhantomJS'],
|
||||
frameworks: ['jasmine'],
|
||||
|
@ -38,14 +28,20 @@ module.exports = function(config) {
|
|||
preprocessors: {
|
||||
'spec/javascripts/**/*.js': ['webpack', 'sourcemap'],
|
||||
},
|
||||
reporters: [progressReporter, 'coverage-istanbul'],
|
||||
coverageIstanbulReporter: {
|
||||
reporters: [progressReporter],
|
||||
webpack: webpackConfig,
|
||||
webpackMiddleware: { stats: 'errors-only' },
|
||||
};
|
||||
|
||||
if (process.env.BABEL_ENV === 'coverage' || process.env.NODE_ENV === 'coverage') {
|
||||
karmaConfig.reporters.push('coverage-istanbul');
|
||||
karmaConfig.coverageIstanbulReporter = {
|
||||
reports: ['html', 'text-summary'],
|
||||
dir: 'coverage-javascript/',
|
||||
subdir: '.',
|
||||
fixWebpackSourcePaths: true
|
||||
},
|
||||
webpack: webpackConfig,
|
||||
webpackMiddleware: { stats: 'errors-only' },
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
config.set(karmaConfig);
|
||||
};
|
||||
|
|
|
@ -59,13 +59,7 @@ var config = {
|
|||
{
|
||||
test: /\.js$/,
|
||||
exclude: /(node_modules|vendor\/assets)/,
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
presets: [
|
||||
["es2015", {"modules": false}],
|
||||
'stage-2'
|
||||
]
|
||||
}
|
||||
loader: 'babel-loader'
|
||||
},
|
||||
{
|
||||
test: /\.svg$/,
|
||||
|
|
11
package.json
11
package.json
|
@ -6,6 +6,7 @@
|
|||
"eslint-fix": "eslint --max-warnings 0 --ext .js --fix .",
|
||||
"eslint-report": "eslint --max-warnings 0 --ext .js --format html --output-file ./eslint-report.html .",
|
||||
"karma": "karma start config/karma.config.js --single-run",
|
||||
"karma-coverage": "BABEL_ENV=coverage karma start config/karma.config.js --single-run",
|
||||
"karma-start": "karma start config/karma.config.js",
|
||||
"webpack": "webpack --config config/webpack.config.js",
|
||||
"webpack-prod": "NODE_ENV=production webpack --config config/webpack.config.js"
|
||||
|
@ -13,7 +14,8 @@
|
|||
"dependencies": {
|
||||
"babel-core": "^6.22.1",
|
||||
"babel-loader": "^6.2.10",
|
||||
"babel-preset-es2015": "^6.22.0",
|
||||
"babel-plugin-transform-define": "^1.2.0",
|
||||
"babel-preset-latest": "^6.24.0",
|
||||
"babel-preset-stage-2": "^6.22.0",
|
||||
"bootstrap-sass": "^3.3.6",
|
||||
"compression-webpack-plugin": "^0.3.2",
|
||||
|
@ -57,12 +59,5 @@
|
|||
"karma-sourcemap-loader": "^0.3.7",
|
||||
"karma-webpack": "^2.0.2",
|
||||
"webpack-dev-server": "^2.3.0"
|
||||
},
|
||||
"nyc": {
|
||||
"exclude": [
|
||||
"spec/javascripts/test_bundle.js",
|
||||
"spec/javascripts/**/*_spec.js",
|
||||
"app/assets/javascripts/droplab/**/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,10 +32,11 @@ testsContext.keys().forEach(function (path) {
|
|||
}
|
||||
});
|
||||
|
||||
// workaround: include all source files to find files with 0% coverage
|
||||
// see also https://github.com/deepsweet/istanbul-instrumenter-loader/issues/15
|
||||
describe('Uncovered files', function () {
|
||||
// the following files throw errors because of undefined variables
|
||||
// if we're generating coverage reports, make sure to include all files so
|
||||
// that we can catch files with 0% coverage
|
||||
// see: https://github.com/deepsweet/istanbul-instrumenter-loader/issues/15
|
||||
if (process.env.BABEL_ENV === 'coverage') {
|
||||
// exempt these files from the coverage report
|
||||
const troubleMakers = [
|
||||
'./blob_edit/blob_edit_bundle.js',
|
||||
'./cycle_analytics/components/stage_plan_component.js',
|
||||
|
@ -48,21 +49,23 @@ describe('Uncovered files', function () {
|
|||
'./network/branch_graph.js',
|
||||
];
|
||||
|
||||
const sourceFiles = require.context('~', true, /^\.\/(?!application\.js).*\.js$/);
|
||||
sourceFiles.keys().forEach(function (path) {
|
||||
// ignore if there is a matching spec file
|
||||
if (testsContext.keys().indexOf(`${path.replace(/\.js$/, '')}_spec`) > -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
it(`includes '${path}'`, function () {
|
||||
try {
|
||||
sourceFiles(path);
|
||||
} catch (err) {
|
||||
if (troubleMakers.indexOf(path) === -1) {
|
||||
expect(err).toBeNull();
|
||||
}
|
||||
describe('Uncovered files', function () {
|
||||
const sourceFiles = require.context('~', true, /\.js$/);
|
||||
sourceFiles.keys().forEach(function (path) {
|
||||
// ignore if there is a matching spec file
|
||||
if (testsContext.keys().indexOf(`${path.replace(/\.js$/, '')}_spec`) > -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
it(`includes '${path}'`, function () {
|
||||
try {
|
||||
sourceFiles(path);
|
||||
} catch (err) {
|
||||
if (troubleMakers.indexOf(path) === -1) {
|
||||
expect(err).toBeNull();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
70
yarn.lock
70
yarn.lock
|
@ -473,6 +473,13 @@ babel-plugin-transform-decorators@^6.22.0:
|
|||
babel-template "^6.22.0"
|
||||
babel-types "^6.22.0"
|
||||
|
||||
babel-plugin-transform-define@^1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-plugin-transform-define/-/babel-plugin-transform-define-1.2.0.tgz#f036bda05162f29a542e434f585da1ccf1e7ec6a"
|
||||
dependencies:
|
||||
lodash.get "4.4.2"
|
||||
traverse "0.6.6"
|
||||
|
||||
babel-plugin-transform-es2015-arrow-functions@^6.22.0:
|
||||
version "6.22.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-arrow-functions/-/babel-plugin-transform-es2015-arrow-functions-6.22.0.tgz#452692cb711d5f79dc7f85e440ce41b9f244d221"
|
||||
|
@ -549,17 +556,17 @@ babel-plugin-transform-es2015-literals@^6.22.0:
|
|||
dependencies:
|
||||
babel-runtime "^6.22.0"
|
||||
|
||||
babel-plugin-transform-es2015-modules-amd@^6.22.0:
|
||||
version "6.22.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-amd/-/babel-plugin-transform-es2015-modules-amd-6.22.0.tgz#bf69cd34889a41c33d90dfb740e0091ccff52f21"
|
||||
babel-plugin-transform-es2015-modules-amd@^6.24.0:
|
||||
version "6.24.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-amd/-/babel-plugin-transform-es2015-modules-amd-6.24.0.tgz#a1911fb9b7ec7e05a43a63c5995007557bcf6a2e"
|
||||
dependencies:
|
||||
babel-plugin-transform-es2015-modules-commonjs "^6.22.0"
|
||||
babel-plugin-transform-es2015-modules-commonjs "^6.24.0"
|
||||
babel-runtime "^6.22.0"
|
||||
babel-template "^6.22.0"
|
||||
|
||||
babel-plugin-transform-es2015-modules-commonjs@^6.22.0:
|
||||
version "6.23.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-commonjs/-/babel-plugin-transform-es2015-modules-commonjs-6.23.0.tgz#cba7aa6379fb7ec99250e6d46de2973aaffa7b92"
|
||||
babel-plugin-transform-es2015-modules-commonjs@^6.24.0:
|
||||
version "6.24.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-commonjs/-/babel-plugin-transform-es2015-modules-commonjs-6.24.0.tgz#e921aefb72c2cc26cb03d107626156413222134f"
|
||||
dependencies:
|
||||
babel-plugin-transform-strict-mode "^6.22.0"
|
||||
babel-runtime "^6.22.0"
|
||||
|
@ -574,11 +581,11 @@ babel-plugin-transform-es2015-modules-systemjs@^6.22.0:
|
|||
babel-runtime "^6.22.0"
|
||||
babel-template "^6.23.0"
|
||||
|
||||
babel-plugin-transform-es2015-modules-umd@^6.22.0:
|
||||
version "6.23.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-umd/-/babel-plugin-transform-es2015-modules-umd-6.23.0.tgz#8d284ae2e19ed8fe21d2b1b26d6e7e0fcd94f0f1"
|
||||
babel-plugin-transform-es2015-modules-umd@^6.24.0:
|
||||
version "6.24.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-umd/-/babel-plugin-transform-es2015-modules-umd-6.24.0.tgz#fd5fa63521cae8d273927c3958afd7c067733450"
|
||||
dependencies:
|
||||
babel-plugin-transform-es2015-modules-amd "^6.22.0"
|
||||
babel-plugin-transform-es2015-modules-amd "^6.24.0"
|
||||
babel-runtime "^6.22.0"
|
||||
babel-template "^6.23.0"
|
||||
|
||||
|
@ -669,9 +676,9 @@ babel-plugin-transform-strict-mode@^6.22.0:
|
|||
babel-runtime "^6.22.0"
|
||||
babel-types "^6.22.0"
|
||||
|
||||
babel-preset-es2015@^6.22.0:
|
||||
version "6.22.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-preset-es2015/-/babel-preset-es2015-6.22.0.tgz#af5a98ecb35eb8af764ad8a5a05eb36dc4386835"
|
||||
babel-preset-es2015@^6.24.0:
|
||||
version "6.24.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-preset-es2015/-/babel-preset-es2015-6.24.0.tgz#c162d68b1932696e036cd3110dc1ccd303d2673a"
|
||||
dependencies:
|
||||
babel-plugin-check-es2015-constants "^6.22.0"
|
||||
babel-plugin-transform-es2015-arrow-functions "^6.22.0"
|
||||
|
@ -684,10 +691,10 @@ babel-preset-es2015@^6.22.0:
|
|||
babel-plugin-transform-es2015-for-of "^6.22.0"
|
||||
babel-plugin-transform-es2015-function-name "^6.22.0"
|
||||
babel-plugin-transform-es2015-literals "^6.22.0"
|
||||
babel-plugin-transform-es2015-modules-amd "^6.22.0"
|
||||
babel-plugin-transform-es2015-modules-commonjs "^6.22.0"
|
||||
babel-plugin-transform-es2015-modules-amd "^6.24.0"
|
||||
babel-plugin-transform-es2015-modules-commonjs "^6.24.0"
|
||||
babel-plugin-transform-es2015-modules-systemjs "^6.22.0"
|
||||
babel-plugin-transform-es2015-modules-umd "^6.22.0"
|
||||
babel-plugin-transform-es2015-modules-umd "^6.24.0"
|
||||
babel-plugin-transform-es2015-object-super "^6.22.0"
|
||||
babel-plugin-transform-es2015-parameters "^6.22.0"
|
||||
babel-plugin-transform-es2015-shorthand-properties "^6.22.0"
|
||||
|
@ -698,6 +705,27 @@ babel-preset-es2015@^6.22.0:
|
|||
babel-plugin-transform-es2015-unicode-regex "^6.22.0"
|
||||
babel-plugin-transform-regenerator "^6.22.0"
|
||||
|
||||
babel-preset-es2016@^6.22.0:
|
||||
version "6.22.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-preset-es2016/-/babel-preset-es2016-6.22.0.tgz#b061aaa3983d40c9fbacfa3743b5df37f336156c"
|
||||
dependencies:
|
||||
babel-plugin-transform-exponentiation-operator "^6.22.0"
|
||||
|
||||
babel-preset-es2017@^6.22.0:
|
||||
version "6.22.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-preset-es2017/-/babel-preset-es2017-6.22.0.tgz#de2f9da5a30c50d293fb54a0ba15d6ddc573f0f2"
|
||||
dependencies:
|
||||
babel-plugin-syntax-trailing-function-commas "^6.22.0"
|
||||
babel-plugin-transform-async-to-generator "^6.22.0"
|
||||
|
||||
babel-preset-latest@^6.24.0:
|
||||
version "6.24.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-preset-latest/-/babel-preset-latest-6.24.0.tgz#a68d20f509edcc5d7433a48dfaebf7e4f2cd4cb7"
|
||||
dependencies:
|
||||
babel-preset-es2015 "^6.24.0"
|
||||
babel-preset-es2016 "^6.22.0"
|
||||
babel-preset-es2017 "^6.22.0"
|
||||
|
||||
babel-preset-stage-2@^6.22.0:
|
||||
version "6.22.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-preset-stage-2/-/babel-preset-stage-2-6.22.0.tgz#ccd565f19c245cade394b21216df704a73b27c07"
|
||||
|
@ -2900,6 +2928,10 @@ lodash.deburr@^4.0.0:
|
|||
version "4.1.0"
|
||||
resolved "https://registry.yarnpkg.com/lodash.deburr/-/lodash.deburr-4.1.0.tgz#ddb1bbb3ef07458c0177ba07de14422cb033ff9b"
|
||||
|
||||
lodash.get@4.4.2:
|
||||
version "4.4.2"
|
||||
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
|
||||
|
||||
lodash.get@^3.7.0:
|
||||
version "3.7.0"
|
||||
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-3.7.0.tgz#3ce68ae2c91683b281cc5394128303cbf75e691f"
|
||||
|
@ -4271,6 +4303,10 @@ tough-cookie@~2.3.0:
|
|||
dependencies:
|
||||
punycode "^1.4.1"
|
||||
|
||||
traverse@0.6.6:
|
||||
version "0.6.6"
|
||||
resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.6.6.tgz#cbdf560fd7b9af632502fed40f918c157ea97137"
|
||||
|
||||
trim-right@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"
|
||||
|
|
Loading…
Reference in New Issue