From 56f85189e13220207a6afededd77b5a122789421 Mon Sep 17 00:00:00 2001 From: Haoliang Gao Date: Wed, 21 Jun 2017 01:08:58 +0800 Subject: [PATCH] fix: There is a case sensitive issue from spawn-wrap on Windows (#67) this PR will hotfix this code https://github.com/tapjs/spawn-wrap/pull/57 --- lib/cmd/cov.js | 35 +++++++++++++++++++++++++++++++++++ package.json | 5 +++-- test/lib/cmd/cov.test.js | 1 + 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/cmd/cov.js b/lib/cmd/cov.js index d52be79a..e8c96b4a 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,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); + } +} diff --git a/package.json b/package.json index 93f5c490..cd51a972 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", 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')));