UNPKG

2.13 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.default = void 0;
7
8function _defineProperty(obj, key, value) {
9 if (key in obj) {
10 Object.defineProperty(obj, key, {
11 value: value,
12 enumerable: true,
13 configurable: true,
14 writable: true
15 });
16 } else {
17 obj[key] = value;
18 }
19 return obj;
20}
21
22/**
23 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
24 *
25 * This source code is licensed under the MIT license found in the
26 * LICENSE file in the root directory of this source tree.
27 */
28class ReporterDispatcher {
29 constructor() {
30 _defineProperty(this, '_reporters', void 0);
31
32 this._reporters = [];
33 }
34
35 register(reporter) {
36 this._reporters.push(reporter);
37 }
38
39 unregister(ReporterClass) {
40 this._reporters = this._reporters.filter(
41 reporter => !(reporter instanceof ReporterClass)
42 );
43 }
44
45 async onTestResult(test, testResult, results) {
46 for (const reporter of this._reporters) {
47 reporter.onTestResult &&
48 (await reporter.onTestResult(test, testResult, results));
49 } // Release memory if unused later.
50
51 testResult.sourceMaps = undefined;
52 testResult.coverage = undefined;
53 testResult.console = undefined;
54 }
55
56 async onTestStart(test) {
57 for (const reporter of this._reporters) {
58 reporter.onTestStart && (await reporter.onTestStart(test));
59 }
60 }
61
62 async onRunStart(results, options) {
63 for (const reporter of this._reporters) {
64 reporter.onRunStart && (await reporter.onRunStart(results, options));
65 }
66 }
67
68 async onRunComplete(contexts, results) {
69 for (const reporter of this._reporters) {
70 reporter.onRunComplete &&
71 (await reporter.onRunComplete(contexts, results));
72 }
73 } // Return a list of last errors for every reporter
74
75 getErrors() {
76 return this._reporters.reduce((list, reporter) => {
77 const error = reporter.getLastError && reporter.getLastError();
78 return error ? list.concat(error) : list;
79 }, []);
80 }
81
82 hasErrors() {
83 return this.getErrors().length !== 0;
84 }
85}
86
87exports.default = ReporterDispatcher;