UNPKG

13.3 kBJavaScriptView Raw
1(function (factory) {
2 if (typeof module === "object" && typeof module.exports === "object") {
3 var v = factory(require, exports);
4 if (v !== undefined) module.exports = v;
5 }
6 else if (typeof define === "function" && define.amd) {
7 define(["require", "exports", "tslib", "charm", "istanbul-lib-coverage", "./Reporter", "./TextCoverage", "../common/util"], factory);
8 }
9})(function (require, exports) {
10 "use strict";
11 Object.defineProperty(exports, "__esModule", { value: true });
12 var tslib_1 = require("tslib");
13 var charm_1 = tslib_1.__importDefault(require("charm"));
14 var istanbul_lib_coverage_1 = require("istanbul-lib-coverage");
15 var Reporter_1 = require("./Reporter");
16 var TextCoverage_1 = tslib_1.__importDefault(require("./TextCoverage"));
17 var util_1 = require("../common/util");
18 var eventHandler = Reporter_1.createEventHandler();
19 var Runner = (function (_super) {
20 tslib_1.__extends(Runner, _super);
21 function Runner(executor, options) {
22 if (options === void 0) { options = {}; }
23 var _this = _super.call(this, executor, options) || this;
24 _this.hidePassed = options.hidePassed || false;
25 _this.hideSkipped = options.hideSkipped || false;
26 _this.hideTunnelDownloadProgress =
27 options.hideTunnelDownloadProgress || false;
28 _this.sessions = {};
29 _this.hasRunErrors = false;
30 _this.hasSuiteErrors = false;
31 _this.serveOnly = executor.config.serveOnly;
32 _this.charm = charm_1.default();
33 _this.charm.pipe(_this.output);
34 _this.charm.display('reset');
35 _this._deprecationMessages = {};
36 return _this;
37 }
38 Runner.prototype.coverage = function (message) {
39 var sessionId = message.sessionId || '';
40 if (!this.sessions[sessionId]) {
41 this.sessions[sessionId] = {};
42 }
43 var session = this.sessions[sessionId];
44 session.coverage = session.coverage || istanbul_lib_coverage_1.createCoverageMap();
45 session.coverage.merge(message.coverage);
46 };
47 Runner.prototype.deprecated = function (message) {
48 var key = message.original + "|" + message.replacement + "|" + message.message;
49 if (this._deprecationMessages[key]) {
50 return;
51 }
52 this._deprecationMessages[key] = true;
53 this.charm
54 .foreground('yellow')
55 .write('⚠︎ ' + message.original + ' is deprecated. ');
56 if (message.replacement) {
57 this.charm.write('Use ' + message.replacement + ' instead.');
58 }
59 else {
60 this.charm.write('Please open a ticket at https://github.com/theintern/intern/issues if you still ' +
61 'require access to this function.');
62 }
63 if (message.message) {
64 this.charm.write(' ' + message.message);
65 }
66 this.charm.write('\n');
67 this.charm.display('reset');
68 };
69 Runner.prototype.error = function (error) {
70 this.charm.foreground('red');
71 this.charm.write('(ノಠ益ಠ)ノ彡┻━┻\n');
72 this.charm.write(this.formatError(error));
73 this.charm.display('reset');
74 this.charm.write('\n\n');
75 this.hasRunErrors = true;
76 };
77 Runner.prototype.warning = function (warning) {
78 this.charm.foreground('yellow');
79 var message = typeof warning === 'string' ? warning : this.formatError(warning);
80 this.charm.write("WARNING: " + message.replace(/^Error:\s+/, ''));
81 this.charm.display('reset');
82 this.charm.write('\n\n');
83 };
84 Runner.prototype.log = function (message) {
85 var _this = this;
86 message.split('\n').forEach(function (line) {
87 _this.console.log("DEBUG: " + line);
88 });
89 };
90 Runner.prototype.runEnd = function () {
91 var _this = this;
92 var map = this.executor.coverageMap;
93 var numTests = 0;
94 var numPassedTests = 0;
95 var numFailedTests = 0;
96 var numSkippedTests = 0;
97 var sessionIds = Object.keys(this.sessions);
98 var numEnvironments = sessionIds.length;
99 sessionIds
100 .filter(function (sessionId) { return _this.sessions[sessionId].suite; })
101 .forEach(function (sessionId) {
102 var suite = _this.sessions[sessionId].suite;
103 numTests += suite.numTests;
104 numPassedTests += suite.numPassedTests;
105 numFailedTests += suite.numFailedTests;
106 numSkippedTests += suite.numSkippedTests;
107 });
108 var charm = this.charm;
109 if (map.files().length > 0) {
110 charm.write('\n');
111 charm.display('bright');
112 charm.write('Total coverage\n');
113 charm.display('reset');
114 this.createCoverageReport(this.reportType, map);
115 }
116 var message = "TOTAL: tested " + numEnvironments + " platforms, " + numPassedTests + " passed, " + numFailedTests + " failed";
117 if (numSkippedTests) {
118 message += ", " + numSkippedTests + " skipped";
119 }
120 var numUnrunTests = numTests - (numPassedTests + numFailedTests + numSkippedTests);
121 if (numUnrunTests) {
122 message += ", " + numUnrunTests + " not run";
123 }
124 if (this.hasRunErrors) {
125 message += '; fatal error occurred';
126 }
127 else if (this.hasSuiteErrors) {
128 message += '; suite error occurred';
129 }
130 charm.display('bright');
131 charm.foreground(numFailedTests > 0 || this.hasRunErrors || this.hasSuiteErrors
132 ? 'red'
133 : 'green');
134 charm.write(message);
135 charm.display('reset');
136 charm.write('\n');
137 };
138 Runner.prototype.serverStart = function (server) {
139 if (this.executor.config.serveOnly) {
140 this.charm.write("To use the browser client, browse to\n\n " + this.executor.config.serverUrl + "__intern/\n\n");
141 this.charm.write('Press CTRL-C to stop serving\n\n');
142 }
143 else {
144 var message = "Listening on localhost:" + server.port;
145 if (server.socketPort) {
146 message += " (ws " + server.socketPort + ")";
147 }
148 this.charm.write(message + "\n");
149 }
150 };
151 Runner.prototype.suiteEnd = function (suite) {
152 var session = this.sessions[suite.sessionId || ''];
153 if (!session) {
154 if (!this.serveOnly) {
155 var charm_2 = this.charm;
156 charm_2.display('bright');
157 charm_2.foreground('yellow');
158 charm_2.write('BUG: suiteEnd was received for invalid session ' + suite.sessionId);
159 charm_2.display('reset');
160 charm_2.write('\n');
161 }
162 return;
163 }
164 if (suite.error) {
165 var error = suite.error;
166 var charm_3 = this.charm;
167 charm_3.foreground('red');
168 charm_3.write("Suite " + suite.id + " ERROR" + (error.lifecycleMethod ? " in " + error.lifecycleMethod : '') + "\n");
169 charm_3.write(this.formatError(error));
170 charm_3.display('reset');
171 charm_3.write('\n');
172 this.hasSuiteErrors = session.hasSuiteErrors = true;
173 }
174 else if (!suite.hasParent && this.executor.suites.length > 1) {
175 if (session.coverage) {
176 this.charm.write('\n');
177 this.createCoverageReport(this.reportType, session.coverage);
178 }
179 else {
180 var charm_4 = this.charm;
181 charm_4.write('No unit test coverage for ' + suite.name);
182 charm_4.display('reset');
183 charm_4.write('\n');
184 }
185 var name_1 = suite.name;
186 var hasError = suite.error || session.hasSuiteErrors;
187 var numTests = suite.numTests;
188 var numFailedTests = suite.numFailedTests;
189 var numSkippedTests = suite.numSkippedTests;
190 var numPassedTests = numTests - numFailedTests - numSkippedTests;
191 var summary = name_1 + ": " + numPassedTests + " passed, " + numFailedTests + " failed";
192 if (numSkippedTests) {
193 summary += ", " + numSkippedTests + " skipped";
194 }
195 if (hasError) {
196 summary += '; suite error occurred';
197 }
198 var charm_5 = this.charm;
199 charm_5.display('bright');
200 charm_5.foreground(numFailedTests || hasError > 0 ? 'red' : 'green');
201 charm_5.write(summary);
202 charm_5.display('reset');
203 charm_5.write('\n');
204 }
205 };
206 Runner.prototype.suiteStart = function (suite) {
207 if (!suite.hasParent) {
208 this.sessions[suite.sessionId || ''] = { suite: suite };
209 if (suite.sessionId) {
210 this.charm.write('\n');
211 this.charm.write('‣ Created remote session ' +
212 suite.name +
213 ' (' +
214 suite.sessionId +
215 ')\n');
216 }
217 }
218 };
219 Runner.prototype.testEnd = function (test) {
220 var charm = this.charm;
221 if (test.error) {
222 charm.foreground('red');
223 charm.write('× ' + test.id);
224 charm.write(' (' + test.timeElapsed / 1000 + 's)');
225 charm.write('\n');
226 charm.write(util_1.prefix(this.formatError(test.error), ' '));
227 charm.display('reset');
228 charm.write('\n\n');
229 }
230 else if (test.skipped) {
231 if (!this.hideSkipped) {
232 charm.write('~ ' + test.id);
233 charm.display('reset');
234 charm.write(' (' + (test.skipped || 'skipped') + ')');
235 charm.display('reset');
236 charm.write('\n');
237 }
238 }
239 else {
240 if (!this.hidePassed) {
241 charm.foreground('green');
242 charm.write('✓ ' + test.id);
243 charm.display('reset');
244 charm.write(' (' + test.timeElapsed / 1000 + 's)');
245 charm.display('reset');
246 charm.write('\n');
247 }
248 }
249 };
250 Runner.prototype.tunnelDownloadProgress = function (message) {
251 if (this.hideTunnelDownloadProgress) {
252 return;
253 }
254 var progress = message.progress;
255 this.charm.write('Tunnel download: ' +
256 ((progress.received / progress.total) * 100).toFixed(3) +
257 '%\r');
258 };
259 Runner.prototype.tunnelStart = function (_) {
260 this.charm.write('Tunnel started\n');
261 };
262 Runner.prototype.tunnelStatus = function (message) {
263 this.charm.write(message.status + '\x1b[K\r');
264 };
265 tslib_1.__decorate([
266 eventHandler()
267 ], Runner.prototype, "coverage", null);
268 tslib_1.__decorate([
269 eventHandler()
270 ], Runner.prototype, "deprecated", null);
271 tslib_1.__decorate([
272 eventHandler()
273 ], Runner.prototype, "error", null);
274 tslib_1.__decorate([
275 eventHandler()
276 ], Runner.prototype, "warning", null);
277 tslib_1.__decorate([
278 eventHandler()
279 ], Runner.prototype, "log", null);
280 tslib_1.__decorate([
281 eventHandler()
282 ], Runner.prototype, "runEnd", null);
283 tslib_1.__decorate([
284 eventHandler()
285 ], Runner.prototype, "serverStart", null);
286 tslib_1.__decorate([
287 eventHandler()
288 ], Runner.prototype, "suiteEnd", null);
289 tslib_1.__decorate([
290 eventHandler()
291 ], Runner.prototype, "suiteStart", null);
292 tslib_1.__decorate([
293 eventHandler()
294 ], Runner.prototype, "testEnd", null);
295 tslib_1.__decorate([
296 eventHandler()
297 ], Runner.prototype, "tunnelDownloadProgress", null);
298 tslib_1.__decorate([
299 eventHandler()
300 ], Runner.prototype, "tunnelStart", null);
301 tslib_1.__decorate([
302 eventHandler()
303 ], Runner.prototype, "tunnelStatus", null);
304 return Runner;
305 }(TextCoverage_1.default));
306 exports.default = Runner;
307});
308//# sourceMappingURL=Runner.js.map
\No newline at end of file