1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
6 | if (k2 === undefined) k2 = k;
|
7 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
8 | }) : (function(o, m, k, k2) {
|
9 | if (k2 === undefined) k2 = k;
|
10 | o[k2] = m[k];
|
11 | }));
|
12 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
13 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
14 | }) : function(o, v) {
|
15 | o["default"] = v;
|
16 | });
|
17 | var __importStar = (this && this.__importStar) || function (mod) {
|
18 | if (mod && mod.__esModule) return mod;
|
19 | var result = {};
|
20 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
21 | __setModuleDefault(result, mod);
|
22 | return result;
|
23 | };
|
24 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
25 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
26 | };
|
27 | Object.defineProperty(exports, "__esModule", { value: true });
|
28 | exports.isCoreException = exports.TestsStore = void 0;
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | const time_span_1 = __importDefault(require("time-span"));
|
38 | const Contracts_1 = require("../Contracts");
|
39 | const exceptions = __importStar(require("../Exceptions"));
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | class TestsStore {
|
45 | constructor() {
|
46 | this._store = {
|
47 | passedCount: 0,
|
48 | skippedCount: 0,
|
49 | failedCount: 0,
|
50 | todoCount: 0,
|
51 | regressionCount: 0,
|
52 | total: 0,
|
53 | groups: [],
|
54 | duration: 0,
|
55 | };
|
56 | }
|
57 | |
58 |
|
59 |
|
60 | get activeGroup() {
|
61 | return this._store.groups[this._store.groups.length - 1];
|
62 | }
|
63 | |
64 |
|
65 |
|
66 | recordGroup(group) {
|
67 | this.open();
|
68 | this._store.groups.push({ title: group.title, failedTests: [], failedHooks: [] });
|
69 | }
|
70 | |
71 |
|
72 |
|
73 | endGroup(group) {
|
74 | if (group.status === Contracts_1.IGroupStatus.FAILED && this.activeGroup.title === group.title) {
|
75 | const error = group.error;
|
76 | this.activeGroup.failedHooks.push({ title: error.fnName || error.lifecycle, error });
|
77 | }
|
78 | }
|
79 | |
80 |
|
81 |
|
82 | recordTest(test) {
|
83 | this.open();
|
84 | |
85 |
|
86 |
|
87 |
|
88 | if (test.status === Contracts_1.ITestStatus.FAILED) {
|
89 | this.activeGroup.failedTests.push({ title: test.title, error: test.error });
|
90 | }
|
91 | |
92 |
|
93 |
|
94 | this._store.total++;
|
95 | |
96 |
|
97 |
|
98 | switch (test.status) {
|
99 | case Contracts_1.ITestStatus.FAILED:
|
100 | this._store.failedCount++;
|
101 | break;
|
102 | case Contracts_1.ITestStatus.PASSED:
|
103 | this._store.passedCount++;
|
104 | break;
|
105 | case Contracts_1.ITestStatus.SKIPPED:
|
106 | this._store.skippedCount++;
|
107 | break;
|
108 | case Contracts_1.ITestStatus.TODO:
|
109 | this._store.todoCount++;
|
110 | break;
|
111 | }
|
112 | |
113 |
|
114 |
|
115 | if (test.regression) {
|
116 | this._store.regressionCount++;
|
117 | }
|
118 | }
|
119 | |
120 |
|
121 |
|
122 | open() {
|
123 | if (!this._processStart) {
|
124 | this._processStart = (0, time_span_1.default)();
|
125 | }
|
126 | }
|
127 | |
128 |
|
129 |
|
130 | close() {
|
131 | if (!this._store.duration) {
|
132 | this._store.duration = this._processStart.rounded();
|
133 | }
|
134 | }
|
135 | |
136 |
|
137 |
|
138 | getReport() {
|
139 | this.close();
|
140 | return this._store;
|
141 | }
|
142 | }
|
143 | exports.TestsStore = TestsStore;
|
144 |
|
145 |
|
146 |
|
147 |
|
148 | function isCoreException(error) {
|
149 | return !!Object.keys(exceptions).find((e) => error instanceof exceptions[e]);
|
150 | }
|
151 | exports.isCoreException = isCoreException;
|