Browse Source

Implement Instanbul test coverage for the electron-mocha tests

* Custom mocha reporter to pass results to Istanbul
* Istanbul reporter generates text and HTML reports
pull/1562/head
Samuel Attard 5 years ago
parent
commit
1b2055b286
No known key found for this signature in database GPG Key ID: 273DC1869D8F13EF
  1. 1
      .eslintignore
  2. 2
      .gitignore
  3. 5
      package.json
  4. 11
      test/electron/util/coverage.js
  5. 17
      test/istanbul-reporter.js

1
.eslintignore

@ -1,2 +1,3 @@
build/
node_modules/
cov/

2
.gitignore

@ -1,6 +1,8 @@
node_modules/
build/
dist/
cov/
coverage/
.settings.json
xunit.xml
vendor/*.msi

5
package.json

@ -26,8 +26,10 @@
"postinstall": "node vendor/rebuild.js --instant",
"test": "npm run lint",
"pretest-electron": "npm run build",
"pretest-electron-coverage": "istanbul instrument src --output cov --no-compact --complete-copy --es-modules",
"pretest-spectron": "npm run build",
"test-electron": "electron-mocha ./test/electron --recursive --compilers js:babel-core/register --timeout 10000 -R spec-xunit-file",
"test-electron": "electron-mocha ./test/electron/**/*_spec.js --recursive --compilers js:babel-core/register --timeout 10000 -R spec-xunit-file",
"test-electron-coverage": "npm run test-electron -- -r test/electron/util/coverage.js -R test/istanbul-reporter",
"test-spectron": "mocha ./test/spectron --compilers js:babel-core/register -R spec-xunit-file --timeout 10000",
"prestart": "pre-flight && node vendor/mac_patch_dev.js",
"start": "electron . --dev",
@ -94,6 +96,7 @@
"gulp-less": "^3.1.0",
"gulp-replace": "^0.5.4",
"gulp-uglify": "^2.0.0",
"istanbul": "^1.1.0-alpha.1",
"jquery": "^2.2.3",
"material-design-icons-iconfont": "^2.0.5",
"materialize-css": "^0.97.6",

11
test/electron/util/coverage.js

@ -0,0 +1,11 @@
import Module from 'module';
const originalRequire = Module.prototype.require;
Module.prototype.require = function fancyCoverageRequireHack(moduleName, ...args) {
try {
return originalRequire.call(this, moduleName.replace('build/', 'cov/'), ...args);
} catch (e) {
return originalRequire.call(this, moduleName, ...args);
}
};

17
test/istanbul-reporter.js

@ -0,0 +1,17 @@
const istanbulAPI = require('istanbul-api');
const libCoverage = require('istanbul-lib-coverage');
function Istanbul(runner) {
runner.on('end', () => {
const mainReporter = istanbulAPI.createReporter();
const coverageMap = libCoverage.createCoverageMap();
coverageMap.merge(global.__coverage__ || {});
mainReporter.addAll(['text', 'html']);
mainReporter.write(coverageMap, {});
});
}
module.exports = Istanbul;
Loading…
Cancel
Save