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", "./Reporter", "../Suite"], factory);
|
8 | }
|
9 | })(function (require, exports) {
|
10 | "use strict";
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | var tslib_1 = require("tslib");
|
13 | var Reporter_1 = tslib_1.__importStar(require("./Reporter"));
|
14 | var Suite_1 = require("../Suite");
|
15 | var TeamCity = (function (_super) {
|
16 | tslib_1.__extends(TeamCity, _super);
|
17 | function TeamCity() {
|
18 | return _super !== null && _super.apply(this, arguments) || this;
|
19 | }
|
20 | TeamCity.prototype.runStart = function () {
|
21 | this._ignoredTestIds = {};
|
22 | };
|
23 | TeamCity.prototype.testStart = function (test) {
|
24 | this._sendMessage('testStarted', {
|
25 | name: test.name,
|
26 | flowId: test.sessionId
|
27 | });
|
28 | };
|
29 | TeamCity.prototype.testEnd = function (test) {
|
30 | if (test.error) {
|
31 | var message = {
|
32 | name: test.name,
|
33 | message: this.formatError(test.error),
|
34 | flowId: test.sessionId
|
35 | };
|
36 | if (test.error.actual && test.error.expected) {
|
37 | message.type = 'comparisonFailure';
|
38 | message.expected = test.error.expected;
|
39 | message.actual = test.error.actual;
|
40 | }
|
41 | this._sendMessage('testFailed', message);
|
42 | }
|
43 | else if (test.skipped) {
|
44 | this._sendMessage('testIgnored', {
|
45 | name: test.name,
|
46 | flowId: test.sessionId
|
47 | });
|
48 | }
|
49 | else {
|
50 | this._sendMessage('testFinished', {
|
51 | name: test.name,
|
52 | duration: test.timeElapsed,
|
53 | flowId: test.sessionId
|
54 | });
|
55 | }
|
56 | };
|
57 | TeamCity.prototype.suiteStart = function (suite) {
|
58 | this._sendMessage('testSuiteStarted', {
|
59 | name: suite.name,
|
60 | startDate: new Date(),
|
61 | flowId: suite.sessionId
|
62 | });
|
63 | };
|
64 | TeamCity.prototype.suiteEnd = function (suite) {
|
65 | if (suite.error) {
|
66 | this._sendMessage('message', {
|
67 | name: suite.name,
|
68 | flowId: suite.sessionId,
|
69 | text: 'SUITE ERROR',
|
70 | errorDetails: this.formatError(suite.error),
|
71 | status: 'ERROR'
|
72 | });
|
73 | this._notifyUnrunTests(suite);
|
74 | }
|
75 | else {
|
76 | this._sendMessage('testSuiteFinished', {
|
77 | name: suite.name,
|
78 | duration: suite.timeElapsed,
|
79 | flowId: suite.sessionId
|
80 | });
|
81 | }
|
82 | };
|
83 | TeamCity.prototype._escapeString = function (str) {
|
84 | var replacer = /['\n\r\|\[\]\u0100-\uffff]/g;
|
85 | var map = {
|
86 | "'": "|'",
|
87 | '|': '||',
|
88 | '\n': '|n',
|
89 | '\r': '|r',
|
90 | '[': '|[',
|
91 | ']': '|]'
|
92 | };
|
93 | return str.replace(replacer, function (character) {
|
94 | if (character in map) {
|
95 | return map[character];
|
96 | }
|
97 | if (/[^\u0000-\u00ff]/.test(character)) {
|
98 | return '|0x' + character.charCodeAt(0).toString(16);
|
99 | }
|
100 | return '';
|
101 | });
|
102 | };
|
103 | TeamCity.prototype._notifyUnrunTests = function (suite) {
|
104 | var _this = this;
|
105 | var ignoredTestIds = this._ignoredTestIds;
|
106 | var ignoredTests = ignoredTestIds[suite.sessionId];
|
107 | if (!ignoredTests) {
|
108 | ignoredTests = ignoredTestIds[suite.sessionId] = {};
|
109 | }
|
110 | suite.tests.forEach(function (test) {
|
111 | if (Suite_1.isSuite(test)) {
|
112 | _this._notifyUnrunTests(test);
|
113 | }
|
114 | else if (!ignoredTests[test.id]) {
|
115 | _this._sendMessage('testIgnored', {
|
116 | name: test.name,
|
117 | flowId: test.sessionId
|
118 | });
|
119 | ignoredTests[test.id] = true;
|
120 | }
|
121 | });
|
122 | };
|
123 | TeamCity.prototype._sendMessage = function (type, args) {
|
124 | var _this = this;
|
125 | args.timestamp = new Date().toISOString().slice(0, -1);
|
126 | args = Object.keys(args)
|
127 | .map(function (key) { return key + "='" + _this._escapeString(String(args[key])) + "'"; })
|
128 | .join(' ');
|
129 | this.output.write("##teamcity[" + type + " " + args + "]\n");
|
130 | };
|
131 | tslib_1.__decorate([
|
132 | Reporter_1.eventHandler()
|
133 | ], TeamCity.prototype, "runStart", null);
|
134 | tslib_1.__decorate([
|
135 | Reporter_1.eventHandler()
|
136 | ], TeamCity.prototype, "testStart", null);
|
137 | tslib_1.__decorate([
|
138 | Reporter_1.eventHandler()
|
139 | ], TeamCity.prototype, "testEnd", null);
|
140 | tslib_1.__decorate([
|
141 | Reporter_1.eventHandler()
|
142 | ], TeamCity.prototype, "suiteStart", null);
|
143 | tslib_1.__decorate([
|
144 | Reporter_1.eventHandler()
|
145 | ], TeamCity.prototype, "suiteEnd", null);
|
146 | return TeamCity;
|
147 | }(Reporter_1.default));
|
148 | exports.default = TeamCity;
|
149 | });
|
150 |
|
\ | No newline at end of file |