-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.js
51 lines (43 loc) · 1.04 KB
/
test.js
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
// Total.js Tests
// The MIT License
// Copyright 2023 (c) Peter Širka <petersirka@gmail.com>
var Test = { items: [], count: 0 };
Test.start = function(message) {
var divider = '------------------------------------------------';
if (Test.count)
console.log('');
console.log(divider);
console.log('> ' + message.padRight(divider.length - 4) + ' <');
console.log(divider);
};
Test.print = function(message, err) {
console.log('[' + (err ? 'FAIL' : 'OK') + ']', message);
Test.count++;
if (err) {
setTimeout(() => process.exit(1), 1);
if (err instanceof Error)
throw err;
else
throw new Error(err.toString());
}
};
Test.push = function(name, fn) {
Test.items.push({ name: name, fn: fn });
};
Test.run = function(callback) {
console.time('Time');
Test.items.wait(function(item, next) {
Test.start(item.name);
item.fn(next);
}, function() {
console.log('');
console.log('Tests:', Test.count);
console.timeEnd('Time');
console.log('');
if (callback)
callback();
else
process.exit(0);
});
};
global.Test = Test;