From 5b740b1a1145f1f3c8bcc22666be5c39f6f070bd Mon Sep 17 00:00:00 2001 From: Kristian Tashkov Date: Mon, 18 Jan 2016 22:39:04 +0200 Subject: [PATCH] Fix setting of environment variables in gulp test tasks in Windows See this stackoverflow link for why this is necessary http://stackoverflow.com/questions/27084392/code-coverage-for-mocha-in-windows-7/27193866#27193866 --- package.json | 4 ++-- tasks/gulp-tests.js | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index f280469b6a..9e2dde0b21 100644 --- a/package.json +++ b/package.json @@ -87,14 +87,14 @@ "test": "gulp test", "test:api-v2:unit": "mocha test/server_side", "test:api-v2:integration": "mocha test/api/v2 --recursive", - "test:api-legacy": "istanbul cover -i \"website/src/**\" --dir coverage/api mocha test/api-legacy", + "test:api-legacy": "istanbul cover -i \"website/src/**\" --dir coverage/api ./node_modules/mocha/bin/_mocha test/api-legacy", "test:common": "mocha test/common", "test:content": "mocha test/content", "test:karma": "karma start --single-run", "test:karma:watch": "karma start", "test:prepare:webdriver": "webdriver-manager update", "test:e2e:webdriver": "webdriver-manager start", - "test:e2e": "DISPLAY=:99 NODE_ENV=testing protractor protractor.conf.js", + "test:e2e": "protractor protractor.conf.js", "test:nodemon": "gulp test:nodemon", "start": "gulp run:dev", "sprites": "gulp sprites:compile", diff --git a/tasks/gulp-tests.js b/tasks/gulp-tests.js index 097620ffb3..210cde7661 100644 --- a/tasks/gulp-tests.js +++ b/tasks/gulp-tests.js @@ -11,6 +11,7 @@ import psTree from 'ps-tree'; import gulp from 'gulp'; import Q from 'q'; import runSequence from 'run-sequence'; +import os from 'os'; const TEST_SERVER_PORT = 3003 const TEST_DB = 'habitrpg_test' @@ -34,8 +35,16 @@ let testCount = (stdout, regexp) => { return parseInt(match && match[1] || 0); } -let testBin = (string) => { - return `NODE_ENV=testing ${string}`; +let testBin = (string, additionalEnvVariables = '') => { + if(os.platform() === "win32") { + if(additionalEnvVariables != '') { + additionalEnvVariables = additionalEnvVariables.split(' ').join('&&set '); + additionalEnvVariables = 'set ' + additionalEnvVariables + '&&'; + } + return `set NODE_ENV=testing&&${additionalEnvVariables}${string}`; + } else { + return `NODE_ENV=testing ${additionalEnvVariables} ${string}`; + } }; gulp.task('test:nodemon', (done) => { @@ -56,7 +65,7 @@ gulp.task('test:prepare:mongo', (cb) => { gulp.task('test:prepare:server', ['test:prepare:mongo'], () => { if (!server) { - server = exec(`NODE_ENV="TESTING" NODE_DB_URI="${TEST_DB_URI}" PORT="${TEST_SERVER_PORT}" node ./website/src/server.js`, (error, stdout, stderr) => { + server = exec(testBin('node ./website/src/server.js', `NODE_DB_URI=${TEST_DB_URI} PORT=${TEST_SERVER_PORT} `), (error, stdout, stderr) => { if (error) { throw `Problem with the server: ${error}`; } if (stderr) { console.error(stderr); } }); @@ -249,7 +258,7 @@ gulp.task('test:karma:safe', ['test:prepare:build'], (cb) => { gulp.task('test:e2e', ['test:prepare', 'test:prepare:server'], (cb) => { let support = [ 'Xvfb :99 -screen 0 1024x768x24 -extension RANDR', - 'npm run test:e2e:webdriver', + testBin('npm run test:e2e:webdriver', 'DISPLAY=:99'), ].map(exec); support.push(server);