2019-01-30 15:47:03 +00:00
|
|
|
|
|
|
|
import ChildProcess from 'child_process';
|
|
|
|
|
2019-02-24 13:01:17 +00:00
|
|
|
export default function WithAutheliaRunning(configPath: string, waitTimeout: number = 5000) {
|
2019-01-30 15:47:03 +00:00
|
|
|
before(function() {
|
2019-02-24 13:01:17 +00:00
|
|
|
this.timeout(10000);
|
2019-02-23 22:02:03 +00:00
|
|
|
|
|
|
|
console.log('Spawning Authelia server with configuration %s.', configPath);
|
2019-01-30 15:47:03 +00:00
|
|
|
const authelia = ChildProcess.spawn(
|
|
|
|
'./scripts/authelia-scripts',
|
2019-01-30 21:44:03 +00:00
|
|
|
['serve', '--no-watch', '--config', configPath],
|
2019-01-30 15:47:03 +00:00
|
|
|
{detached: true});
|
2019-02-04 22:23:59 +00:00
|
|
|
|
2019-02-23 22:27:34 +00:00
|
|
|
authelia.on('exit', function(status) {
|
|
|
|
console.log('Server terminated with status ' + status);
|
2019-02-04 22:23:59 +00:00
|
|
|
});
|
2019-01-30 15:47:03 +00:00
|
|
|
this.authelia = authelia;
|
|
|
|
|
|
|
|
const waitPromise = new Promise((resolve, reject) => setTimeout(() => resolve(), waitTimeout));
|
|
|
|
return waitPromise;
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function() {
|
2019-02-24 13:01:17 +00:00
|
|
|
this.timeout(10000);
|
2019-01-30 15:47:03 +00:00
|
|
|
|
2019-02-23 22:02:03 +00:00
|
|
|
console.log('Killing Authelia server.');
|
2019-01-30 15:47:03 +00:00
|
|
|
// Kill the group of processes.
|
|
|
|
process.kill(-this.authelia.pid);
|
2019-02-24 13:01:17 +00:00
|
|
|
|
|
|
|
// Leave 5 seconds for the process to terminate.
|
|
|
|
const waitPromise = new Promise((resolve, reject) => setTimeout(() => resolve(), 5000));
|
|
|
|
return waitPromise;
|
2019-01-30 15:47:03 +00:00
|
|
|
});
|
|
|
|
}
|