2019-01-30 22:47:03 +07:00
|
|
|
#!/usr/bin/env node
|
2019-01-27 21:54:29 +07:00
|
|
|
|
2019-01-30 22:47:03 +07:00
|
|
|
var program = require('commander');
|
|
|
|
var spawn = require('child_process').spawn;
|
2019-02-05 05:23:59 +07:00
|
|
|
var fs = require('fs');
|
|
|
|
var execSync = require('child_process').execSync;
|
2019-01-30 22:47:03 +07:00
|
|
|
|
|
|
|
program
|
2019-02-05 05:23:59 +07:00
|
|
|
.option('--headless', 'Run in headless mode.')
|
2019-01-30 22:47:03 +07:00
|
|
|
.parse(process.argv);
|
|
|
|
|
2019-02-05 05:23:59 +07: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 16:27:54 +07:00
|
|
|
execSync('./example/compose/nginx/portal/render.js --production');
|
2019-02-05 05:23:59 +07:00
|
|
|
// Prepare the environment
|
2019-02-22 16:27:54 +07:00
|
|
|
execSync('./scripts/utils/prepare-environment.sh');
|
2019-02-05 05:23:59 +07: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 22:47:03 +07:00
|
|
|
env: {
|
|
|
|
...process.env,
|
|
|
|
TS_NODE_PROJECT: 'test/tsconfig.json',
|
2019-02-05 05:23:59 +07:00
|
|
|
WITH_SERVER: (withServer) ? 'y' : 'n',
|
|
|
|
HEADLESS: (program.headless) ? 'y' : 'n',
|
2019-01-30 22:47:03 +07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mocha.stdout.on('data', (data) => {
|
|
|
|
process.stdout.write(`${data}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
mocha.stderr.on('data', (data) => {
|
|
|
|
process.stderr.write(`${data}`);
|
|
|
|
});
|
2019-02-24 20:05:11 +07:00
|
|
|
|
|
|
|
mocha.on('exit', function(statusCode) {
|
|
|
|
if (statusCode != 0) {
|
|
|
|
console.error("The tests failed... Mocha exited with status code " + statusCode);
|
2019-02-24 22:42:29 +07:00
|
|
|
fs.readFile('/tmp/authelia-server.log', function(err, data) {
|
|
|
|
if (err) {
|
|
|
|
console.error(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log(data.toString('utf-8'));
|
|
|
|
});
|
2019-02-24 20:05:11 +07:00
|
|
|
}
|
|
|
|
process.exit(statusCode);
|
|
|
|
})
|