Skip to content

Commit

Permalink
fix: only hotfix spawn-wrap on windows (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored and popomore committed Jul 5, 2017
1 parent c2eaa81 commit e784a3d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/cmd/cov.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class CovCommand extends Command {
env: Object.assign({ NODE_ENV: 'test' }, env),
};

// FIXME: remove hotfix after https://github.com/tapjs/spawn-wrap/pull/57 merged
yield hotfixSpawnWrap();

// save coverage-xxxx.json to $PWD/coverage
Expand Down Expand Up @@ -127,14 +128,17 @@ 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);
if (process.platform === 'win32') {
yield replaceSpawnWrap(src, target);
}
}

function* rollbackSpawnWrap() {
yield replaceSpawnWrap(target, src);
if (process.platform === 'win32') {
yield replaceSpawnWrap(target, src);
}
}


function* replaceSpawnWrap(src, target) {
let spawnWrapPath;
try {
Expand Down
32 changes: 31 additions & 1 deletion test/lib/cmd/cov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,38 @@ describe('test/lib/cmd/cov.test.js', () => {
child.expect('stdout', /Statements {3}: 80% \( 4[\/|\\]5 \)/);
}

if (process.platform === 'win32') {
child.expect('stderr', /\[egg-bin] hotfix spawn-wrap/);
}

child.expect('code', 0)
.end(err => {
assert.ifError(err);
assert.ok(fs.existsSync(path.join(cwd, 'coverage/coverage-final.json')));
assert.ok(fs.existsSync(path.join(cwd, 'coverage/coverage-summary.json')));
assert.ok(fs.existsSync(path.join(cwd, 'coverage/lcov-report/index.html')));
assert.ok(fs.existsSync(path.join(cwd, 'coverage/lcov.info')));
done();
});
});

it('should hotfixSpawnWrap success on mock windows', done => {
mm(process.env, 'TESTS', 'test/**/*.test.js');
mm(process.env, 'NYC_CWD', cwd);
const child = coffee.fork(eggBin, [ 'cov' ], { cwd })
.debug()
.beforeScript(path.join(__dirname, 'mock-win32.js'))
.expect('stdout', /should success/)
.expect('stdout', /a\.test\.js/)
.expect('stdout', /b[\/|\\]b\.test\.js/)
.notExpect('stdout', /a.js/);

// only test on npm run test
if (!process.env.NYC_ROOT_ID) {
child.expect('stdout', /Statements {3}: 80% \( 4[\/|\\]5 \)/);
}
child.expect('stderr', /\[egg-bin] hotfix spawn-wrap/);
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
4 changes: 4 additions & 0 deletions test/lib/cmd/mock-win32.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

const mm = require('mm');
mm(process, 'platform', 'win32');

0 comments on commit e784a3d

Please sign in to comment.