-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration-test.js
67 lines (52 loc) · 1.18 KB
/
integration-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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var isograte = require('./index')
var isolate = isograte.isolate
var integrate = isograte.integrate
const mock = {
one: function() {
throw new Error('Called one')
},
two: function() {
throw new Error('Called two')
}
}
function impureOne(x) {
return mock.one(x)
}
var isolatedOne = isolate(impureOne, 'one')
function impureTwo(x) {
isolatedOne()
return mock.two(x)
}
var isolatedTwo = isolate(impureTwo, 'two')
if (isolatedOne() !== 'one') {
throw new Error('improper return value')
}
if (isolatedTwo() !== 'two') {
throw new Error('improper return value')
}
mock.one = function(x) {
return x
}
mock.two = function(x) {
return x
}
var _impureOne = integrate(isolatedOne)
var _impureTwo = integrate(isolatedTwo)
if(_impureOne(2) !== 2) {
console.log(_impureOne(2))
throw new Error('Integration failed')
}
mock.one = function() {
throw new Error('should not call this')
}
if (_impureTwo(2) !== 2) {
console.log(_impureTwo(2))
throw new Error('Integration failed')
}
if (isolatedOne() !== 'one') {
throw new Error('improper return value')
}
if (isolatedTwo() !== 'two') {
throw new Error('improper return value')
}
console.log('Passed all integration tests')