Skip to content

Commit

Permalink
chore: fix coverage in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aadityataparia committed Jun 3, 2019
1 parent be80009 commit 6e035a3
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
5 changes: 3 additions & 2 deletions dist/sifrr.dev.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/sifrr.dev.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions dist/sifrr.dev.module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/sifrr.dev.module.js.map

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions scripts/test/run.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
const path = require('path');

// check if should inspect or not
const inspect = process.argv.indexOf('-i') > 0 || process.argv.indexOf('--inspect') > 0;

// Check if need coverage
const coverage = process.env.COVERAGE === 'true';

// coverage for require
if (coverage) {
const { createInstrumenter } = require('istanbul-lib-instrument');
const instrumenter = createInstrumenter();
const { hookRequire } = require('istanbul-lib-hook');
hookRequire((filePath) => filePath.match(/\/src/), (code, { filename }) => instrumenter.instrumentSync(code, filename));
global.cov = true;
}

// check if should inspect or not
const inspect = process.argv.indexOf('-i') > 0 || process.argv.indexOf('--inspect') > 0;

// check if need junit reporter
const useJunitReporter = process.argv.indexOf('-j') > 0 || process.argv.indexOf('--junit') > 0;

Expand Down
2 changes: 2 additions & 0 deletions src/test/loadbrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = async function(root, coverage) {

function setPageGoto(page) {
page.goto = async (url, options) => {
/* istanbul ignore next */
const jsCoverage = await page.evaluate(() => window.__coverage__);
writeCoverage(jsCoverage, path.join(nycReport, `./${Date.now()}-browser-coverage.json`));
const ret = page.mainFrame().goto(url, options);
Expand All @@ -39,6 +40,7 @@ module.exports = async function(root, coverage) {

browser.__close = browser.close;
browser.close = async () => {
/* istanbul ignore next */
const jsCoverage = await page.evaluate(() => window.__coverage__);
writeCoverage(jsCoverage, path.join(nycReport, `./${Date.now()}-browser-coverage.json`));
return browser.__close();
Expand Down
5 changes: 3 additions & 2 deletions src/test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ module.exports = async function({
}
if (setGlobals) testGlobals();

if (coverage) {
if (coverage && !global.cov) {
const { createInstrumenter } = require('istanbul-lib-instrument');
const instrumenter = createInstrumenter();
const { hookRequire } = require('istanbul-lib-hook');
hookRequire((filePath) => filePath.match(/\/src/), (code, { filename }) => instrumenter.instrumentSync(code, filename));
hookRequire((filePath) => filePath.indexOf(root + 'src') > -1, (code, { filename }) => instrumenter.instrumentSync(code, filename));
global.cov = true;
}

const mochaOptions = {
Expand Down

0 comments on commit 6e035a3

Please sign in to comment.