-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.js
More file actions
93 lines (81 loc) · 1.72 KB
/
test.js
File metadata and controls
93 lines (81 loc) · 1.72 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
/**
* Testing library.
* (C) 2013 Alex Fernández.
*/
import testing from './index.js'
/**
* Test success and failure.
*/
function testSuccessFailure(callback)
{
testing.success('success');
testing.failure('test; please ignore');
testing.removeError()
testing.success('Success and failure work', callback);
}
/**
* Test assert functions.
*/
function testAssert(callback)
{
testing.verify(1 + 1 == 2, 'Basic assert', callback);
testing.equals(1 + 1, 2, 'Basic assert equals', callback);
testing.equals({a: 'a'}, {a: 'a'}, 'Object assert equals', callback);
testing.notEquals(1 + 1, 3, 'Basic assert not equals', callback);
testing.notEquals({a: 'a'}, {a: 'b'}, 'Object assert not equals', callback);
testing.check(false, 'Check should not trigger', callback);
testing.success(callback);
}
/**
* A test which returns a complex object, to check how results are displayed.
*/
function testObject(callback)
{
const object = {
embedded: {
key: 'value',
},
};
testing.success(object, callback);
}
function sleep(ms) {
return new Promise(resolve => {
setTimeout(() => {
resolve()
}, ms)
})
}
async function testPromise()
{
await sleep(100)
return 'promise'
}
/**
* Function to test separately.
*/
function testSingleFunction(callback)
{
testing.success(true, callback);
}
/**
* Run all module tests.
*/
function testAll(callback) {
const tests = [
testSuccessFailure,
testAssert,
{
recursive: {
object: testObject,
},
},
testPromise,
];
testing.run(testSingleFunction, function(error, result)
{
testing.check(error, 'Could not run single function', callback);
testing.assert(result, 'Invalid test result', callback);
testing.run(tests, callback);
});
}
testAll(testing.show);