From 886ecc51df946206e8c7319331c7187d322944e7 Mon Sep 17 00:00:00 2001 From: popomore Date: Tue, 20 Jun 2017 23:33:46 +0800 Subject: [PATCH] fix: There is a case sensitive issue from spawn-wrap on Windows this PR will hotfix this code https://github.com/tapjs/spawn-wrap/pull/57 --- lib/cmd/cov.js | 27 +++++++++++++++++++++++++++ test/lib/cmd/cov.test.js | 1 + 2 files changed, 28 insertions(+) diff --git a/lib/cmd/cov.js b/lib/cmd/cov.js index d52be79a..8bbd6609 100644 --- a/lib/cmd/cov.js +++ b/lib/cmd/cov.js @@ -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'); @@ -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(); } /** @@ -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); + } +} diff --git a/test/lib/cmd/cov.test.js b/test/lib/cmd/cov.test.js index 4c5f58d1..0ab95084 100644 --- a/test/lib/cmd/cov.test.js +++ b/test/lib/cmd/cov.test.js @@ -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')));