This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathtests-api.js
More file actions
69 lines (58 loc) · 1.84 KB
/
Copy pathtests-api.js
File metadata and controls
69 lines (58 loc) · 1.84 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
'use strict';
var Suite = require('./suite'),
State = require('./state');
function nothing() {}
function makeSkipBrowser(browser) {
if (typeof browser === 'string') {
return {name: browser};
}
return browser;
}
function SuiteBuilder(suite) {
this.setCaptureElements = function() {
if (arguments.length === 1 && Array.isArray(arguments[0])) {
suite.captureSelectors = arguments[0];
} else {
suite.captureSelectors = Array.prototype.slice.call(arguments);
}
return this;
};
this.before = function(hook) {
suite.beforeHook = hook;
return this;
};
this.setUrl = function setUrl(url) {
suite.url = url;
return this;
};
this.capture = function capture(name, cb) {
cb = cb || nothing;
suite.addState(new State(suite, name, cb));
return this;
};
this.skip = function skip(browser) {
if (!browser) {
suite.skip();
} else if (Array.isArray(browser)) {
suite.skip(browser.map(makeSkipBrowser));
} else if (typeof browser === 'string' || typeof browser === 'object') {
suite.skip([makeSkipBrowser(browser)]);
} else {
throw new Error('Unacceptable value for .skip method: ' + browser);
}
return this;
};
}
module.exports = function(context, rootSuite) {
context.suite = function suite(name, callback) {
if (typeof name !== 'string') {
throw new Error('First argument of the .suite must be a string');
}
if (typeof callback !== 'function') {
throw new Error('Second argument of the .suite must be a function');
}
rootSuite = Suite.create(name, rootSuite);
callback(new SuiteBuilder(rootSuite));
rootSuite = rootSuite.parent;
};
};