-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackender-testbuilder.js
More file actions
78 lines (71 loc) · 1.71 KB
/
Copy pathbackender-testbuilder.js
File metadata and controls
78 lines (71 loc) · 1.71 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
require('app-module-path').addPath(__dirname);
var ls = require('list-directory-contents');
var _ = require('underscore');
function profile(func, key) {
return function () {
var returnVal = func.apply(this, arguments);
var tmpTest = arguments[0];
tmpTest.screenshot('./report/dalek/details/' + key + '.png');
return returnVal;
};
}
var factory = function (stepdir, f) {
return function (test) {
var tests = {};
console.log("step directory");
console.log(stepdir);
ls(stepdir, function (err, tree) {
console.log("DIR TREE");
console.log(tree);
tree.map(function (o) {
console.log("LOOKING INTO STEP");
console.log('./' + o);
var obj = require( '..\\..\\' +o)(test);
tests = _.extend(tests, obj);
});
for (var key in tests) {
if (!tests.hasOwnProperty(key)) {
continue;
}
test[key] = tests[key];
}
f && f(test);
test.done();
});
};
};
var allTrue = function (obj) {
for (var o in obj)
if (!obj[o])
return false;
return true;
}
var runStepIfDifferentFrom = function (test, ex, testName, testArg) {
if (!ex) {
throw 'Please enter an exception to step : ' + '"fill out all other parts of the redemption form correctly except"'
}
if (typeof ex === 'string') {
ex = [ex];
}
var canRun = allTrue(ex.map(function (o) {
return ex != testName;
}));
canRun && test[testName](testArg);
};
var builder={};
builder.helper={
runStepIfDifferentFrom:runStepIfDifferentFrom
};
builder.steps=function (stepdir) {
return function (tests) {
var payload = {};
for (var key in tests) {
if (!tests.hasOwnProperty(key)) {
continue;
}
payload[key] = factory(stepdir, profile(tests[key], key));
}
return payload;
};
};
module.exports = builder;