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
tags/v3.6.0
Samuel Attard 3 years ago
parent
commit
1b2055b286
No account linked to committer's email address
5 changed files with 35 additions and 1 deletions
  1. 1
    0
      .eslintignore
  2. 2
    0
      .gitignore
  3. 4
    1
      package.json
  4. 11
    0
      test/electron/util/coverage.js
  5. 17
    0
      test/istanbul-reporter.js

+ 1
- 0
.eslintignore View File

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

+ 2
- 0
.gitignore View File

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

+ 4
- 1
package.json View File

@@ -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
- 0
test/electron/util/coverage.js View File

@@ -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
- 0
test/istanbul-reporter.js View File

@@ -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