Skip to content

Commit

Permalink
fix: Handle environment variables in start script
Browse files Browse the repository at this point in the history
  • Loading branch information
shinout committed May 13, 2016
1 parent 89d5197 commit 2a9d8c5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/hello-world/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "testium-core.hello-world",
"scripts": {
"start": "node server.js Quinn"
"start": "DEBUG=* NODE_ENV=development node server.js Quinn"
}
}
18 changes: 13 additions & 5 deletions lib/processes/application/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,24 @@ function getAppOptions(config) {

var commandArgs = options.command.split(/[\s]+/g);

var env = {
NODE_ENV: config.get('launchEnv', 'test'),
PORT: options.port,
PATH: './node_modules/.bin:' + process.env.PATH,
};

while (commandArgs.length && commandArgs[0].match('=')) {
var arg = commandArgs.shift();
var envPair = arg.split('=');
env[envPair[0]] = envPair[1];
}

return _.extend(options, {
command: commandArgs.shift(),
commandArgs: commandArgs,
verifyTimeout: config.get('app.timeout', 30000),
spawnOpts: {
env: _.defaults({
NODE_ENV: config.get('launchEnv', 'test'),
PORT: options.port,
PATH: './node_modules/.bin:' + process.env.PATH,
}, process.env),
env: _.defaults(env, process.env),
cwd: config.get('root'),
},
});
Expand Down
2 changes: 2 additions & 0 deletions test/processes/application.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ describe('App', () => {
const options = await App.getOptions(config);
assert.hasType('Finds an open port', Number, options.port);
assert.equal('Parses command from scripts.start', 'node', options.command);
assert.equal('Parses environment variables in scripts.start', '*', options.spawnOpts.env.DEBUG);
assert.equal('Overrides NODE_ENV when set in scripts.start', 'development', options.spawnOpts.env.NODE_ENV);
assert.deepEqual('Parses commandArgs from scripts.start',
['server.js', 'Quinn'], options.commandArgs);
});
Expand Down

0 comments on commit 2a9d8c5

Please sign in to comment.