Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: There is a case sensitive issue from spawn-wrap on Windows #67

Merged
merged 3 commits into from
Jun 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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