UNPKG

6.41 kBJavaScriptView Raw
1'use strict';
2
3var global = (function () {
4 if (typeof globalThis !== 'undefined') {
5 return globalThis;
6 } else if (typeof global !== 'undefined') {
7 return global;
8 } else if (typeof self !== 'undefined') {
9 return self;
10 } else if (typeof window !== 'undefined') {
11 return window;
12 } else {
13 return Function('return this')();
14 }
15})();
16
17var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
18Object.defineProperty(exports, '__esModule', {
19 value: true
20});
21exports.default = void 0;
22
23var _testResult = require('@jest/test-result');
24
25var _jestMessageUtil = require('jest-message-util');
26
27var global = (function () {
28 if (typeof globalThis !== 'undefined') {
29 return globalThis;
30 } else if (typeof global !== 'undefined') {
31 return global;
32 } else if (typeof self !== 'undefined') {
33 return self;
34 } else if (typeof window !== 'undefined') {
35 return window;
36 } else {
37 return Function('return this')();
38 }
39})();
40
41var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
42
43var global = (function () {
44 if (typeof globalThis !== 'undefined') {
45 return globalThis;
46 } else if (typeof global !== 'undefined') {
47 return global;
48 } else if (typeof self !== 'undefined') {
49 return self;
50 } else if (typeof window !== 'undefined') {
51 return window;
52 } else {
53 return Function('return this')();
54 }
55})();
56
57var jestNow = global[Symbol.for('jest-native-now')] || global.Date.now;
58
59var global = (function () {
60 if (typeof globalThis !== 'undefined') {
61 return globalThis;
62 } else if (typeof global !== 'undefined') {
63 return global;
64 } else if (typeof self !== 'undefined') {
65 return self;
66 } else if (typeof window !== 'undefined') {
67 return window;
68 } else {
69 return Function('return this')();
70 }
71})();
72
73var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
74
75var global = (function () {
76 if (typeof globalThis !== 'undefined') {
77 return globalThis;
78 } else if (typeof global !== 'undefined') {
79 return global;
80 } else if (typeof self !== 'undefined') {
81 return self;
82 } else if (typeof window !== 'undefined') {
83 return window;
84 } else {
85 return Function('return this')();
86 }
87})();
88
89var Promise = global[Symbol.for('jest-native-promise')] || global.Promise;
90
91function _defineProperty(obj, key, value) {
92 if (key in obj) {
93 Object.defineProperty(obj, key, {
94 value: value,
95 enumerable: true,
96 configurable: true,
97 writable: true
98 });
99 } else {
100 obj[key] = value;
101 }
102 return obj;
103}
104
105class Jasmine2Reporter {
106 constructor(globalConfig, config, testPath) {
107 _defineProperty(this, '_testResults', void 0);
108
109 _defineProperty(this, '_globalConfig', void 0);
110
111 _defineProperty(this, '_config', void 0);
112
113 _defineProperty(this, '_currentSuites', void 0);
114
115 _defineProperty(this, '_resolve', void 0);
116
117 _defineProperty(this, '_resultsPromise', void 0);
118
119 _defineProperty(this, '_startTimes', void 0);
120
121 _defineProperty(this, '_testPath', void 0);
122
123 this._globalConfig = globalConfig;
124 this._config = config;
125 this._testPath = testPath;
126 this._testResults = [];
127 this._currentSuites = [];
128 this._resolve = null;
129 this._resultsPromise = new Promise(resolve => (this._resolve = resolve));
130 this._startTimes = new Map();
131 }
132
133 jasmineStarted(_runDetails) {}
134
135 specStarted(spec) {
136 this._startTimes.set(spec.id, jestNow());
137 }
138
139 specDone(result) {
140 this._testResults.push(
141 this._extractSpecResults(result, this._currentSuites.slice(0))
142 );
143 }
144
145 suiteStarted(suite) {
146 this._currentSuites.push(suite.description);
147 }
148
149 suiteDone(_result) {
150 this._currentSuites.pop();
151 }
152
153 jasmineDone(_runDetails) {
154 let numFailingTests = 0;
155 let numPassingTests = 0;
156 let numPendingTests = 0;
157 let numTodoTests = 0;
158 const testResults = this._testResults;
159 testResults.forEach(testResult => {
160 if (testResult.status === 'failed') {
161 numFailingTests++;
162 } else if (testResult.status === 'pending') {
163 numPendingTests++;
164 } else if (testResult.status === 'todo') {
165 numTodoTests++;
166 } else {
167 numPassingTests++;
168 }
169 });
170 const testResult = {
171 ...(0, _testResult.createEmptyTestResult)(),
172 console: null,
173 failureMessage: (0, _jestMessageUtil.formatResultsErrors)(
174 testResults,
175 this._config,
176 this._globalConfig,
177 this._testPath
178 ),
179 numFailingTests,
180 numPassingTests,
181 numPendingTests,
182 numTodoTests,
183 snapshot: {
184 added: 0,
185 fileDeleted: false,
186 matched: 0,
187 unchecked: 0,
188 unmatched: 0,
189 updated: 0
190 },
191 testFilePath: this._testPath,
192 testResults
193 };
194
195 this._resolve(testResult);
196 }
197
198 getResults() {
199 return this._resultsPromise;
200 }
201
202 _addMissingMessageToStack(stack, message) {
203 // Some errors (e.g. Angular injection error) don't prepend error.message
204 // to stack, instead the first line of the stack is just plain 'Error'
205 const ERROR_REGEX = /^Error:?\s*\n/;
206
207 if (stack && message && !stack.includes(message)) {
208 return message + stack.replace(ERROR_REGEX, '\n');
209 }
210
211 return stack;
212 }
213
214 _extractSpecResults(specResult, ancestorTitles) {
215 const start = this._startTimes.get(specResult.id);
216
217 const duration = start ? jestNow() - start : undefined;
218 const status =
219 specResult.status === 'disabled' ? 'pending' : specResult.status;
220 const location = specResult.__callsite
221 ? {
222 column: specResult.__callsite.getColumnNumber(),
223 line: specResult.__callsite.getLineNumber()
224 }
225 : null;
226 const results = {
227 ancestorTitles,
228 duration,
229 failureDetails: [],
230 failureMessages: [],
231 fullName: specResult.fullName,
232 location,
233 numPassingAsserts: 0,
234 // Jasmine2 only returns an array of failed asserts.
235 status,
236 title: specResult.description
237 };
238 specResult.failedExpectations.forEach(failed => {
239 const message =
240 !failed.matcherName && typeof failed.stack === 'string'
241 ? this._addMissingMessageToStack(failed.stack, failed.message)
242 : failed.message || '';
243 results.failureMessages.push(message);
244 results.failureDetails.push(failed);
245 });
246 return results;
247 }
248}
249
250exports.default = Jasmine2Reporter;