forked from allure-framework/allure-js-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtime.js
85 lines (74 loc) · 2.32 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
'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(
that._allure.endStep.bind(that._allure, 'passed'),
that._allure.endStep.bind(that._allure, '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.getCurrentSuite().currentTest.addLabel(name, value);
};
Allure.prototype.description = function(description) {
this._allure.setDescription(description);
};
Allure.prototype.SEVERITY = {
BLOCKER: 'blocker',
CRITICAL: 'critical',
NORMAL: 'normal',
MINOR: 'minor',
TRIVIAL: 'trivial'
};
Allure.prototype.severity = function(severity) {
this.addLabel('severity', severity);
};
Allure.prototype.feature = function(feature) {
this.addLabel('feature', feature);
};
Allure.prototype.story = function(story) {
this.addLabel('story', story);
};
Allure.prototype._format = function(name, arr) {
return name.replace(/(\{(\d+)\})/gi, function(match, submatch, index) {
return arr[index];
});
};
module.exports = Allure;