Skip to content

Commit

Permalink
test: add code coverage to spawned gyp jobs
Browse files Browse the repository at this point in the history
Fixes: #28
  • Loading branch information
bruce-one authored and indutny committed Nov 25, 2016
1 parent f91cf6b commit 7885e7f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SRC_FILES+= test/**/*.js
SRC_FILES+= test/**/**/*.js

BINDIR=./node_modules/.bin
COVERAGEDIR=./coverage

lint:
@$(BINDIR)/eslint $(SRC_FILES)
Expand All @@ -21,7 +22,10 @@ check:
@$(BINDIR)/mocha --reporter=spec test/*-test.js

coverage:
@$(BINDIR)/istanbul cover --html $(BINDIR)/_mocha -- -u exports -R spec test/*-test.js
@-rm -rf $(COVERAGEDIR)
@$(BINDIR)/istanbul cover --report none --print none --include-pid \
$(BINDIR)/_mocha -- -u exports -R spec test/*-test.js
@$(BINDIR)/istanbul report text-summary lcov

test: check

Expand Down
15 changes: 12 additions & 3 deletions test/gyppies-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ const rimraf = require('rimraf');
const ninja = require('ninja.js');
const spawnSync = require('child_process').spawnSync;

const gyp = path.join(__dirname, '..', 'bin', 'gyp');
const rootDir = path.join(__dirname, '..');
const gyp = path.join(rootDir, 'bin', 'gyp');
const istanbul = path.join(rootDir, 'node_modules', '.bin', 'istanbul');
const istanbulCoverageDir = path.join(rootDir, 'coverage');
const istanbulArgs = [ istanbul, 'cover', '--root', rootDir, '--dir',
istanbulCoverageDir, '--report', 'none', '--print',
'none', '--include-pid' ];
const gyppiesDir = path.join(__dirname, 'gyppies');
const tests = fs.readdirSync(gyppiesDir);

Expand All @@ -24,9 +30,12 @@ function build(name) {
const spawnOpts = { stdio: stdio, cwd: folder };

const argvFile = path.join(folder, 'argv.json');
const argv = fs.existsSync(argvFile) ? require(argvFile) : [];
let argv = fs.existsSync(argvFile) ? require(argvFile) : [];
argv = [ gyp ].concat(argv);
if (process.env.running_under_istanbul)
argv = istanbulArgs.concat(argv);

let p = spawnSync(process.execPath, [ gyp ].concat(argv), spawnOpts);
let p = spawnSync(process.execPath, argv, spawnOpts);
if (p.status !== 0 && p.stdout)
console.error(p.stdout.toString());
if (p.error)
Expand Down

0 comments on commit 7885e7f

Please sign in to comment.