summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitlab-ci.yml4
-rw-r--r--changelogs/unreleased/cover-my-karma.yml4
-rw-r--r--config/karma.config.js7
-rw-r--r--config/webpack.config.js1
-rw-r--r--package.json10
-rw-r--r--spec/javascripts/test_bundle.js35
6 files changed, 59 insertions, 2 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7d0c976d816..b8619d7d3f8 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -254,7 +254,7 @@ karma:
name: coverage-javascript
expire_in: 31d
paths:
- - coverage-javascript/default/
+ - coverage-javascript/
lint-doc:
stage: test
@@ -393,7 +393,7 @@ pages:
- mv public/ .public/
- mkdir public/
- mv coverage/ public/coverage-ruby/ || true
- - mv coverage-javascript/default/ public/coverage-javascript/ || true
+ - mv coverage-javascript/ public/coverage-javascript/ || true
- mv eslint-report.html public/ || true
artifacts:
paths:
diff --git a/changelogs/unreleased/cover-my-karma.yml b/changelogs/unreleased/cover-my-karma.yml
new file mode 100644
index 00000000000..4a823dc5ca4
--- /dev/null
+++ b/changelogs/unreleased/cover-my-karma.yml
@@ -0,0 +1,4 @@
+---
+title: Reintroduce coverage report for JavaScript
+merge_request: 9133
+author: winniehell
diff --git a/config/karma.config.js b/config/karma.config.js
index 44229e2ee88..a1fbeab1f46 100644
--- a/config/karma.config.js
+++ b/config/karma.config.js
@@ -15,6 +15,13 @@ module.exports = function(config) {
preprocessors: {
'spec/javascripts/**/*.js?(.es6)': ['webpack', 'sourcemap'],
},
+ reporters: ['progress', 'coverage-istanbul'],
+ coverageIstanbulReporter: {
+ reports: ['html', 'text-summary'],
+ dir: 'coverage-javascript/',
+ subdir: '.',
+ fixWebpackSourcePaths: true
+ },
webpack: webpackConfig,
webpackMiddleware: { stats: 'errors-only' },
});
diff --git a/config/webpack.config.js b/config/webpack.config.js
index 2ac779c8511..5d5e4bb570a 100644
--- a/config/webpack.config.js
+++ b/config/webpack.config.js
@@ -54,6 +54,7 @@ var config = {
exclude: /(node_modules|vendor\/assets)/,
loader: 'babel-loader',
options: {
+ plugins: ['istanbul'],
presets: [
["es2015", {"modules": false}],
'stage-2'
diff --git a/package.json b/package.json
index 48f571eda9b..0500ba9670e 100644
--- a/package.json
+++ b/package.json
@@ -37,6 +37,7 @@
"webpack-dev-server": "^2.3.0"
},
"devDependencies": {
+ "babel-plugin-istanbul": "^4.0.0",
"eslint": "^3.10.1",
"eslint-config-airbnb-base": "^10.0.1",
"eslint-import-resolver-webpack": "^0.8.1",
@@ -47,9 +48,18 @@
"jasmine-core": "^2.5.2",
"jasmine-jquery": "^2.1.1",
"karma": "^1.4.1",
+ "karma-coverage-istanbul-reporter": "^0.2.0",
"karma-jasmine": "^1.1.0",
"karma-phantomjs-launcher": "^1.0.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.2"
+ },
+ "nyc": {
+ "exclude": [
+ "spec/javascripts/test_bundle.js",
+ "spec/javascripts/**/*_spec.js",
+ "spec/javascripts/**/*_spec.js.es6",
+ "app/assets/javascripts/droplab/**/*"
+ ]
}
}
diff --git a/spec/javascripts/test_bundle.js b/spec/javascripts/test_bundle.js
index 030d2de090a..ca707d872a4 100644
--- a/spec/javascripts/test_bundle.js
+++ b/spec/javascripts/test_bundle.js
@@ -42,3 +42,38 @@ 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
+ const troubleMakers = [
+ './blob_edit/blob_edit_bundle.js',
+ './cycle_analytics/components/stage_plan_component.js',
+ './cycle_analytics/components/stage_staging_component.js',
+ './cycle_analytics/components/stage_test_component.js',
+ './diff_notes/components/jump_to_discussion.js',
+ './diff_notes/components/resolve_count.js',
+ './merge_conflicts/components/inline_conflict_lines.js',
+ './merge_conflicts/components/parallel_conflict_lines.js',
+ './network/branch_graph.js',
+ ];
+
+ const sourceFiles = require.context('~', true, /^\.\/(?!application\.js).*\.(js|es6)$/);
+ sourceFiles.keys().forEach(function (path) {
+ // ignore if there is a matching spec file
+ if (testsContext.keys().indexOf(`${path.replace(/\.js(\.es6)?$/, '')}_spec`) > -1) {
+ return;
+ }
+
+ it(`includes '${path}'`, function () {
+ try {
+ sourceFiles(path);
+ } catch (err) {
+ if (troubleMakers.indexOf(path) === -1) {
+ expect(err).toBeNull();
+ }
+ }
+ });
+ });
+});