fix(reporters): preserve the order between deferred errors and stdio (#20830)
This commit is contained in:
parent
0484f02145
commit
8a1612ceec
|
|
@ -18,7 +18,6 @@ import type { FullConfig, TestCase, TestError, TestResult, FullResult, TestStep,
|
||||||
import { Suite } from '../common/test';
|
import { Suite } from '../common/test';
|
||||||
|
|
||||||
type StdIOChunk = {
|
type StdIOChunk = {
|
||||||
type: 'stdout' | 'stderr';
|
|
||||||
chunk: string | Buffer;
|
chunk: string | Buffer;
|
||||||
test?: TestCase;
|
test?: TestCase;
|
||||||
result?: TestResult;
|
result?: TestResult;
|
||||||
|
|
@ -26,8 +25,7 @@ type StdIOChunk = {
|
||||||
|
|
||||||
export class Multiplexer implements Reporter {
|
export class Multiplexer implements Reporter {
|
||||||
private _reporters: Reporter[];
|
private _reporters: Reporter[];
|
||||||
private _deferredErrors: TestError[] | null = [];
|
private _deferred: { error?: TestError, stdout?: StdIOChunk, stderr?: StdIOChunk }[] | null = [];
|
||||||
private _deferredStdIO: StdIOChunk[] | null = [];
|
|
||||||
private _config!: FullConfig;
|
private _config!: FullConfig;
|
||||||
|
|
||||||
constructor(reporters: Reporter[]) {
|
constructor(reporters: Reporter[]) {
|
||||||
|
|
@ -44,20 +42,17 @@ export class Multiplexer implements Reporter {
|
||||||
|
|
||||||
onBegin(config: FullConfig, suite: Suite) {
|
onBegin(config: FullConfig, suite: Suite) {
|
||||||
for (const reporter of this._reporters)
|
for (const reporter of this._reporters)
|
||||||
reporter.onBegin?.(config, suite);
|
wrap(() => reporter.onBegin?.(config, suite));
|
||||||
|
|
||||||
const errors = this._deferredErrors!;
|
const deferred = this._deferred!;
|
||||||
this._deferredErrors = null;
|
this._deferred = null;
|
||||||
for (const error of errors)
|
for (const item of deferred) {
|
||||||
this.onError(error);
|
if (item.error)
|
||||||
|
this.onError(item.error);
|
||||||
const stdios = this._deferredStdIO!;
|
if (item.stdout)
|
||||||
this._deferredStdIO = null;
|
this.onStdOut(item.stdout.chunk, item.stdout.test, item.stdout.result);
|
||||||
for (const stdio of stdios) {
|
if (item.stderr)
|
||||||
if (stdio.type === 'stdout')
|
this.onStdErr(item.stderr.chunk, item.stderr.test, item.stderr.result);
|
||||||
this.onStdOut(stdio.chunk, stdio.test, stdio.result);
|
|
||||||
else
|
|
||||||
this.onStdErr(stdio.chunk, stdio.test, stdio.result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,8 +62,8 @@ export class Multiplexer implements Reporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
onStdOut(chunk: string | Buffer, test?: TestCase, result?: TestResult) {
|
onStdOut(chunk: string | Buffer, test?: TestCase, result?: TestResult) {
|
||||||
if (this._deferredStdIO) {
|
if (this._deferred) {
|
||||||
this._deferredStdIO.push({ chunk, test, result, type: 'stdout' });
|
this._deferred.push({ stdout: { chunk, test, result } });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (const reporter of this._reporters)
|
for (const reporter of this._reporters)
|
||||||
|
|
@ -76,8 +71,8 @@ export class Multiplexer implements Reporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
onStdErr(chunk: string | Buffer, test?: TestCase, result?: TestResult) {
|
onStdErr(chunk: string | Buffer, test?: TestCase, result?: TestResult) {
|
||||||
if (this._deferredStdIO) {
|
if (this._deferred) {
|
||||||
this._deferredStdIO.push({ chunk, test, result, type: 'stderr' });
|
this._deferred.push({ stderr: { chunk, test, result } });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,7 +88,7 @@ export class Multiplexer implements Reporter {
|
||||||
async onEnd() { }
|
async onEnd() { }
|
||||||
|
|
||||||
async onExit(result: FullResult) {
|
async onExit(result: FullResult) {
|
||||||
if (this._deferredErrors) {
|
if (this._deferred) {
|
||||||
// onBegin was not reported, emit it.
|
// onBegin was not reported, emit it.
|
||||||
this.onBegin(this._config, new Suite('', 'root'));
|
this.onBegin(this._config, new Suite('', 'root'));
|
||||||
}
|
}
|
||||||
|
|
@ -106,8 +101,8 @@ export class Multiplexer implements Reporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
onError(error: TestError) {
|
onError(error: TestError) {
|
||||||
if (this._deferredErrors) {
|
if (this._deferred) {
|
||||||
this._deferredErrors.push(error);
|
this._deferred.push({ error });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (const reporter of this._reporters)
|
for (const reporter of this._reporters)
|
||||||
|
|
@ -121,7 +116,7 @@ export class Multiplexer implements Reporter {
|
||||||
|
|
||||||
onStepEnd(test: TestCase, result: TestResult, step: TestStep) {
|
onStepEnd(test: TestCase, result: TestResult, step: TestStep) {
|
||||||
for (const reporter of this._reporters)
|
for (const reporter of this._reporters)
|
||||||
(reporter as any).onStepEnd?.(test, result, step);
|
wrap(() => (reporter as any).onStepEnd?.(test, result, step));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue