Skip to content

Commit

Permalink
fix: There is a case sensitive issue from spawn-wrap on Windows (#67)
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 authored Jun 20, 2017
1 parent 94f61fa commit 56f8518
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
35 changes: 35 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,33 @@ 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) {
let spawnWrapPath;
try {
spawnWrapPath = require.resolve('spawn-wrap/index.js');
} catch (_) {
spawnWrapPath = path.join(__dirname, '../../node_modules/nyc/node_modules/spawn-wrap/index.js');
}
if (!(yield fs.exists(spawnWrapPath))) return;

let content = yield fs.readFile(spawnWrapPath, '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(spawnWrapPath, content);
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"globby": "^6.1.0",
"intelli-espower-loader": "^1.0.1",
"mocha": "^3.4.2",
"mz": "^2.6.0",
"mz-modules": "^1.0.0",
"nyc": "^11.0.2",
"power-assert": "^1.4.4",
Expand All @@ -28,9 +29,9 @@
"babel": "^6.3.26",
"babel-preset-airbnb": "^1.0.1",
"babel-register": "^6.4.3",
"coffee": "^4.0.0",
"coffee": "^4.0.1",
"cross-env": "^3.1.3",
"egg-ci": "^1.7.0",
"egg-ci": "^1.8.0",
"enzyme": "^2.0.0",
"eslint": "^3.0.0",
"eslint-config-egg": "^4.2.1",
Expand Down
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 56f8518

Please sign in to comment.