Repository navigation
Expand file tree
/
Copy pathsuite.js
More file actions
122 lines (100 loc) · 2.66 KB
/
Copy pathsuite.js
File metadata and controls
122 lines (100 loc) · 2.66 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
'use strict';
var inherit = require('inherit'),
_ = require('lodash');
function definePrivate(suite) {
Object.defineProperty(suite, '_states', {
value: []
});
Object.defineProperty(suite, '_children', {
value: []
});
}
var Suite = inherit({
__constructor: function(name) {
this.name = name;
this.url = null;
this.skipped = false;
this.captureSelectors = null;
this.tolerance = null;
this.ignoreSelectors = [];
this.beforeHook = function() {};
this.afterHook = function() {};
this.postActions = [];
this.browsers = [];
definePrivate(this);
},
addState: function(state) {
this._states.push(state);
},
addPostActions: function(actions) {
if (actions) {
this.postActions.push(actions);
}
},
runPostActions: function() {
var _this = this;
if (this.postActions.length > 0) {
return this.postActions[0].perform()
.then(function() {
_this.postActions = [];
});
}
},
skip: function(browserSkipMatcher) {
if (this.skipped === true) {
return;
}
if (!browserSkipMatcher) {
this.skipped = true;
} else {
this.skipped = _.isArray(this.skipped)
? this.skipped.concat(browserSkipMatcher)
: [browserSkipMatcher];
}
},
hasChildNamed: function(name) {
return _.some(this._children, {name: name});
},
hasStateNamed: function(name) {
return _.some(this._states, {name: name});
},
get states() {
return this._states;
},
get children() {
return this._children;
},
addChild: function(suite) {
suite.parent = this;
this._children.push(suite);
},
removeChild: function(suite) {
var index = _.indexOf(this._children, suite);
if (index !== -1) {
suite.parent = null;
this._children.splice(index, 1);
}
},
get hasStates() {
return this._states.length > 0;
},
get isRoot() {
return !this.parent;
},
get fullName() {
return this.isRoot
? this.name
: _.compact([this.parent.fullName, this.name]).join(' ');
}
});
exports.create = function createSuite(name, parent) {
if (!parent) {
return new Suite(name);
}
var suite = Object.create(parent);
definePrivate(suite);
suite.name = name;
suite.path = parent.path? parent.path.concat(name) : [name];
parent.addChild(suite);
return suite;
};