-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
123 lines (103 loc) · 2.97 KB
/
index.js
File metadata and controls
123 lines (103 loc) · 2.97 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
'use strict';
const { isObjectLiteral } = require('conjunction-junction');
const deepEqual = require('deep-equal');
const logger = require('log123').createLogger('./consolation-test.log', 'no-header');
const describe = (string, fn) => {
this.describeString = string;
fn();
};
const it = (string, fn) => {
this.itString = string;
fn();
};
const expect = (actual, logObjects=true) => {
// logger.info('this.describeString',this.describeString)
// logger.info('this.itString',this.itString)
return {
to: {
equal: expected => {
if(actual !== expected) {
logger.warn(`\nFAIL > > : "${this.describeString} / ${this.itString}", \n actual: ${actual} does not equal \n expected: ${expected}`);
return false;
}
logger.info(` OK (shlw) "${this.describeString} / ${this.itString}"`);
return true;
},
deep: {
equal: expected => {
if(actual === expected) {
logger.info(` OK (shlw) "${this.describeString} / ${this.itString}"`);
return true;
}
if(deepEqual(actual, expected)){
logger.info(` OK (deep) "${this.describeString} / ${this.itString}"`);
return true;
}
// fail
logger.warn(`\n....FAIL: "${this.describeString} / ${this.itString}"`);
const logIt =
isObjectLiteral(actual) && logObjects ||
isObjectLiteral(expected) && logObjects ||
Array.isArray(actual) && logObjects ||
Array.isArray(expected) && logObjects ||
actual === null ||
expected === null ||
actual === undefined ||
expected === undefined;
if(logIt){
logger.warn('....ACTUAL:\n', actual);
logger.warn('....EXPECTED:\n', expected);
} else {
logger.warn(`....actual: ${actual} does not deep equal \n....expected: ${expected}`);
}
return false;
}
}
}
};
};
module.exports = {
describe,
it,
expect,
testLog: logger,
};
// describe('a bunch of tests',()=>{
// it('fruits are equal', ()=>{
// expect('apple').to.equal('apple');
// });
// it('fruits are equal', ()=>{
// expect('apple').to.equal('apples');
// });
// });
// describe('more bunch of tests',()=>{
// it('plants are equal', ()=>{
// expect('tree').to.equal('bush');
// });
// it('cars are equal', ()=>{
// expect('Honda').to.equal('Toyota');
// });
// });
// describe('comparing objects',()=>{
// const a = {
// one: 1,
// two: 2,
// };
// const b = {
// one: 1,
// two: 2,
// };
// const c = {
// three: 3,
// four: 88,
// };
// it('objects identical but not equal', ()=>{
// expect(a).to.deep.equal(b);
// });
// it('objects are equal', ()=>{
// expect(a).to.deep.equal(a);
// });
// it('objects are NOT equal', ()=>{
// expect(a).to.deep.equal(c);
// });
// });