2019-03-02 15:19:08 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
var program = require('commander');
|
|
|
|
var spawn = require('child_process').spawn;
|
|
|
|
var fs = require('fs');
|
2019-03-02 21:09:51 +00:00
|
|
|
var ListSuites = require('./utils/ListSuites');
|
2019-03-02 15:19:08 +00:00
|
|
|
|
|
|
|
let suite;
|
|
|
|
|
|
|
|
program
|
|
|
|
.description(`Start the suite provided as argument. You can list the suites with the 'list' command.`)
|
|
|
|
.arguments('<suite>')
|
|
|
|
.action((suiteArg) => suite = suiteArg)
|
|
|
|
.parse(process.argv)
|
|
|
|
|
|
|
|
if (!suite) {
|
|
|
|
program.help();
|
|
|
|
}
|
|
|
|
|
2019-03-02 21:09:51 +00:00
|
|
|
if (ListSuites().indexOf(suite) == -1) {
|
|
|
|
console.log("[WARNING] This suite does not exist. Use 'list' command to check the existing suites.");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2019-03-02 15:19:08 +00:00
|
|
|
const ENVIRONMENT_FILENAME = '.suite';
|
|
|
|
|
|
|
|
let runEnvProcess;
|
|
|
|
|
|
|
|
// Sometime SIGINT is received twice, we make sure with this variable that we cleanup
|
|
|
|
// only once.
|
|
|
|
var alreadyCleaningUp = false;
|
|
|
|
|
|
|
|
// Properly cleanup server and client if ctrl-c is hit
|
|
|
|
process.on('SIGINT', function() {
|
|
|
|
if (alreadyCleaningUp) return;
|
|
|
|
alreadyCleaningUp = true;
|
|
|
|
console.log('Cleanup procedure is running...');
|
|
|
|
});
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
fs.writeFileSync(ENVIRONMENT_FILENAME, suite);
|
|
|
|
|
|
|
|
// Start the environment from ts-node process.
|
|
|
|
runEnvProcess = spawn('./node_modules/.bin/ts-node -P test/tsconfig.json -- ./scripts/run-environment.ts ' + suite, {
|
2019-04-24 21:52:08 +00:00
|
|
|
shell: true,
|
|
|
|
env: {
|
|
|
|
...process.env,
|
|
|
|
ENVIRONMENT: 'dev',
|
|
|
|
}
|
2019-03-02 15:19:08 +00:00
|
|
|
});
|
|
|
|
runEnvProcess.stdout.pipe(process.stdout);
|
|
|
|
runEnvProcess.stderr.pipe(process.stderr);
|
|
|
|
|
|
|
|
runEnvProcess.on('exit', function(statusCode) {
|
|
|
|
fs.unlinkSync(ENVIRONMENT_FILENAME);
|
|
|
|
process.exit(statusCode);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-03 22:51:52 +00:00
|
|
|
main()
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1)
|
|
|
|
});
|