This repository has been archived by the owner on Nov 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
it.js
72 lines (58 loc) · 1.67 KB
/
it.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict';
(function() {
var root = this;
var isNode = typeof exports !== 'undefined';
if (isNode) {
var chalk = require('chalk');
}
var it = function(description, test) {
return new Promise((resolve, reject) => {
var failed = false;
var testFN = {
done: function() {
if (!failed) {
if (!isNode) {
document.querySelector('#success').innerHTML += 'Passed test: It '+ description + '<br>';
} else {
console.log(chalk.green('Passed test: It '+ description));
}
resolve();
}
},
fail: function(msg) {
if (!isNode) {
document.querySelector('#error').innerHTML = 'Failed test: It '+ description + '.<br>('+msg+')<br>';
} else {
console.log(chalk.red('Failed test: It '+ description + '\n ('+msg+')'));
}
failed = true;
reject();
}
};
try {
if (test.call(testFN) === false) {
throw new Error('Failed test: It '+ description);
reject();
}
} catch (err) {
reject();
if (!isNode) {
document.querySelector('#error').innerHTML = 'Failed test: It '+ description + '<br>';
document.querySelector('#error').innerHTML += err.stack;
} else {
console.log(chalk.red('Failed test: It '+ description));
console.log(chalk.red(err));
}
throw err;
}
});
}
if (isNode) {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = it;
}
exports.it = it;
} else {
root.it = it;
}
}).call(this);