Skip to content

Commit

Permalink
fix: There is a case sensitive issue from spawn-wrap on Windows
Browse files Browse the repository at this point in the history
this PR will hotfix this code

istanbuljs/spawn-wrap#57
  • Loading branch information
popomore committed Jun 20, 2017
1 parent 94f61fa commit 886ecc5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/cmd/cov.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const debug = require('debug')('egg-bin:cov');
const path = require('path');
const rimraf = require('mz-modules/rimraf');
const testExclude = require('test-exclude');
const fs = require('mz/fs');

const Command = require('./test');
const EXCLUDES = Symbol('cov#excludes');
Expand Down Expand Up @@ -71,10 +72,14 @@ class CovCommand extends Command {
env: Object.assign({ NODE_ENV: 'test' }, env),
};

yield hotfixSpawnWrap();

// save coverage-xxxx.json to $PWD/coverage
const covArgs = this.getCovArgs(context);
debug('covArgs: %j', covArgs);
yield this.helper.forkNode(nycCli, covArgs, opt);

yield rollbackSpawnWrap();
}

/**
Expand Down Expand Up @@ -119,3 +124,25 @@ class CovCommand extends Command {
}

module.exports = CovCommand;

const src = 'var command = path.basename(options.file, \'.exe\')';
const target = 'var command = path.basename(options.file).replace(/\.exe$/i, \'\')';

function* hotfixSpawnWrap() {
yield replaceSpawnWrap(src, target);
}

function* rollbackSpawnWrap() {
yield replaceSpawnWrap(target, src);
}

function* replaceSpawnWrap(src, target) {
const filepath = path.join(__dirname, '../../node_modules/nyc/node_modules/spawn-wrap/index.js');
let content = yield fs.readFile(filepath, 'utf8');
// https://github.com/tapjs/spawn-wrap/pull/57
if (content.includes(src)) {
content = content.replace(src, target);
console.warn('[egg-bin] hotfix spawn-wrap');
yield fs.writeFile(filepath, content);
}
}
1 change: 1 addition & 0 deletions test/lib/cmd/cov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('test/lib/cmd/cov.test.js', () => {
}

child.expect('code', 0)
.expect('stderr', /\[egg-bin] hotfix spawn-wrap/)
.end(err => {
assert.ifError(err);
assert.ok(fs.existsSync(path.join(cwd, 'coverage/coverage-final.json')));
Expand Down

0 comments on commit 886ecc5

Please sign in to comment.