mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[jest] try running unit tests in parallel (#130823)
This commit is contained in:
parent
47918ae0be
commit
fa7323769d
5 changed files with 28 additions and 8 deletions
|
@ -72,6 +72,7 @@ const defaultOptions: Options = {
|
|||
processExit$,
|
||||
sigint$,
|
||||
sigterm$,
|
||||
forceColor: true,
|
||||
};
|
||||
|
||||
expect.addSnapshotSerializer(extendedEnvSerializer);
|
||||
|
@ -80,7 +81,6 @@ beforeEach(() => {
|
|||
jest.clearAllMocks();
|
||||
log.messages.length = 0;
|
||||
process.execArgv = ['--inheritted', '--exec', '--argv'];
|
||||
process.env.FORCE_COLOR = process.env.FORCE_COLOR || '1';
|
||||
currentProc = undefined;
|
||||
});
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ export interface Options {
|
|||
sigint$?: Rx.Observable<void>;
|
||||
sigterm$?: Rx.Observable<void>;
|
||||
mapLogLine?: DevServer['mapLogLine'];
|
||||
forceColor?: boolean;
|
||||
}
|
||||
|
||||
export class DevServer {
|
||||
|
@ -50,6 +51,7 @@ export class DevServer {
|
|||
private readonly argv: string[];
|
||||
private readonly gracefulTimeout: number;
|
||||
private readonly mapLogLine?: (line: string) => string | null;
|
||||
private readonly forceColor: boolean;
|
||||
|
||||
constructor(options: Options) {
|
||||
this.log = options.log;
|
||||
|
@ -62,6 +64,7 @@ export class DevServer {
|
|||
this.sigint$ = options.sigint$ ?? Rx.fromEvent<void>(process, 'SIGINT');
|
||||
this.sigterm$ = options.sigterm$ ?? Rx.fromEvent<void>(process, 'SIGTERM');
|
||||
this.mapLogLine = options.mapLogLine;
|
||||
this.forceColor = options.forceColor ?? !!process.stdout.isTTY;
|
||||
}
|
||||
|
||||
isReady$() {
|
||||
|
@ -141,8 +144,13 @@ export class DevServer {
|
|||
})
|
||||
);
|
||||
|
||||
const serverOptions = {
|
||||
script: this.script,
|
||||
argv: this.argv,
|
||||
forceColor: this.forceColor,
|
||||
};
|
||||
const runServer = () =>
|
||||
usingServerProcess(this.script, this.argv, (proc) => {
|
||||
usingServerProcess(serverOptions, (proc) => {
|
||||
this.phase$.next('starting');
|
||||
this.ready$.next(false);
|
||||
|
||||
|
|
|
@ -18,14 +18,19 @@ interface ProcResource extends Rx.Unsubscribable {
|
|||
unsubscribe(): void;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
script: string;
|
||||
argv: string[];
|
||||
forceColor: boolean;
|
||||
}
|
||||
|
||||
export function usingServerProcess<T>(
|
||||
script: string,
|
||||
argv: string[],
|
||||
options: Options,
|
||||
fn: (proc: execa.ExecaChildProcess) => Rx.Observable<T>
|
||||
) {
|
||||
return Rx.using(
|
||||
(): ProcResource => {
|
||||
const proc = execa.node(script, argv, {
|
||||
const proc = execa.node(options.script, options.argv, {
|
||||
stdio: 'pipe',
|
||||
nodeOptions: [
|
||||
...process.execArgv,
|
||||
|
@ -36,7 +41,7 @@ export function usingServerProcess<T>(
|
|||
NODE_OPTIONS: process.env.NODE_OPTIONS,
|
||||
isDevCliChild: 'true',
|
||||
ELASTIC_APM_SERVICE_NAME: 'kibana',
|
||||
...(process.stdout.isTTY ? { FORCE_COLOR: 'true' } : {}),
|
||||
...(options.forceColor ? { FORCE_COLOR: 'true' } : {}),
|
||||
},
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue