authelia/test/helpers/context/WithAutheliaRunning.ts

30 lines
876 B
TypeScript
Raw Normal View History

import ChildProcess from 'child_process';
export default function WithAutheliaRunning(configPath: string, waitTimeout: number = 3000) {
before(function() {
this.timeout(5000);
2019-02-24 05:02:03 +07:00
console.log('Spawning Authelia server with configuration %s.', configPath);
const authelia = ChildProcess.spawn(
'./scripts/authelia-scripts',
['serve', '--no-watch', '--config', configPath],
{detached: true});
authelia.on('exit', function(status) {
console.log('Server terminated with status ' + status);
});
this.authelia = authelia;
const waitPromise = new Promise((resolve, reject) => setTimeout(() => resolve(), waitTimeout));
return waitPromise;
});
after(function() {
this.timeout(1000);
2019-02-24 05:02:03 +07:00
console.log('Killing Authelia server.');
// Kill the group of processes.
process.kill(-this.authelia.pid);
});
}