authelia/test/helpers/utils/exec.ts
Clement Michaud 76fa325f08 [BREAKING] Create a suite for kubernetes tests.
Authelia client uses hash router instead of browser router in order to work
with Kubernetes nginx-ingress-controller. This is also better for users having
old browsers.

This commit is breaking because it requires to change the configuration of the
proxy to include the # in the URL of the login portal.
2019-03-16 00:13:27 +01:00

42 lines
947 B
TypeScript

var spawn = require('child_process').spawn;
interface Options {
cwd?: string;
env?: {[key: string]: string};
debug?: boolean;
}
export function exec(command: string, options?: Options): Promise<void> {
return new Promise((resolve, reject) => {
const spawnOptions = {
shell: true,
} as any;
if (options && options.cwd) {
spawnOptions['cwd'] = options.cwd;
}
if (options && options.env) {
spawnOptions['env'] = {
...options.env,
...process.env,
}
}
if (options && options.debug) {
console.log('>>> ' + command);
}
const cmd = spawn(command, spawnOptions);
cmd.stdout.pipe(process.stdout);
cmd.stderr.pipe(process.stderr);
cmd.on('exit', (statusCode: number) => {
if (statusCode == 0) {
resolve();
return;
}
reject(new Error('\'' + command + '\' exited with status code ' + statusCode));
});
});
}