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 40
/
runtime.js
106 lines (90 loc) · 2.83 KB
/
runtime.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
101
102
103
104
105
106
'use strict';
var Allure = function(allure) {
this._allure = allure;
};
Allure.prototype.isPromise = function(obj) {
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
};
Allure.prototype.createStep = function(name, stepFunc) {
var that = this;
return function() {
var stepName = that._format(name, Array.prototype.slice.call(arguments, 0)),
status = 'passed',
result;
that._allure.startStep(stepName);
try {
result = stepFunc.apply(this, arguments);
}
catch(error) {
status = 'broken';
throw error;
}
finally {
if(that.isPromise(result)) {
result.then(function() {
that._allure.endStep('passed');
}, function() {
that._allure.endStep('broken');
});
} else {
that._allure.endStep(status);
}
}
return result;
};
};
Allure.prototype.createAttachment = function(name, content, type) {
var that = this;
if(typeof content === 'function') {
return function() {
var attachmentName = that._format(name, Array.prototype.slice.call(arguments, 0)),
buffer = content.apply(this, arguments);
return that.createAttachment(attachmentName, buffer, type);
};
} else {
return that._allure.addAttachment(name, content, type);
}
};
Allure.prototype.addLabel = function(name, value) {
this._allure.getCurrentTest().addLabel(name, value);
};
Allure.prototype.addArgument = function(name, value) {
this._allure.getCurrentTest().addParameter('argument', name, value);
};
Allure.prototype.addEnvironment = function(name, value) {
this._allure.getCurrentTest().addParameter('environment-variable', name, value);
};
Allure.prototype.description = function(description, type) {
this._allure.setDescription(description, type);
};
Allure.prototype.SEVERITY = {
BLOCKER: 'blocker',
CRITICAL: 'critical',
NORMAL: 'normal',
MINOR: 'minor',
TRIVIAL: 'trivial'
};
Allure.prototype.severity = function(severity) {
this.addLabel('severity', severity);
};
Allure.prototype.epic = function(epic) {
this.addLabel('epic', epic);
};
Allure.prototype.feature = function(feature) {
this.addLabel('feature', feature);
};
Allure.prototype.story = function(story) {
this.addLabel('story', story);
};
Allure.prototype.issue = function(value) {
this.addLabel('issue', value);
};
Allure.prototype.testId = function(value) {
this.addLabel('testId', value);
};
Allure.prototype._format = function(name, arr) {
return name.replace(/(\{(\d+)\})/gi, function(match, submatch, index) {
return arr[index];
});
};
module.exports = Allure;