This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathindex.js
100 lines (83 loc) · 2.95 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'use strict';
var assign = require('object-assign'),
Suite = require('./beans/suite'),
Test = require('./beans/test'),
Step = require('./beans/step'),
Attachment = require('./beans/attachment'),
util = require('./util'),
writer = require('./writer');
function Allure() {
this.suites = [];
this.options = {
targetDir: 'allure-results'
};
}
Allure.prototype.setOptions = function(options) {
assign(this.options, options);
};
Allure.prototype.getCurrentSuite = function() {
return this.suites[0];
};
Allure.prototype.getCurrentTest = function() {
return this.getCurrentSuite().currentTest;
};
Allure.prototype.startSuite = function(suiteName, timestamp) {
this.suites.unshift(new Suite(suiteName, timestamp));
};
Allure.prototype.endSuite = function(timestamp) {
var suite = this.getCurrentSuite();
suite.end(timestamp);
if(suite.hasTests()) {
writer.writeSuite(this.options.targetDir, suite);
}
this.suites.shift();
};
Allure.prototype.startCase = function(testName, timestamp) {
var test = new Test(testName, timestamp),
suite = this.getCurrentSuite();
suite.currentTest = test;
suite.currentStep = test;
suite.addTest(test);
};
Allure.prototype.endCase = function(status, err, timestamp) {
this.getCurrentTest().end(status, err, timestamp);
};
Allure.prototype.startStep = function(stepName, timestamp) {
var step = new Step(stepName, timestamp),
suite = this.getCurrentSuite();
if (!suite || !suite.currentStep) {
console.warn('allure-js-commons: Unexpected startStep() of ' + stepName + '. There is no parent step');
return;
}
step.parent = suite.currentStep;
step.parent.addStep(step);
suite.currentStep = step;
};
Allure.prototype.endStep = function(status, timestamp) {
var suite = this.getCurrentSuite();
if (!suite || !(suite.currentStep instanceof Step)) {
console.warn('allure-js-commons: Unexpected endStep(). There is no running step');
return;
}
suite.currentStep.end(status, timestamp);
suite.currentStep = suite.currentStep.parent;
};
Allure.prototype.setDescription = function(description, type) {
this.getCurrentTest().setDescription(description, type);
};
Allure.prototype.addAttachment = function(attachmentName, buffer, type) {
var info = util.getBufferInfo(buffer, type),
name = writer.writeBuffer(this.options.targetDir, buffer, info.ext),
attachment = new Attachment(attachmentName, name, buffer.length, info.mime),
currentStep = this.getCurrentSuite().currentStep;
if (currentStep) {
currentStep.addAttachment(attachment);
} else {
console.warn('Trying to add attachment ' + attachmentName + ' to non-existent step');
}
};
Allure.prototype.pendingCase = function(testName, timestamp) {
this.startCase(testName, timestamp);
this.endCase('pending', {message: 'Test ignored'}, timestamp);
};
module.exports = Allure;