From 9aa003023e4927c5b8ce4be87968eb13a8aebfc7 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 4 Jun 2017 01:28:50 +0800 Subject: [PATCH] fix: use context.env instead of process.env (#58) --- .gitignore | 3 +-- .travis.yml | 1 + appveyor.yml | 1 + lib/cmd/dev.js | 2 +- package.json | 24 +++++++++++-------- .../demo-app/node_modules/aliyun-egg/index.js | 1 + test/lib/cmd/debug.test.js | 10 ++++---- test/lib/cmd/dev.test.js | 23 +++++++++++++++--- 8 files changed, 45 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 50367bde..2621831c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ node_modules/ coverage/ !test/fixtures/custom-framework-app/node_modules/ -!test/fixtures/demo-app/node_modules/aliyun-egg -test/fixtures/demo-app/node_modules/aliyun-egg/node_modules/ +!test/fixtures/demo-app/node_modules/aliyun-egg/node_modules/ !test/fixtures/test-files-glob/** .tmp .vscode diff --git a/.travis.yml b/.travis.yml index 5e7a967b..1e455dc4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: node_js node_js: - '6' - '7' + - '8' install: - npm i npminstall && npminstall script: diff --git a/appveyor.yml b/appveyor.yml index ec7400e9..00663727 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,6 +2,7 @@ environment: matrix: - nodejs_version: '6' - nodejs_version: '7' + - nodejs_version: '8' install: - ps: Install-Product node $env:nodejs_version diff --git a/lib/cmd/dev.js b/lib/cmd/dev.js index e1ac45b5..ca8d586b 100644 --- a/lib/cmd/dev.js +++ b/lib/cmd/dev.js @@ -44,7 +44,7 @@ class DevCommand extends Command { const devArgs = yield this.formatArgs(context); const options = { execArgv: context.execArgv, - env: Object.assign({ NODE_ENV: 'development' }, process.env), + env: Object.assign({ NODE_ENV: 'development' }, context.env), }; debug('%s %j %j, %j', this.serverBin, devArgs, options.execArgv, options.env.NODE_ENV); yield this.helper.forkNode(this.serverBin, devArgs, options); diff --git a/package.json b/package.json index 1c6435e3..7e2d2077 100644 --- a/package.json +++ b/package.json @@ -10,14 +10,14 @@ "dependencies": { "change-case": "^3.0.1", "co-mocha": "^1.2.0", - "common-bin": "^2.3.0", - "debug": "^2.6.4", - "detect-port": "^1.1.1", - "egg-utils": "^2.1.0", + "common-bin": "^2.4.0", + "debug": "^2.6.8", + "detect-port": "^1.1.3", + "egg-utils": "^2.2.0", "globby": "^6.1.0", "intelli-espower-loader": "^1.0.1", "istanbul": "^1.1.0-alpha.1", - "mocha": "^3.3.0", + "mocha": "^3.4.2", "mz-modules": "^1.0.0", "power-assert": "^1.4.2", "ypkgfiles": "^1.4.0" @@ -27,12 +27,12 @@ "babel": "^6.3.26", "babel-preset-airbnb": "^1.0.1", "babel-register": "^6.4.3", - "coffee": "^3.3.0", + "coffee": "^3.3.2", "cross-env": "^3.1.3", - "egg-ci": "^1.6.0", + "egg-ci": "^1.7.0", "enzyme": "^2.0.0", "eslint": "^3.19.0", - "eslint-config-egg": "^3.2.0", + "eslint-config-egg": "^4.2.0", "jsdom": "^8.0.1", "mm": "^2.1.0", "mz": "^2.6.0", @@ -44,14 +44,18 @@ "type": "git", "url": "https://github.com/eggjs/egg-bin.git" }, + "bug": { + "url": "https://github.com/eggjs/egg/issues" + }, "homepage": "https://github.com/eggjs/egg-bin", "author": "fengmk2 (https://fengmk2.com)", "scripts": { "lint": "eslint .", + "pkgfiles": "node ./bin/egg-bin.js pkgfiles --check", "test": "npm run lint -- --fix && npm run test-local", "test-local": "node ./bin/egg-bin.js test -t 3600000", "cov": "node ./bin/egg-bin.js cov -t 3600000", - "ci": "npm run lint && npm run cov", + "ci": "npm run lint && npm run pkgfiles && npm run cov", "autod": "autod" }, "engines": { @@ -63,6 +67,6 @@ "bin" ], "ci": { - "version": "6, 7" + "version": "6, 7, 8" } } diff --git a/test/fixtures/demo-app/node_modules/aliyun-egg/index.js b/test/fixtures/demo-app/node_modules/aliyun-egg/index.js index 81de7666..77b977db 100644 --- a/test/fixtures/demo-app/node_modules/aliyun-egg/index.js +++ b/test/fixtures/demo-app/node_modules/aliyun-egg/index.js @@ -5,4 +5,5 @@ exports.startCluster = options => { if (process.execArgv.length) { console.log('process.execArgv:', process.execArgv); } + console.log('NODE_ENV: %s', process.env.NODE_ENV); }; diff --git a/test/lib/cmd/debug.test.js b/test/lib/cmd/debug.test.js index cf729e69..ae13e95e 100644 --- a/test/lib/cmd/debug.test.js +++ b/test/lib/cmd/debug.test.js @@ -11,13 +11,15 @@ describe('test/lib/cmd/debug.test.js', () => { afterEach(mm.restore); - it('should startCluster success', done => { - coffee.fork(eggBin, [ 'debug' ], { cwd }) + it('should startCluster success', () => { + return coffee.fork(eggBin, [ 'debug' ], { cwd }) + .debug() .expect('stderr', /Debugger listening/) - .expect('stderr', /chrome-devtools:/) + // node 8 missing "chrome-devtools" url + // .expect('stderr', /chrome-devtools:/) .expect('stdout', /"workers":1/) .expect('code', 0) - .end(done); + .end(); }); it('should startCluster with port', done => { diff --git a/test/lib/cmd/dev.test.js b/test/lib/cmd/dev.test.js index 65646742..fbe64ea5 100644 --- a/test/lib/cmd/dev.test.js +++ b/test/lib/cmd/dev.test.js @@ -3,19 +3,36 @@ const path = require('path'); const coffee = require('coffee'); const net = require('net'); +const mm = require('mm'); describe('test/lib/cmd/dev.test.js', () => { const eggBin = require.resolve('../../../bin/egg-bin.js'); const cwd = path.join(__dirname, '../../fixtures/demo-app'); - it('should startCluster success', done => { - coffee.fork(eggBin, [ 'dev' ], { cwd }) + afterEach(mm.restore); + + it('should startCluster success', () => { + mm(process.env, 'NODE_ENV', 'development'); + return coffee.fork(eggBin, [ 'dev' ], { cwd }) // .debug() .expect('stdout', /"workers":1/) .expect('stdout', /"baseDir":".*?demo-app"/) .expect('stdout', /"framework":".*?aliyun-egg"/) + .expect('stdout', /NODE_ENV: development/) .expect('code', 0) - .end(done); + .end(); + }); + + it('should dev start with custom NODE_ENV', () => { + mm(process.env, 'NODE_ENV', 'prod'); + return coffee.fork(eggBin, [ 'dev' ], { cwd }) + // .debug() + .expect('stdout', /"workers":1/) + .expect('stdout', /"baseDir":".*?demo-app"/) + .expect('stdout', /"framework":".*?aliyun-egg"/) + .expect('stdout', /NODE_ENV: prod/) + .expect('code', 0) + .end(); }); it('should startCluster with --harmony success', done => {