1 | 'use strict';
|
2 |
|
3 | var _get = require('babel-runtime/helpers/get')['default'];
|
4 |
|
5 | var _inherits = require('babel-runtime/helpers/inherits')['default'];
|
6 |
|
7 | var _createClass = require('babel-runtime/helpers/create-class')['default'];
|
8 |
|
9 | var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default'];
|
10 |
|
11 | var _Object$keys = require('babel-runtime/core-js/object/keys')['default'];
|
12 |
|
13 | var _getIterator = require('babel-runtime/core-js/get-iterator')['default'];
|
14 |
|
15 | var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default'];
|
16 |
|
17 | var _interopRequireWildcard = require('babel-runtime/helpers/interop-require-wildcard')['default'];
|
18 |
|
19 | Object.defineProperty(exports, '__esModule', {
|
20 | value: true
|
21 | });
|
22 |
|
23 | var _events = require('events');
|
24 |
|
25 | var _events2 = _interopRequireDefault(_events);
|
26 |
|
27 | var _allureJsCommonsWorkflo = require('allure-js-commons-workflo');
|
28 |
|
29 | var _allureJsCommonsWorkflo2 = _interopRequireDefault(_allureJsCommonsWorkflo);
|
30 |
|
31 | var _allureJsCommonsWorkfloBeansStep = require('allure-js-commons-workflo/beans/step');
|
32 |
|
33 | var _allureJsCommonsWorkfloBeansStep2 = _interopRequireDefault(_allureJsCommonsWorkfloBeansStep);
|
34 |
|
35 | var _fs = require('fs');
|
36 |
|
37 | var fs = _interopRequireWildcard(_fs);
|
38 |
|
39 | var _path = require('path');
|
40 |
|
41 | var path = _interopRequireWildcard(_path);
|
42 |
|
43 | function isEmpty(object) {
|
44 | return !object || _Object$keys(object).length === 0;
|
45 | }
|
46 |
|
47 | var LOGGING_HOOKS = ['"before all" hook', '"after all" hook'];
|
48 |
|
49 | var debug = false;
|
50 | var debugSeleniumCommand = false;
|
51 |
|
52 | function logger() {
|
53 | if (debug) {
|
54 | console.log(arguments);
|
55 | }
|
56 | }
|
57 | function error() {
|
58 | console.error(arguments);
|
59 | }
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | var AllureReporter = (function (_events$EventEmitter) {
|
69 | _inherits(AllureReporter, _events$EventEmitter);
|
70 |
|
71 | function AllureReporter(baseReporter, config) {
|
72 | var _this = this;
|
73 |
|
74 | var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
75 |
|
76 | _classCallCheck(this, AllureReporter);
|
77 |
|
78 | _get(Object.getPrototypeOf(AllureReporter.prototype), 'constructor', this).call(this);
|
79 |
|
80 | this.baseReporter = baseReporter;
|
81 | this.config = config;
|
82 | this.options = options;
|
83 | if (options) {
|
84 | debug = options.debug;
|
85 | debugSeleniumCommand = options.debugSeleniumCommand;
|
86 | }
|
87 | this.allures = {};
|
88 | this.currentTestId = '';
|
89 | this.startedSpecs = false;
|
90 | this.testIds = {};
|
91 | this.errorCtr = 0;
|
92 |
|
93 |
|
94 |
|
95 | this.on('end', function () {
|
96 |
|
97 | if (_this.startedSpecs) {
|
98 | _this.addResults();
|
99 | }
|
100 | });
|
101 |
|
102 | this.on('startSpecs', function (runner) {
|
103 | if (!_this.startedSpecs) {
|
104 | _this.startedSpecs = true;
|
105 | }
|
106 | });
|
107 |
|
108 | this.on('suite:start', function (suite) {
|
109 | var allure = _this.getAllure(suite.cid);
|
110 | var currentSuite = allure.getCurrentSuite();
|
111 | var prefix = currentSuite ? currentSuite.name + ' ' : '';
|
112 |
|
113 | process.workflo.currentCid = suite.cid;
|
114 |
|
115 | allure.startSuite(prefix + suite.title);
|
116 | });
|
117 |
|
118 | this.on('suite:end', function (suite) {
|
119 | _this.getAllure(suite.cid).endSuite();
|
120 | });
|
121 |
|
122 | this.on('test:setCurrentId', function (test) {
|
123 | var allure = _this.getAllure(test.cid);
|
124 | _this.currentTestId = test.id;
|
125 |
|
126 | var currentTest = allure.getCurrentTest();
|
127 |
|
128 | if (_this.currentTestId) {
|
129 | if (test.testcase) {
|
130 | var traceInfo = _this.config.traceInfo.testcases[_this.currentTestId];
|
131 |
|
132 | currentTest.addParameter('argument', 'Testcase File', traceInfo.testcaseFile);
|
133 | currentTest.addParameter('argument', 'Validates Specs', traceInfo.specs.join(', '));
|
134 | } else if (test.spec) {
|
135 | var parts = _this.currentTestId.split('|');
|
136 | var spec = parts[0];
|
137 | var criteria = parts[1];
|
138 |
|
139 | var traceInfo = _this.config.traceInfo.specs[spec];
|
140 |
|
141 | currentTest.addParameter('argument', 'Spec File', traceInfo.specFile);
|
142 |
|
143 | var manualFile = traceInfo.criteriaValidationFiles[criteria].manualFile;
|
144 | var testcases = traceInfo.criteriaValidationFiles[criteria].testcases;
|
145 |
|
146 | if (manualFile) {
|
147 | currentTest.addParameter('argument', 'Validated by Manual Results', manualFile);
|
148 | } else if (testcases.length > 0) {
|
149 | currentTest.addParameter('argument', 'Validated in Testcases', testcases.join(', '));
|
150 | }
|
151 | }
|
152 | }
|
153 | });
|
154 |
|
155 | this.on('test:start', function (test) {
|
156 | var allure = _this.getAllure(test.cid);
|
157 | allure.startCase(test.title);
|
158 |
|
159 | _this.lastCid = test.cid;
|
160 |
|
161 | var currentTest = allure.getCurrentTest();
|
162 |
|
163 | if (test.metadata) {
|
164 | for (var key in test.metadata) {
|
165 | var meta = {
|
166 | event: 'test:meta',
|
167 | cid: test.cid
|
168 | };
|
169 | meta[key] = test.metadata[key];
|
170 |
|
171 | _this.handleMetadata(meta);
|
172 | }
|
173 | }
|
174 |
|
175 |
|
176 | var printObject = _this.config.printObject;
|
177 |
|
178 | var filterFilesStr = printObject['Spec Files'] + ' specFiles, ' + printObject['Testcase Files'] + ' testcaseFiles, ' + printObject['Manual Result Files'] + ' manualResultFiles';
|
179 | var filtersStr = printObject['Features'] + ' features, ' + printObject['Specs'] + ' specs, ' + printObject['Suites'] + ' suites, ' + printObject['Testcases'] + ' testcases';
|
180 | var coverageStr = printObject['Automated Criteria'].count + ' automated ' + printObject['Automated Criteria'].percentage + ', ' + printObject['Manual Criteria'].count + ' manual ' + printObject['Manual Criteria'].percentage + ', ' + printObject['Uncovered Criteria'].count + ' uncovered ' + printObject['Uncovered Criteria'].percentage;
|
181 | var uncoveredCriteriaStr = '';
|
182 |
|
183 | for (var spec in printObject['Uncovered Criteria Object']) {
|
184 | uncoveredCriteriaStr += spec + ': [' + printObject['Uncovered Criteria Object'][spec].join(', ') + '], ';
|
185 | }
|
186 |
|
187 | uncoveredCriteriaStr = uncoveredCriteriaStr.substring(0, uncoveredCriteriaStr.length - 2);
|
188 |
|
189 |
|
190 | currentTest.addParameter('environment-variable', 'BROWSER', test.runner[test.cid].browserName);
|
191 | currentTest.addParameter('environment-variable', 'BASE URL', _this.config.baseUrl);
|
192 |
|
193 | if (_this.config.manualOnly) {
|
194 | currentTest.addParameter('environment-variable', 'EXECUTION MODE: ', 'Manual Only');
|
195 | } else if (_this.config.automaticOnly) {
|
196 | currentTest.addParameter('environment-variable', 'EXECUTION MODE: ', 'Automatic Only');
|
197 | } else {
|
198 | currentTest.addParameter('environment-variable', 'EXECUTION MODE: ', 'Automatic and Manual');
|
199 | }
|
200 |
|
201 |
|
202 |
|
203 |
|
204 | currentTest.addParameter('environment-variable', 'CRITERIA COVERAGE: ', coverageStr);
|
205 | currentTest.addParameter('environment-variable', 'FILTER FILES: ', filterFilesStr);
|
206 | currentTest.addParameter('environment-variable', 'FILTERS: ', filtersStr);
|
207 |
|
208 | if (uncoveredCriteriaStr) {
|
209 | currentTest.addParameter('environment-variable', 'UNCOVERED CRITERIA: ', uncoveredCriteriaStr);
|
210 | }
|
211 | });
|
212 |
|
213 | this.on('test:pass', function (test) {
|
214 | var allure = _this.getAllure(test.cid);
|
215 |
|
216 | _this.addArguments(test);
|
217 | _this.addResultsDummy(test);
|
218 | allure.endCase('passed');
|
219 | });
|
220 |
|
221 | this.on('test:fail', function (test) {
|
222 | var allure = _this.getAllure(test.cid);
|
223 |
|
224 | if (!allure.getCurrentTest()) {
|
225 | allure.startCase(test.title);
|
226 | } else {
|
227 | allure.getCurrentTest().name = test.title;
|
228 | }
|
229 |
|
230 | while (allure.getCurrentSuite().currentStep instanceof _allureJsCommonsWorkfloBeansStep2['default']) {
|
231 | allure.endStep('failed');
|
232 | }
|
233 |
|
234 | _this.addArguments(test);
|
235 | _this.addResultsDummy(test);
|
236 | allure.endCase('failed', {
|
237 | message: '\n' + test.err.message,
|
238 | stack: '\n' + test.err.stack
|
239 | });
|
240 | });
|
241 |
|
242 | this.on('test:broken', function (test) {
|
243 | var allure = _this.getAllure(test.cid);
|
244 |
|
245 | if (!allure.getCurrentTest()) {
|
246 | allure.startCase(test.title);
|
247 | } else {
|
248 | allure.getCurrentTest().name = test.title;
|
249 | }
|
250 |
|
251 | while (allure.getCurrentSuite().currentStep instanceof _allureJsCommonsWorkfloBeansStep2['default']) {
|
252 | allure.endStep('broken');
|
253 | }
|
254 |
|
255 | _this.addArguments(test);
|
256 | _this.addResultsDummy(test);
|
257 |
|
258 | allure.endCase('broken', {
|
259 | message: '\n' + test.err.message,
|
260 | stack: '\n' + test.err.stack
|
261 | });
|
262 | });
|
263 |
|
264 | this.on('test:pending', function (test) {
|
265 | var allure = _this.getAllure(test.cid);
|
266 |
|
267 | _this.addArguments(test);
|
268 | _this.addResultsDummy(test);
|
269 | allure.endCase('pending', { message: 'Test ignored', stack: '' });
|
270 | });
|
271 |
|
272 | this.on('test:unvalidated', function (test) {
|
273 | var allure = _this.getAllure(test.cid);
|
274 |
|
275 | if (!allure.getCurrentTest()) {
|
276 | allure.startCase(test.title);
|
277 | } else {
|
278 | allure.getCurrentTest().name = test.title;
|
279 | }
|
280 |
|
281 | _this.addArguments(test);
|
282 | _this.addResultsDummy(test);
|
283 | allure.endCase('unknown', {
|
284 | message: '\n' + test.err.message
|
285 | });
|
286 | });
|
287 |
|
288 | this.on('runner:command', function (command) {
|
289 | var allure = _this.getAllure(command.cid);
|
290 |
|
291 | if (!_this.isAnyTestRunning(allure)) {
|
292 | return;
|
293 | }
|
294 |
|
295 | if (debugSeleniumCommand) {
|
296 | allure.startStep(command.method + ' ' + command.uri.path);
|
297 |
|
298 | if (!isEmpty(command.data)) {
|
299 | _this.dumpJSON(allure, 'Request', command.data);
|
300 | }
|
301 | }
|
302 | });
|
303 |
|
304 | this.on('runner:result', function (command) {
|
305 | var allure = _this.getAllure(command.cid);
|
306 | var status = 'passed';
|
307 |
|
308 | if (!_this.isAnyTestRunning(allure)) {
|
309 | return;
|
310 | }
|
311 |
|
312 | if (debugSeleniumCommand) {
|
313 | if (command.body.screenshot) {
|
314 | allure.addAttachment('Screenshot', new Buffer(command.body.screenshot, 'base64'));
|
315 | delete command.body.screenshot;
|
316 | }
|
317 | if (command.body.type && command.body.type === 'RuntimeError') {
|
318 | status = 'broken';
|
319 | }
|
320 |
|
321 | _this.dumpJSON(allure, 'Response', command.body);
|
322 |
|
323 | allure.endStep(status);
|
324 | }
|
325 | });
|
326 |
|
327 | |
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 | this.on('test:meta', function (meta) {
|
341 | this.handleMetadata(meta);
|
342 | });
|
343 |
|
344 | this.on('step:start', function (step) {
|
345 | var allure = this.getAllure(step.cid);
|
346 | logger('step:start', step);
|
347 |
|
348 | if (!this.isAnyTestRunning(allure)) {
|
349 | error('ERROR', 'cannot start step because no test is running', step);
|
350 | return;
|
351 | }
|
352 | allure.startStep(step.title != null ? step.title : 'No name defined');
|
353 |
|
354 | if (step.arg) {
|
355 | this.dumpJSON(allure, 'Step Arg', step.arg);
|
356 | }
|
357 | });
|
358 |
|
359 | this.on('step:end', function (step) {
|
360 | var allure = this.getAllure(step.cid);
|
361 | logger('step:end', step);
|
362 |
|
363 | if (!this.isAnyTestRunning(allure)) {
|
364 | error('ERROR', 'cannot end step because no test is running', step);
|
365 | return;
|
366 | }
|
367 |
|
368 | if (step.arg) {
|
369 | this.dumpJSON(allure, 'Step Result', step.arg);
|
370 | }
|
371 |
|
372 | if (step.assertionFailures) {
|
373 | this.dumpJSON(allure, 'Validation Failures', step.assertionFailures);
|
374 | }
|
375 |
|
376 | if (step.screenshots) {
|
377 | for (var screenshotMessage in step.screenshots) {
|
378 | for (var i = 0; i < step.screenshots[screenshotMessage].length; ++i) {
|
379 | if (step.screenshots[screenshotMessage] && step.screenshots[screenshotMessage][i]) {
|
380 | allure.addAttachment(screenshotMessage + ' (' + (i + 1) + ')', new Buffer(fs.readFileSync(step.screenshots[screenshotMessage][i], { encoding: 'base64' }), 'base64'));
|
381 | }
|
382 | }
|
383 | }
|
384 | }
|
385 |
|
386 | allure.endStep(step.status);
|
387 | });
|
388 |
|
389 | this.on('step:pass', function (step) {
|
390 | var allure = this.getAllure(step.cid);
|
391 | logger('step:pass', step);
|
392 |
|
393 | allure.endStep('passed');
|
394 | });
|
395 |
|
396 | this.on('step:fail', function (step) {
|
397 | var allure = this.getAllure(step.cid);
|
398 | logger('step:fail', step);
|
399 |
|
400 | this.dumpJSON(allure, 'Validation Failures', step.errs);
|
401 |
|
402 | if (step.screenshots) {
|
403 | for (var screenshotMessage in step.screenshots) {
|
404 | for (var i = 0; i < step.screenshots[screenshotMessage].length; ++i) {
|
405 | if (step.screenshots[screenshotMessage] && step.screenshots[screenshotMessage][i]) {
|
406 | allure.addAttachment(screenshotMessage + ' (' + (i + 1) + ')', new Buffer(fs.readFileSync(step.screenshots[screenshotMessage][i], { encoding: 'base64' }), 'base64'));
|
407 | }
|
408 | }
|
409 | }
|
410 | }
|
411 |
|
412 | allure.endStep('failed');
|
413 | });
|
414 |
|
415 | this.on('step:broken', function (step) {
|
416 | var allure = this.getAllure(step.cid);
|
417 | logger('step:broken', step);
|
418 |
|
419 | this.dumpJSON(allure, 'Errors', step.assertion);
|
420 |
|
421 | if (step.assertion.screenshotFilename) {
|
422 | allure.addAttachment(step.assertion.message, new Buffer(fs.readFileSync(step.assertion.screenshotFilename, { encoding: 'base64' }), 'base64'));
|
423 | }
|
424 |
|
425 | allure.endStep('broken');
|
426 | });
|
427 |
|
428 | this.on('step:unvalidated', function (step) {
|
429 | var allure = this.getAllure(step.cid);
|
430 | logger('step:unvalidated', step);
|
431 |
|
432 | this.dumpJSON(allure, 'unvalidated Specifications', step.err);
|
433 |
|
434 | allure.endStep('unknown');
|
435 | });
|
436 |
|
437 | |
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 | this.on('test:attach', function (attachment) {
|
447 | var allure = this.getAllure(attachment.cid);
|
448 | logger('test:attach', attachment);
|
449 |
|
450 | if (this.isAnyTestRunning(allure)) {
|
451 | error('ERROR', 'cannot attach because no test is running', attachment);
|
452 | return;
|
453 | }
|
454 | allure.addAttachment(attachment.title, fs.readFileSync(attachment.file), attachment.type);
|
455 | });
|
456 |
|
457 | |
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 | this.on('test:log', function (log) {
|
466 | var allure = this.getAllure(log.cid);
|
467 | logger('test:log', log);
|
468 |
|
469 | if (this.isAnyTestRunning(allure)) {
|
470 | error('ERROR', 'cannot log because no test is running', log);
|
471 | return;
|
472 | }
|
473 | var content = log.detail != null ? JSON.stringify(log.detail, null, ' ') : '';
|
474 | allure.addAttachment(log.message, content, 'application/json');
|
475 | });
|
476 |
|
477 | this.on('runner:screenshot', function (command) {
|
478 |
|
479 | });
|
480 |
|
481 | this.on('hook:start', function (hook) {
|
482 | var allure = _this.getAllure(hook.cid);
|
483 |
|
484 | if (!allure.getCurrentSuite() || LOGGING_HOOKS.indexOf(hook.title) === -1) {
|
485 | return;
|
486 | }
|
487 |
|
488 | allure.startCase(hook.title);
|
489 | });
|
490 |
|
491 | this.on('hook:end', function (hook) {
|
492 | var allure = _this.getAllure(hook.cid);
|
493 |
|
494 | if (!allure.getCurrentSuite() || LOGGING_HOOKS.indexOf(hook.title) === -1) {
|
495 | return;
|
496 | }
|
497 |
|
498 | allure.endCase('passed');
|
499 |
|
500 | if (allure.getCurrentTest().steps.length === 0) {
|
501 | allure.getCurrentSuite().testcases.pop();
|
502 | }
|
503 | });
|
504 | }
|
505 |
|
506 | _createClass(AllureReporter, [{
|
507 | key: 'handleMetadata',
|
508 | value: function handleMetadata(meta) {
|
509 | var allure = this.getAllure(meta.cid);
|
510 | logger('test:meta', meta);
|
511 |
|
512 | if (!this.isAnyTestRunning(allure)) {
|
513 | error('ERROR', 'test:meta : NO TEST RUNNING');
|
514 | return;
|
515 | }
|
516 | var currentTest = allure.getCurrentTest();
|
517 |
|
518 |
|
519 | if (meta.description) {
|
520 | currentTest.setDescription(meta.description);
|
521 | }
|
522 |
|
523 | if (meta.feature) {
|
524 | if (typeof meta.feature === 'string') {
|
525 | currentTest.addLabel('feature', meta.feature);
|
526 | } else {
|
527 | for (var i in meta.feature) {
|
528 | currentTest.addLabel('feature', meta.feature[i]);
|
529 | }
|
530 | }
|
531 | }
|
532 | if (meta.story) {
|
533 | if (typeof meta.story === 'string') {
|
534 | currentTest.addLabel('story', meta.story);
|
535 | } else {
|
536 | for (var i in meta.story) {
|
537 | currentTest.addLabel('story', meta.story[i]);
|
538 | }
|
539 | }
|
540 | }
|
541 | if (meta.issue) {
|
542 | if (typeof meta.issue === 'string') {
|
543 | currentTest.addLabel('issue', meta.issue);
|
544 | } else {
|
545 | var _iteratorNormalCompletion = true;
|
546 | var _didIteratorError = false;
|
547 | var _iteratorError = undefined;
|
548 |
|
549 | try {
|
550 | for (var _iterator = _getIterator(meta.issue), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
551 | var issue = _step.value;
|
552 |
|
553 | currentTest.addLabel('issue', issue);
|
554 | }
|
555 | } catch (err) {
|
556 | _didIteratorError = true;
|
557 | _iteratorError = err;
|
558 | } finally {
|
559 | try {
|
560 | if (!_iteratorNormalCompletion && _iterator['return']) {
|
561 | _iterator['return']();
|
562 | }
|
563 | } finally {
|
564 | if (_didIteratorError) {
|
565 | throw _iteratorError;
|
566 | }
|
567 | }
|
568 | }
|
569 | }
|
570 | }
|
571 | if (meta.bug) {
|
572 | if (typeof meta.bug === 'string') {
|
573 | currentTest.addLabel('issue', this.getBug(meta.bug));
|
574 | currentTest.addLabel('bug', this.getBug(meta.bug));
|
575 | } else {
|
576 | var _iteratorNormalCompletion2 = true;
|
577 | var _didIteratorError2 = false;
|
578 | var _iteratorError2 = undefined;
|
579 |
|
580 | try {
|
581 | for (var _iterator2 = _getIterator(meta.bug), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
582 | var bug = _step2.value;
|
583 |
|
584 | currentTest.addLabel('issue', this.getBug(bug));
|
585 | currentTest.addLabel('bug', this.getBug(bug));
|
586 | }
|
587 | } catch (err) {
|
588 | _didIteratorError2 = true;
|
589 | _iteratorError2 = err;
|
590 | } finally {
|
591 | try {
|
592 | if (!_iteratorNormalCompletion2 && _iterator2['return']) {
|
593 | _iterator2['return']();
|
594 | }
|
595 | } finally {
|
596 | if (_didIteratorError2) {
|
597 | throw _iteratorError2;
|
598 | }
|
599 | }
|
600 | }
|
601 | }
|
602 | }
|
603 | if (meta.severity) {
|
604 | if (typeof meta.severity === 'string') {
|
605 | currentTest.addLabel('severity', meta.severity);
|
606 | } else {
|
607 | error('ERROR : meta.severity should be a string', meta);
|
608 | }
|
609 | }
|
610 |
|
611 | if (meta.argument) {
|
612 | if (typeof meta.argument === 'object') {
|
613 | var keys = _Object$keys(meta.argument);
|
614 | for (var i in keys) {
|
615 | var key = keys[i];
|
616 | var val = meta.argument[key];
|
617 | currentTest.addParameter('argument', key, val);
|
618 | }
|
619 | } else {
|
620 | error('ERROR : meta.argument should be an object { name2: val1, name2: val2.. }', meta);
|
621 | }
|
622 | }
|
623 | if (meta.environment) {
|
624 | if (typeof meta.environment === 'object') {
|
625 | var keys = _Object$keys(meta.environment);
|
626 | for (var i in keys) {
|
627 | var key = keys[i];
|
628 | var val = meta.environment[key];
|
629 | currentTest.addParameter('environment-variable', key, val);
|
630 | }
|
631 | } else {
|
632 | error('ERROR : meta.environment should be an object { name2: val1, name2: val2.. }', meta);
|
633 | }
|
634 | }
|
635 | }
|
636 | }, {
|
637 | key: 'getBug',
|
638 | value: function getBug(bug) {
|
639 | if (this.config.allure && this.config.allure.bugAppendix) {
|
640 | bug = '' + bug + this.config.allure.bugAppendix;
|
641 | }
|
642 | if (this.config.allure && this.config.allure.bugPrefix) {
|
643 | bug = '' + this.config.allure.bugPrefix + bug;
|
644 | }
|
645 | return bug;
|
646 | }
|
647 |
|
648 |
|
649 | }, {
|
650 | key: 'addArguments',
|
651 | value: function addArguments(test) {
|
652 | if (test.arguments) {
|
653 | for (var key in test.arguments) {
|
654 | if (test.arguments[key].value) {
|
655 | this.getAllure(test.cid).getCurrentTest().addParameter('argument', test.arguments[key].caption, test.arguments[key].value);
|
656 | }
|
657 | }
|
658 | }
|
659 | }
|
660 | }, {
|
661 | key: 'buildResultStr',
|
662 | value: function buildResultStr(results) {
|
663 | var str = '';
|
664 |
|
665 | str += results.passing.count + ' passing (~' + Math.round(results.passing.percentage) + '%)';
|
666 |
|
667 | if (results.skipped.count > 0) {
|
668 | str += ', ' + results.skipped.count + ' skipped (~' + Math.round(results.skipped.percentage) + '%)';
|
669 | }
|
670 |
|
671 | if (results.unvalidated.count > 0) {
|
672 | str += ', ' + results.unvalidated.count + ' unvalidated (~' + Math.round(results.unvalidated.percentage) + '%)';
|
673 | }
|
674 |
|
675 | if (results.failing.count > 0) {
|
676 | str += ', ' + results.failing.count + ' failing (~' + Math.round(results.failing.percentage) + '%)';
|
677 | }
|
678 |
|
679 | if (results.broken.count > 0) {
|
680 | str += ', ' + results.broken.count + ' broken (~' + Math.round(results.broken.percentage) + '%)';
|
681 | }
|
682 |
|
683 | return str;
|
684 | }
|
685 | }, {
|
686 | key: 'addResultsDummy',
|
687 | value: function addResultsDummy(test) {
|
688 | if (test.cid) {
|
689 | var allure = this.getAllure(test.cid);
|
690 | var currentTest = allure.getCurrentTest();
|
691 |
|
692 | this.testIds[currentTest] = true;
|
693 |
|
694 | currentTest.addParameter('environment-variable', 'TESTCASE RESULTS: ', 'TESTCASE_RESULTS_STR');
|
695 | currentTest.addParameter('environment-variable', 'SPEC RESULTS: ', 'SPEC_RESULTS_STR');
|
696 | }
|
697 | }
|
698 | }, {
|
699 | key: 'addResults',
|
700 | value: function addResults() {
|
701 | var tcResults = this.baseReporter.getTestcaseResults();
|
702 | var specResults = this.baseReporter.getSpecResults();
|
703 |
|
704 | var tcResultsStr = this.buildResultStr(tcResults);
|
705 | var specResultsStr = this.buildResultStr(specResults);
|
706 |
|
707 | var latestRun = fs.readFileSync(this.config.latestRunPath, 'utf8');
|
708 |
|
709 |
|
710 |
|
711 | getAllFiles(path.join(this.config.resultsPath, latestRun), '.xml').forEach(function (file) {
|
712 | var content = fs.readFileSync(file, 'utf8');
|
713 |
|
714 | content = content.replace(/TESTCASE_RESULTS_STR/g, tcResultsStr);
|
715 | content = content.replace(/SPEC_RESULTS_STR/g, specResultsStr);
|
716 |
|
717 | fs.unlinkSync(file);
|
718 |
|
719 | fs.writeFileSync(file, content, 'utf8');
|
720 | });
|
721 | }
|
722 | }, {
|
723 | key: 'getAllure',
|
724 | value: function getAllure(cid) {
|
725 | if (typeof cid === 'undefined') {
|
726 | cid = process.workflo.cid;
|
727 | } else {
|
728 | if (typeof process.workflo === 'undefined') {
|
729 | process.workflo = {};
|
730 | } else {
|
731 | process.workflo.currentCid = cid;
|
732 | }
|
733 | }
|
734 |
|
735 | if (this.allures[cid]) {
|
736 | return this.allures[cid];
|
737 | }
|
738 |
|
739 | var allure = new _allureJsCommonsWorkflo2['default']();
|
740 | allure.setOptions({ targetDir: this.options.outputDir || 'allure-results' });
|
741 | this.allures[cid] = allure;
|
742 | return this.allures[cid];
|
743 | }
|
744 | }, {
|
745 | key: 'isAnyTestRunning',
|
746 | value: function isAnyTestRunning(allure) {
|
747 | return allure.getCurrentSuite() && allure.getCurrentTest();
|
748 | }
|
749 | }, {
|
750 | key: 'dumpJSON',
|
751 | value: function dumpJSON(allure, name, json) {
|
752 | var jsonStr = JSON.stringify(json, null, ' ').split('\\"').join('\'').replace(/(?:\\n)/g, '');
|
753 | allure.addAttachment(name, jsonStr, 'application/json');
|
754 | }
|
755 | }]);
|
756 |
|
757 | return AllureReporter;
|
758 | })(_events2['default'].EventEmitter);
|
759 |
|
760 | var read = function read(dir) {
|
761 | return fs.readdirSync(dir).reduce(function (files, file) {
|
762 | return fs.statSync(path.join(dir, file)).isDirectory() ? files.concat(read(path.join(dir, file))) : files.concat(path.join(dir, file));
|
763 | }, []);
|
764 | };
|
765 |
|
766 | function getAllFiles(dirPath, extension) {
|
767 | return read(dirPath).filter(function (fileName) {
|
768 | return fileName.endsWith(extension);
|
769 | });
|
770 | }
|
771 |
|
772 | exports['default'] = AllureReporter;
|
773 | module.exports = exports['default'];
|