UNPKG

5.03 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", "@theintern/common", "./Reporter"], factory);
8 }
9})(function (require, exports) {
10 "use strict";
11 Object.defineProperty(exports, "__esModule", { value: true });
12 var tslib_1 = require("tslib");
13 var common_1 = require("@theintern/common");
14 var Reporter_1 = tslib_1.__importStar(require("./Reporter"));
15 var Dom = (function (_super) {
16 tslib_1.__extends(Dom, _super);
17 function Dom(executor, options) {
18 if (options === void 0) { options = {}; }
19 var _this = _super.call(this, executor, options) || this;
20 _this.document = options.document || document;
21 _this.suiteNode = options.suiteNode || _this.document.body;
22 return _this;
23 }
24 Dom.prototype.error = function (error) {
25 var errorNode = this.document.createElement('pre');
26 errorNode.appendChild(this.document.createTextNode(this.formatError(error)));
27 this.document.body.appendChild(errorNode);
28 };
29 Dom.prototype.suiteEnd = function (suite) {
30 this.suiteNode = ((this.suiteNode.parentNode.parentNode || this.document.body));
31 if (suite.error) {
32 this.suiteNode.appendChild(this.document.createTextNode('Suite "' + suite.id + '" failed'));
33 this.suiteNode.style.color = 'red';
34 var errorNode = this.document.createElement('pre');
35 errorNode.appendChild(this.document.createTextNode(this.formatError(suite.error)));
36 this.suiteNode.appendChild(errorNode);
37 this._scroll();
38 }
39 };
40 Dom.prototype.suiteStart = function (suite) {
41 var oldSuiteNode = this.suiteNode;
42 this.suiteNode = this.document.createElement('ol');
43 if (oldSuiteNode === this.document.body) {
44 oldSuiteNode.appendChild(this.suiteNode);
45 }
46 else {
47 var outerSuiteNode = this.document.createElement('li');
48 var headerNode = this.document.createElement('div');
49 headerNode.appendChild(this.document.createTextNode(suite.name));
50 outerSuiteNode.appendChild(headerNode);
51 outerSuiteNode.appendChild(this.suiteNode);
52 oldSuiteNode.appendChild(outerSuiteNode);
53 }
54 this._scroll();
55 };
56 Dom.prototype.testEnd = function (test) {
57 if (test.skipped) {
58 var testNode = (this.testNode = this.document.createElement('li'));
59 testNode.appendChild(this.document.createTextNode(test.name +
60 ' skipped' +
61 (test.skipped ? ' (' + test.skipped + ')' : '')));
62 testNode.style.color = 'gray';
63 this.suiteNode.appendChild(testNode);
64 }
65 else if (test.error) {
66 var testNode = this.testNode;
67 testNode.appendChild(this.document.createTextNode(' failed (' + test.timeElapsed + 'ms)'));
68 testNode.style.color = 'red';
69 var errorNode = this.document.createElement('pre');
70 errorNode.appendChild(this.document.createTextNode(this.formatError(test.error)));
71 testNode.appendChild(errorNode);
72 }
73 else {
74 var testNode = this.testNode;
75 testNode.appendChild(this.document.createTextNode(' passed (' + test.timeElapsed + 'ms)'));
76 testNode.style.color = 'green';
77 }
78 this._scroll();
79 };
80 Dom.prototype.testStart = function (test) {
81 this.testNode = this.document.createElement('li');
82 this.testNode.appendChild(this.document.createTextNode(test.name));
83 this.suiteNode.appendChild(this.testNode);
84 this._scroll();
85 };
86 Dom.prototype._scroll = function () {
87 common_1.global.scrollTo(0, this.document.documentElement.scrollHeight ||
88 this.document.body.scrollHeight);
89 };
90 tslib_1.__decorate([
91 Reporter_1.eventHandler()
92 ], Dom.prototype, "error", null);
93 tslib_1.__decorate([
94 Reporter_1.eventHandler()
95 ], Dom.prototype, "suiteEnd", null);
96 tslib_1.__decorate([
97 Reporter_1.eventHandler()
98 ], Dom.prototype, "suiteStart", null);
99 tslib_1.__decorate([
100 Reporter_1.eventHandler()
101 ], Dom.prototype, "testEnd", null);
102 tslib_1.__decorate([
103 Reporter_1.eventHandler()
104 ], Dom.prototype, "testStart", null);
105 return Dom;
106 }(Reporter_1.default));
107 exports.default = Dom;
108});
109//# sourceMappingURL=Dom.js.map
\No newline at end of file