Repository navigation
Expand file tree
/
Copy pathtestSuite.js
More file actions
executable file
·74 lines (60 loc) · 1.78 KB
/
Copy pathtestSuite.js
File metadata and controls
executable file
·74 lines (60 loc) · 1.78 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
var Test = require("cloud/utils/test");
function TestSuite(name) {
this.name = name;
this.beforeFunc = function () {};
this.afterFunc = function () {};
this.beforeEachFunc = function () {};
this.afterEachFunc = function () {};
this.tests = [];
this.onlyFlag = false;
this.config = null;
}
TestSuite.prototype.before = function (func) {
this.beforeFunc = func;
};
TestSuite.prototype.beforeEach = function (func) {
this.beforeEachFunc = func;
};
TestSuite.prototype.afterEach = function (func) {
this.afterEachFunc = func;
};
TestSuite.prototype.it = function (name, func) {
if (this.onlyFlag) return;
this.tests.push(new Test(this.name + " " + name + ".", func));
};
TestSuite.prototype.xit = function () {};
TestSuite.prototype.only = function (name, func) {
this.tests = [];
this.onlyFlag = true;
this.tests.push(new Test(this.name + " " + name + ".", func));
};
TestSuite.prototype.run = function (success, error) {
var results = [],
_this = this,
i = 0,
currentTest;
Parse.Config.get().then(function (config) {
_this.config = config;
_this.beforeFunc();
function runNextTest() {
currentTest = _this.tests[i];
if (currentTest instanceof Test) {
_this.beforeEachFunc();
currentTest.run(function (result) {
results.push(result);
_this.afterEachFunc();
i++;
runNextTest();
})
} else {
_this.afterFunc();
success({
name: _this.name,
payload: results
});
}
}
runNextTest();
});
};
module.exports = TestSuite;