Skip to content

Commit

Permalink
Collect & report test coverage for our browser code (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphinesse authored Jul 22, 2019
1 parent a6413dd commit 74fdba8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ module.exports = function (config) {
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
reporters: ['progress', 'coverage'],

coverageReporter: {
type: 'text'
},

// web server port
port: 9876,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"jasmine-core": "^3.3.0",
"karma": "^4.0.1",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.2",
"karma-jasmine": "^2.0.1",
"puppeteer": "^1.14.0"
}
Expand Down
14 changes: 13 additions & 1 deletion test/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const fs = require('fs-extra');
const path = require('path');
const { build, collectModules } = require('../build-tools');

// Istanbul is provided by karma-coverage
const { Instrumenter } = require('istanbul');

if (require.main === module) {
buildCordovaJsTestBundle(process.argv[2])
.catch(err => {
Expand All @@ -16,10 +19,19 @@ module.exports = buildCordovaJsTestBundle;

// Writes the cordova-js test build bundle to bundlePath
function buildCordovaJsTestBundle (bundlePath) {
const instrumenter = new Instrumenter();

return build({
platformName: 'test',
platformVersion: 'N/A',
extraModules: collectTestBuildModules()
extraModules: collectTestBuildModules(),
preprocess (f) {
// Do not instrument our test dummies
if (f.path.includes('src/legacy-exec/test/')) return f;

const contents = instrumenter.instrumentSync(f.contents, f.path);
return Object.assign({}, f, { contents });
}
})
.then(testBundle => fs.outputFile(bundlePath, testBundle));
}
Expand Down

0 comments on commit 74fdba8

Please sign in to comment.