Skip to content

Commit 08a7dca

Browse files
committed
Fix up some tests, clarify benchmarks in readme
1 parent 272f6bf commit 08a7dca

6 files changed

+113
-83
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ console.log(result);
184184

185185
## Benchmarks
186186

187-
As of [morning, Friday, August 18, 2017](https://github.com/node-machine/machine/tree/35548a4a1425d5a21bff481470a615c0561a536b):
187+
As of [morning, Friday, August 18, 2017](https://github.com/node-machine/machine/tree/35548a4a1425d5a21bff481470a615c0561a536b), without any build-time normalization of definitions, and with runtime data type validation disabled:
188188

189189
```
190190
∑ NODE_ENV=production npm run bench

Diff for: test/exit-getExample.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var assert = require('assert');
22
var _ = require('@sailshq/lodash');
3-
var M = require('../lib/Machine.constructor');
3+
var M = require('../');
44

55
describe('Machine exits getExample', function() {
66

Diff for: test/exit-rttc.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
var util = require('util');
66
var _ = require('@sailshq/lodash');
77
var assert = require('assert');
8-
var Machine = require('../lib/Machine.constructor');
8+
var Machine = require('../');
99

1010
var runSuite = require('../node_modules/rttc/spec/helpers/run-suite');
1111
var TEST_SUITE = require('../node_modules/rttc/spec/coercion.spec.js');

Diff for: test/exit-usage.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var assert = require('assert');
22
var _ = require('@sailshq/lodash');
3-
var M = require('../lib/Machine.constructor');
3+
var M = require('../');
44

55
describe('Machine fn calling `exits()` (w/ different usages)', function() {
66

Diff for: test/input-rttc.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var assert = require('assert');
66
var util = require('util');
77
var Stream = require('stream');
88
var _ = require('@sailshq/lodash');
9-
var M = require('../lib/Machine.constructor');
9+
var M = require('../');
1010

1111
var runSuite = require('../node_modules/rttc/spec/helpers/run-suite');
1212
var TEST_SUITE = require('../node_modules/rttc/spec/validation.spec.js');

Diff for: test/like-and-itemOf.test.js

+108-78
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('`like` and `itemOf`', function (){
1313

1414
describe('using `like` in one of its exits', function (){
1515
testMachineWithMocha().machine(Machine.build({
16+
identity: 'test',
1617
inputs: { fullName: { example: 'Roger Rabbit' } },
1718
exits: { success: { like: 'fullName' } },
1819
fn: function (inputs, exits) { return exits.success(123); }
@@ -25,6 +26,7 @@ describe('`like` and `itemOf`', function (){
2526

2627
describe('and referenced input is configured with an invalid (and incompatible) input value', function (){
2728
testMachineWithMocha().machine(Machine.build({
29+
identity: 'test',
2830
inputs: { fullName: { example: 'Roger Rabbit' } },
2931
exits: { success: { like: 'fullName' } },
3032
fn: function (inputs, exits) { return exits.success(123); }
@@ -38,6 +40,7 @@ describe('`like` and `itemOf`', function (){
3840
it('should not .build() the machine if an input refers to another input w/ a `like` or `itemOf` instead of an example', function (){
3941
assert.throws(function (){
4042
Machine.build({
43+
identity: 'test',
4144
inputs: {
4245
fullName: { example: 'Roger Rabbit' },
4346
firstName: { like: 'fullName' },
@@ -49,6 +52,7 @@ describe('`like` and `itemOf`', function (){
4952

5053
assert.throws(function (){
5154
Machine.build({
55+
identity: 'test',
5256
inputs: {
5357
nameParts: { example: ['Roger'] },
5458
firstName: { itemOf: 'fullName' },
@@ -60,80 +64,87 @@ describe('`like` and `itemOf`', function (){
6064
});
6165
});
6266

63-
describe('using `like` in one of its inputs', function (){
64-
testMachineWithMocha().machine(Machine.build({
65-
inputs: {
66-
fullName: { example: 'Roger Rabbit' },
67-
firstName: { like: 'fullName' }
68-
},
69-
exits: { success: { example: '===' } },
70-
fn: function (inputs, exits) { return exits.success(inputs.firstName); }
71-
}))
72-
.use({ firstName: 123 })
73-
.expect({
74-
outcome: 'success',
75-
output: '123'
76-
});
67+
// No longer supported:
68+
// describe('using `like` in one of its inputs', function (){
69+
// testMachineWithMocha().machine(Machine.build({
70+
// identity: 'test',
71+
// inputs: {
72+
// fullName: { example: 'Roger Rabbit' },
73+
// firstName: { like: 'fullName' }
74+
// },
75+
// exits: { success: { example: '===' } },
76+
// fn: function (inputs, exits) { return exits.success(inputs.firstName); }
77+
// }))
78+
// .use({ firstName: 123 })
79+
// .expect({
80+
// outcome: 'success',
81+
// output: '123'
82+
// });
7783

78-
describe('and referenced input is configured with an invalid (and incompatible) input value', function (){
79-
testMachineWithMocha().machine(Machine.build({
80-
inputs: {
81-
fullName: { example: 'Roger Rabbit' },
82-
firstName: { like: 'fullName' }
83-
},
84-
exits: { success: { example: '===' } },
85-
fn: function (inputs, exits) { return exits.success(inputs.firstName); }
86-
}))
87-
.use({ firstName: 123, fullName: [] })
88-
.expect({
89-
outcome: 'error'
90-
});
91-
});
84+
// describe('and referenced input is configured with an invalid (and incompatible) input value', function (){
85+
// testMachineWithMocha().machine(Machine.build({
86+
// identity: 'test',
87+
// inputs: {
88+
// fullName: { example: 'Roger Rabbit' },
89+
// firstName: { like: 'fullName' }
90+
// },
91+
// exits: { success: { example: '===' } },
92+
// fn: function (inputs, exits) { return exits.success(inputs.firstName); }
93+
// }))
94+
// .use({ firstName: 123, fullName: [] })
95+
// .expect({
96+
// outcome: 'error'
97+
// });
98+
// });
9299

93100

94-
it('should not .build() the machine if an input refers to itself', function (){
95-
assert.throws(function (){
96-
Machine.build({
97-
inputs: {
98-
fullName: { example: 'Roger Rabbit' },
99-
firstName: { like: 'firstName' }
100-
},
101-
exits: { success: { example: '===' } },
102-
fn: function (inputs, exits) { return exits.error(); }
103-
});
104-
});
105-
});
101+
// it('should not .build() the machine if an input refers to itself', function (){
102+
// assert.throws(function (){
103+
// Machine.build({
104+
// identity: 'test',
105+
// inputs: {
106+
// fullName: { example: 'Roger Rabbit' },
107+
// firstName: { like: 'firstName' }
108+
// },
109+
// exits: { success: { example: '===' } },
110+
// fn: function (inputs, exits) { return exits.error(); }
111+
// });
112+
// });
113+
// });
106114

107-
it('should not .build() the machine if an input refers to another input w/ a `like` or `itemOf` instead of an example', function (){
108-
assert.throws(function (){
109-
Machine.build({
110-
inputs: {
111-
fullName: { example: 'Roger Rabbit' },
112-
lastName: { like: 'firstName' },
113-
firstName: { like: 'fullName' }
114-
},
115-
exits: { success: { example: '===' } },
116-
fn: function (inputs, exits) { return exits.error(); }
117-
});
118-
});
115+
// it('should not .build() the machine if an input refers to another input w/ a `like` or `itemOf` instead of an example', function (){
116+
// assert.throws(function (){
117+
// Machine.build({
118+
// identity: 'test',
119+
// inputs: {
120+
// fullName: { example: 'Roger Rabbit' },
121+
// lastName: { like: 'firstName' },
122+
// firstName: { like: 'fullName' }
123+
// },
124+
// exits: { success: { example: '===' } },
125+
// fn: function (inputs, exits) { return exits.error(); }
126+
// });
127+
// });
119128

120-
assert.throws(function (){
121-
Machine.build({
122-
inputs: {
123-
namePieces: { example: ['Roger'] },
124-
lastName: { itemOf: 'namePieces' },
125-
firstName: { like: 'lastName' }
126-
},
127-
exits: { success: { example: '===' } },
128-
fn: function (inputs, exits) { return exits.error(); }
129-
});
130-
});
131-
});
129+
// assert.throws(function (){
130+
// Machine.build({
131+
// identity: 'test',
132+
// inputs: {
133+
// namePieces: { example: ['Roger'] },
134+
// lastName: { itemOf: 'namePieces' },
135+
// firstName: { like: 'lastName' }
136+
// },
137+
// exits: { success: { example: '===' } },
138+
// fn: function (inputs, exits) { return exits.error(); }
139+
// });
140+
// });
141+
// });
132142

133-
});
143+
// });
134144

135145
describe('using `itemOf` in one of its exits', function (){
136146
testMachineWithMocha().machine(Machine.build({
147+
identity: 'test',
137148
inputs: {
138149
fullName: { example: ['Roger'] }
139150
},
@@ -148,23 +159,35 @@ describe('`like` and `itemOf`', function (){
148159
});
149160

150161
describe('using `itemOf` in one of its inputs', function (){
151-
testMachineWithMocha().machine(Machine.build({
152-
inputs: {
153-
fullName: { example: ['Roger'] },
154-
firstName: { itemOf: 'fullName' }
155-
},
156-
exits: { success: { example: '===' } },
157-
fn: function (inputs, exits) { return exits.success(inputs.firstName); }
158-
}))
159-
.use({ firstName: 123 })
160-
.expect({
161-
outcome: 'success',
162-
output: '123'
162+
it('should no longer work!', function(){
163+
try {
164+
testMachineWithMocha().machine(Machine.build({
165+
identity: 'test',
166+
inputs: {
167+
fullName: { example: ['Roger'] },
168+
firstName: { itemOf: 'fullName' }
169+
},
170+
exits: { success: { example: '===' } },
171+
fn: function (inputs, exits) { return exits.success(inputs.firstName); }
172+
}))
173+
.use({ firstName: 123 })
174+
.expect({
175+
outcome: 'success',
176+
output: '123'
177+
});
178+
} catch (err) {
179+
if (err.name === 'ImplementationError') {
180+
// ok that's what we expected.
181+
}
182+
else { throw err; }
183+
}
184+
throw new Error('should not have made it here');
163185
});
164186
});
165187

166188
describe('using `like` in one of its contract\'s exits', function (){
167189
testMachineWithMocha().machine(Machine.build({
190+
identity: 'test',
168191
inputs: {
169192
fullName: { example: 'Roger' },
170193
getFullName: {
@@ -175,7 +198,7 @@ describe('`like` and `itemOf`', function (){
175198
}
176199
}
177200
},
178-
exits: { success: { example: '===' } },
201+
exits: { success: { outputExample: '===' } },
179202
fn: function (inputs, exits) { return exits.success( inputs.getFullName().execSync() ); }
180203
}))
181204
.use({
@@ -191,6 +214,7 @@ describe('`like` and `itemOf`', function (){
191214

192215
describe('using `like` in one of its contract\'s inputs', function (){
193216
testMachineWithMocha().machine(Machine.build({
217+
identity: 'test',
194218
inputs: {
195219
fullName: { example: 'Roger' },
196220
getFullName: {
@@ -218,6 +242,7 @@ describe('`like` and `itemOf`', function (){
218242

219243
describe('using `itemOf` in one of its contract\'s exits', function (){
220244
testMachineWithMocha().machine(Machine.build({
245+
identity: 'test',
221246
inputs: {
222247
fullName: { example: ['Roger'] },
223248
getFullName: {
@@ -244,6 +269,7 @@ describe('`like` and `itemOf`', function (){
244269

245270
describe('using `itemOf` in one of its contract\'s inputs', function (){
246271
testMachineWithMocha().machine(Machine.build({
272+
identity: 'test',
247273
inputs: {
248274
fullName: { example: ['Roger'] },
249275
getFullName: {
@@ -271,6 +297,7 @@ describe('`like` and `itemOf`', function (){
271297

272298
describe('using `like` in one of its contract\'s inputs\' contract\'s exits', function (){
273299
testMachineWithMocha().machine(Machine.build({
300+
identity: 'test',
274301
inputs: {
275302
fullName: { example: 'Roger' },
276303
getFullName: {
@@ -312,6 +339,7 @@ describe('`like` and `itemOf`', function (){
312339

313340
describe('using `like` in one of its contract\'s inputs\' contract\'s inputs', function (){
314341
testMachineWithMocha().machine(Machine.build({
342+
identity: 'test',
315343
inputs: {
316344
fullName: { example: 'Roger' },
317345
getFullName: {
@@ -354,6 +382,7 @@ describe('`like` and `itemOf`', function (){
354382

355383
describe('using `itemOf` in one of its contract\'s inputs\' contract\'s exits', function (){
356384
testMachineWithMocha().machine(Machine.build({
385+
identity: 'test',
357386
inputs: {
358387
fullName: { example: ['Roger'] },
359388
getFullName: {
@@ -395,6 +424,7 @@ describe('`like` and `itemOf`', function (){
395424

396425
describe('using `itemOf` in one of its contract\'s inputs\' contract\'s inputs', function (){
397426
testMachineWithMocha().machine(Machine.build({
427+
identity: 'test',
398428
inputs: {
399429
fullName: { example: ['Roger'] },
400430
getFullName: {

0 commit comments

Comments
 (0)