-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathexecSync.test.js
182 lines (165 loc) · 4.13 KB
/
execSync.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
var assert = require('assert');
var Machine = require('../');
describe('Machine.prototype.execSync()', function (){
it('should throw when called on a machine that does not declare sync:true', function (){
try {
Machine.build(machineFixtures[0]).execSync();
}
catch (e) {
assert.equal(e.code,'E_USAGE');
return;
}
// Should never make it here
assert(false, 'Should have thrown an error');
});
it('should return the expected value when called on a configured machine that triggers its success exit', function (){
var result = Machine.build(machineFixtures[1]).execSync();
assert.equal(result,'stuff');
});
it('should throw an Error when called on a configured machine that triggers any non-success exit and sends back an Error instance', function (){
var m = Machine.build(machineFixtures[2]);
m.configure({value: 'hi'});
assert.throws(function (){
m.execSync();
});
});
it('should throw an Error when called on a configured machine that triggers any non-success exit and sends back a string', function (){
var m = Machine.build(machineFixtures[2]);
m.configure({value: 'hi'});
assert.throws(function (){
m.execSync();
});
});
it('should throw an Error when called on a configured machine that triggers any non-success exit and sends back a boolean', function (){
var m = Machine.build(machineFixtures[2]);
m.configure({value: true});
assert.throws(function (){
m.execSync();
});
});
it('should throw an Error when called on a configured machine that triggers any non-success exit and sends back a number', function (){
var m = Machine.build(machineFixtures[2]);
m.configure({value: -234.2});
assert.throws(function (){
m.execSync();
});
});
it('should throw an Error when called on a configured machine that triggers any non-success exit and sends back an array', function (){
var m = Machine.build(machineFixtures[2]);
m.configure({value: ['stuff', 'and', 'things']});
assert.throws(function (){
m.execSync();
});
});
it('should throw an Error when called on a configured machine that triggers any non-success exit and sends back an object', function (){
var m = Machine.build(machineFixtures[2]);
m.configure({value: {
email: '[email protected]'
}});
assert.throws(function (){
m.execSync();
});
});
});
var machineFixtures = [
// (0)
// Standard asynchronous machine
{
inputs: {
foo: {
example: 100
},
bar: {
example: 'foobar'
}
},
exits: {
success: {
example: 'hello'
},
error: {
example: 'world'
}
},
fn: function (inputs, exits) {
exits.success('stuff');
}
},
// (1)
// Same machine as above, but with sync:true
{
sync: true,
inputs: {
foo: {
example: 100
},
bar: {
example: 'foobar'
}
},
exits: {
success: {
example: 'hello'
},
error: {
example: 'world'
}
},
fn: function (inputs, exits) {
exits.success('stuff');
}
},
// (2)
// Sync machine which calls a non-success exit with whatever
// was passed into the `value` input.
{
sync: true,
inputs: {
value: {
typeclass: '*'
}
},
exits: {
success: {
example: 'hello'
},
someOtherExit: {
getExample: function (inputs){
return inputs.value;
}
},
error: {
example: 'world'
}
},
fn: function (inputs, exits) {
exits.someOtherExit(inputs.value);
}
},
// (3)
// Sync machine which calls a non-success exit with a new Error.
{
sync: true,
inputs: {
value: {
typeclass: '*'
}
},
exits: {
success: {
example: 'hello'
},
someOtherExit: {
getExample: function (inputs){
return inputs.value;
}
},
error: {
example: 'world'
}
},
fn: function (inputs, exits) {
exits.someOtherExit(new Error('deliberate error'));
}
}
];