2021-06-06 17:09:53 -07:00
|
|
|
/**
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-07-19 14:54:18 -07:00
|
|
|
import { FullConfig, Suite, TestCase, TestError, TestResult, Reporter, FullResult } from '../../../types/testReporter';
|
2021-06-06 17:09:53 -07:00
|
|
|
|
|
|
|
export class Multiplexer implements Reporter {
|
|
|
|
private _reporters: Reporter[];
|
|
|
|
|
|
|
|
constructor(reporters: Reporter[]) {
|
|
|
|
this._reporters = reporters;
|
|
|
|
}
|
|
|
|
|
|
|
|
onBegin(config: FullConfig, suite: Suite) {
|
|
|
|
for (const reporter of this._reporters)
|
2021-07-16 12:40:33 -07:00
|
|
|
reporter.onBegin?.(config, suite);
|
2021-06-06 17:09:53 -07:00
|
|
|
}
|
|
|
|
|
2021-07-19 14:54:18 -07:00
|
|
|
onTestBegin(test: TestCase) {
|
2021-06-06 17:09:53 -07:00
|
|
|
for (const reporter of this._reporters)
|
2021-07-16 12:40:33 -07:00
|
|
|
reporter.onTestBegin?.(test);
|
2021-06-06 17:09:53 -07:00
|
|
|
}
|
|
|
|
|
2021-07-19 14:54:18 -07:00
|
|
|
onStdOut(chunk: string | Buffer, test?: TestCase) {
|
2021-06-06 17:09:53 -07:00
|
|
|
for (const reporter of this._reporters)
|
2021-07-16 12:40:33 -07:00
|
|
|
reporter.onStdOut?.(chunk, test);
|
2021-06-06 17:09:53 -07:00
|
|
|
}
|
|
|
|
|
2021-07-19 14:54:18 -07:00
|
|
|
onStdErr(chunk: string | Buffer, test?: TestCase) {
|
2021-06-06 17:09:53 -07:00
|
|
|
for (const reporter of this._reporters)
|
2021-07-16 12:40:33 -07:00
|
|
|
reporter.onStdErr?.(chunk, test);
|
2021-06-06 17:09:53 -07:00
|
|
|
}
|
|
|
|
|
2021-07-19 14:54:18 -07:00
|
|
|
onTestEnd(test: TestCase, result: TestResult) {
|
2021-06-06 17:09:53 -07:00
|
|
|
for (const reporter of this._reporters)
|
2021-07-16 12:40:33 -07:00
|
|
|
reporter.onTestEnd?.(test, result);
|
2021-06-06 17:09:53 -07:00
|
|
|
}
|
|
|
|
|
2021-06-29 10:55:46 -07:00
|
|
|
async onEnd(result: FullResult) {
|
2021-06-06 17:09:53 -07:00
|
|
|
for (const reporter of this._reporters)
|
2021-07-16 12:40:33 -07:00
|
|
|
await reporter.onEnd?.(result);
|
2021-06-06 17:09:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
onError(error: TestError) {
|
|
|
|
for (const reporter of this._reporters)
|
2021-07-16 12:40:33 -07:00
|
|
|
reporter.onError?.(error);
|
2021-06-06 17:09:53 -07:00
|
|
|
}
|
|
|
|
}
|