Repository navigation
Expand file tree
/
Copy pathsuite.js
More file actions
131 lines (105 loc) · 2.99 KB
/
Copy pathsuite.js
File metadata and controls
131 lines (105 loc) · 2.99 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
123
124
125
126
127
128
129
130
131
'use strict';
const _ = require('lodash');
function definePrivate(suite) {
Object.defineProperty(suite, '_states', {
value: []
});
Object.defineProperty(suite, '_children', {
value: []
});
}
module.exports = class Suite {
constructor(name) {
this.name = name;
this.url = null;
this.skipped = false;
this.captureSelectors = null;
this.tolerance = null;
this.ignoreSelectors = [];
this.beforeActions = [];
this.afterActions = [];
this.browsers = [];
this.context = {};
this.file = null;
definePrivate(this);
}
static create(name, parent) {
if (!parent) {
return new Suite(name);
}
if (_.isEmpty(name)) {
throw new Error('Empty suite name');
}
const suite = Object.create(parent);
definePrivate(suite);
suite.name = name;
suite.path = parent.path ? parent.path.concat(name) : [name];
suite.context = _.clone(parent.context);
return suite;
}
addState(state) {
state.suite = this;
this._states.push(state);
}
skip(browserSkipMatcher) {
if (this.skipped === true) {
return;
}
if (!browserSkipMatcher) {
this.skipped = true;
} else {
this.skipped = _.isArray(this.skipped)
? this.skipped.concat(browserSkipMatcher)
: [browserSkipMatcher];
}
}
clone() {
const clonedSuite = Suite.create(this.name, this.parent);
_.forOwn(this, (value, key) => {
clonedSuite[key] = _.clone(value);
});
this.children.forEach((child) => clonedSuite.addChild(child.clone()));
this.states.forEach((state) => clonedSuite.addState(state.clone()));
return clonedSuite;
}
hasChild(name, browsers) {
return _.some(this.children, (child) => {
return _.isEqual(child.name, name) && !_.isEmpty(_.intersection(child.browsers, browsers));
});
}
hasStateNamed(name) {
return _.some(this._states, {name: name});
}
get states() {
return this._states;
}
get children() {
return this._children;
}
addChild(child) {
Object.setPrototypeOf(child, this);
this._children.push(child);
}
removeChild(suite) {
const index = _.indexOf(this._children, suite);
if (index !== -1) {
Object.setPrototypeOf(suite, Suite.prototype);
this._children.splice(index, 1);
}
}
get hasStates() {
return this._states.length > 0;
}
get isRoot() {
return !this.parent;
}
get parent() {
const proto = Object.getPrototypeOf(this);
return proto === Suite.prototype ? null : proto;
}
get fullName() {
return this.isRoot
? this.name
: _.compact([this.parent.fullName, this.name]).join(' ');
}
};