2019-01-30 15:47:03 +00:00
|
|
|
#!/usr/bin/env node
|
2019-01-27 14:54:29 +00:00
|
|
|
|
2019-01-30 15:47:03 +00:00
|
|
|
var program = require('commander');
|
|
|
|
var spawn = require('child_process').spawn;
|
2019-02-04 22:23:59 +00:00
|
|
|
var fs = require('fs');
|
|
|
|
var execSync = require('child_process').execSync;
|
2019-01-30 15:47:03 +00:00
|
|
|
|
|
|
|
program
|
2019-02-04 22:23:59 +00:00
|
|
|
.option('--headless', 'Run in headless mode.')
|
2019-01-30 15:47:03 +00:00
|
|
|
.parse(process.argv);
|
|
|
|
|
2019-02-04 22:23:59 +00:00
|
|
|
let suite;
|
|
|
|
let withServer = false;
|
|
|
|
let args = [];
|
|
|
|
const ENVIRONMENT_FILENAME = '.suite';
|
|
|
|
|
|
|
|
if (fs.existsSync(ENVIRONMENT_FILENAME)) {
|
|
|
|
const suite = fs.readFileSync(ENVIRONMENT_FILENAME);
|
|
|
|
console.log('Suite %s detected (dev env running). Running test related to this suite.', suite);
|
|
|
|
args.push('test/suites/' + suite + '/*.ts');
|
|
|
|
}
|
|
|
|
else if (program.args.length > 0) {
|
|
|
|
console.log('No suite detected. Running selected tests against built server.');
|
|
|
|
withServer = true;
|
|
|
|
args = program.args;
|
|
|
|
|
|
|
|
// Render the production version of the nginx portal configuration
|
2019-02-22 09:27:54 +00:00
|
|
|
execSync('./example/compose/nginx/portal/render.js --production');
|
2019-02-04 22:23:59 +00:00
|
|
|
// Prepare the environment
|
2019-02-22 09:27:54 +00:00
|
|
|
execSync('./scripts/utils/prepare-environment.sh');
|
2019-02-04 22:23:59 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log('No suite detected but no tests have been selected...');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
mocha = spawn('./node_modules/.bin/mocha', ['--exit', '--colors', '--require', 'ts-node/register', ...args], {
|
2019-01-30 15:47:03 +00:00
|
|
|
env: {
|
|
|
|
...process.env,
|
|
|
|
TS_NODE_PROJECT: 'test/tsconfig.json',
|
2019-02-04 22:23:59 +00:00
|
|
|
WITH_SERVER: (withServer) ? 'y' : 'n',
|
|
|
|
HEADLESS: (program.headless) ? 'y' : 'n',
|
2019-01-30 15:47:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mocha.stdout.on('data', (data) => {
|
|
|
|
process.stdout.write(`${data}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
mocha.stderr.on('data', (data) => {
|
|
|
|
process.stderr.write(`${data}`);
|
|
|
|
});
|
2019-02-24 13:05:11 +00:00
|
|
|
|
|
|
|
mocha.on('exit', function(statusCode) {
|
|
|
|
if (statusCode != 0) {
|
|
|
|
console.error("The tests failed... Mocha exited with status code " + statusCode);
|
|
|
|
}
|
|
|
|
process.exit(statusCode);
|
|
|
|
})
|