UNPKG

intern

Version:

Intern. A next-generation code testing stack for JavaScript.

109 lines 5.03 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports", "tslib", "@theintern/common", "./Reporter"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var common_1 = require("@theintern/common"); var Reporter_1 = tslib_1.__importStar(require("./Reporter")); var Dom = (function (_super) { tslib_1.__extends(Dom, _super); function Dom(executor, options) { if (options === void 0) { options = {}; } var _this = _super.call(this, executor, options) || this; _this.document = options.document || document; _this.suiteNode = options.suiteNode || _this.document.body; return _this; } Dom.prototype.error = function (error) { var errorNode = this.document.createElement('pre'); errorNode.appendChild(this.document.createTextNode(this.formatError(error))); this.document.body.appendChild(errorNode); }; Dom.prototype.suiteEnd = function (suite) { this.suiteNode = ((this.suiteNode.parentNode.parentNode || this.document.body)); if (suite.error) { this.suiteNode.appendChild(this.document.createTextNode('Suite "' + suite.id + '" failed')); this.suiteNode.style.color = 'red'; var errorNode = this.document.createElement('pre'); errorNode.appendChild(this.document.createTextNode(this.formatError(suite.error))); this.suiteNode.appendChild(errorNode); this._scroll(); } }; Dom.prototype.suiteStart = function (suite) { var oldSuiteNode = this.suiteNode; this.suiteNode = this.document.createElement('ol'); if (oldSuiteNode === this.document.body) { oldSuiteNode.appendChild(this.suiteNode); } else { var outerSuiteNode = this.document.createElement('li'); var headerNode = this.document.createElement('div'); headerNode.appendChild(this.document.createTextNode(suite.name)); outerSuiteNode.appendChild(headerNode); outerSuiteNode.appendChild(this.suiteNode); oldSuiteNode.appendChild(outerSuiteNode); } this._scroll(); }; Dom.prototype.testEnd = function (test) { if (test.skipped) { var testNode = (this.testNode = this.document.createElement('li')); testNode.appendChild(this.document.createTextNode(test.name + ' skipped' + (test.skipped ? ' (' + test.skipped + ')' : ''))); testNode.style.color = 'gray'; this.suiteNode.appendChild(testNode); } else if (test.error) { var testNode = this.testNode; testNode.appendChild(this.document.createTextNode(' failed (' + test.timeElapsed + 'ms)')); testNode.style.color = 'red'; var errorNode = this.document.createElement('pre'); errorNode.appendChild(this.document.createTextNode(this.formatError(test.error))); testNode.appendChild(errorNode); } else { var testNode = this.testNode; testNode.appendChild(this.document.createTextNode(' passed (' + test.timeElapsed + 'ms)')); testNode.style.color = 'green'; } this._scroll(); }; Dom.prototype.testStart = function (test) { this.testNode = this.document.createElement('li'); this.testNode.appendChild(this.document.createTextNode(test.name)); this.suiteNode.appendChild(this.testNode); this._scroll(); }; Dom.prototype._scroll = function () { common_1.global.scrollTo(0, this.document.documentElement.scrollHeight || this.document.body.scrollHeight); }; tslib_1.__decorate([ Reporter_1.eventHandler() ], Dom.prototype, "error", null); tslib_1.__decorate([ Reporter_1.eventHandler() ], Dom.prototype, "suiteEnd", null); tslib_1.__decorate([ Reporter_1.eventHandler() ], Dom.prototype, "suiteStart", null); tslib_1.__decorate([ Reporter_1.eventHandler() ], Dom.prototype, "testEnd", null); tslib_1.__decorate([ Reporter_1.eventHandler() ], Dom.prototype, "testStart", null); return Dom; }(Reporter_1.default)); exports.default = Dom; }); //# sourceMappingURL=Dom.js.map