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
This commit is contained in:
Kristian Tashkov
2016-01-18 22:39:04 +02:00
committed by Blade Barringer
parent fc8c377eab
commit 5b740b1a11
2 changed files with 15 additions and 6 deletions

View File

@@ -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",

View File

@@ -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);