Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
81 lines (63 loc) · 1.63 KB
/
Copy pathtest.js
File metadata and controls
81 lines (63 loc) · 1.63 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
// Total.js Tests
// The MIT License
// Copyright 2023 (c) Peter Širka <petersirka@gmail.com>
if (!global.Total)
require('total5');
var Test = { items: [], count: 0, fakes: {} };
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 });
};
// Replaces an action with a fake, the original action is kept for "Test.restore()"
Test.fake = function(name, obj) {
if (Test.fakes[name] === undefined) {
Test.fakes[name] = F.actions[name] || null;
delete F.actions[name];
}
return NEWACTION(name, obj);
};
// Removes all fakes and puts the original actions back
Test.restore = function() {
for (var name in Test.fakes) {
var action = Test.fakes[name];
F.actions[name] && F.actions[name].remove();
if (action)
F.actions[name] = action;
}
Test.fakes = {};
};
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
setTimeout(() => process.exit(0), 2);
});
};
global.Test = Test;