123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- /**
- * Module dependencies
- */
- var util = require('util');
- var assert = require('assert');
- var Machine = require('../');
- describe('flow control & artificial delay', function (){
- describe('given a machine with an asynchronous implementation', function () {
- describe('that declares itself synchronous', function () {
- var NM_DEF_FIXTURE = {
- sync: true,
- inputs: {},
- fn: function (inputs, exits){
- var sum = 1;
- setTimeout(function (){
- sum++;
- return exits.success(sum);
- }, 50);
- }
- };
- describe('calling .execSync()', function () {
- it('should throw a predictable error', function (){
- try {
- Machine.build(NM_DEF_FIXTURE).execSync();
- } catch (e) {
- // console.log('->',e);
- assert.equal(e.code,'E_MACHINE_INCONSISTENT');
- return;
- }//-•
- throw new Error('Expected an error, but instead it was successful.');
- });//</it>
- });//</describe :: calling .execSync()>
- describe('calling .exec()', function () {
- // FUTURE: make this cause an error instead of working-- eg. make this test pass:
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- it.skip('should throw a predictable error', function (done){
- Machine.build(NM_DEF_FIXTURE).exec(function (err){
- if (err) {
- // console.log('->',err);
- try {
- assert.equal(err.code,'E_MACHINE_INCONSISTENT');
- } catch (e) { return done(e); }
- return done();
- }
- return done(new Error('Expected an error, but instead it was successful.'));
- });//<.exec()>
- });//</it>
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- });//</describe :: calling .exec()>
- });//</describe :: that declares itself synchronous>
- describe('that DOES NOT declare itself synchronous', function () {
- var NM_DEF_FIXTURE = {
- inputs: {},
- fn: function (inputs, exits){
- var sum = 1;
- setTimeout(function (){
- sum++;
- return exits.success(sum);
- }, 50);
- }
- };
- describe('calling .execSync()', function () {
- it('should throw a predictable error', function (){
- try {
- Machine.build(NM_DEF_FIXTURE).execSync();
- } catch (e) {
- // console.log('->',e);
- assert.equal(e.code,'E_USAGE');
- return;
- }//-•
- throw new Error('Expected an error, but instead it was successful.');
- });//</it>
- });//</describe :: calling .execSync()>
- describe('calling .exec()', function () {
- it('should succeed, and should yield before triggering callback', function (done){
- var didYield;
- Machine.build(NM_DEF_FIXTURE).exec(function (err){
- if (err) { return done(err); }
- try {
- assert(didYield, new Error('Should have "yielded"!'));
- } catch (e) { return done(e); }
- return done();
- });//<.exec()>
- didYield = true;
- });//</it>
- });//</describe :: calling .exec()>
- });//</describe :: that DOES NOT declare itself synchronous>
- });//</describe :: given a machine with an asynchronous implementation>
- describe('given a machine with a synchronous implementation', function () {
- describe('that declares itself synchronous', function () {
- var NM_DEF_FIXTURE = {
- sync: true,
- inputs: {},
- fn: function (inputs, exits){
- var sum = 1+1;
- return exits.success(sum);
- }
- };
- describe('calling .execSync()', function () {
- it('should succeed', function (){
- Machine.build(NM_DEF_FIXTURE).execSync();
- });//</it>
- });//</describe :: calling .execSync()>
- describe('calling .exec()', function () {
- it('should succeed, and should yield before triggering callback', function (done){
- var didYield;
- Machine.build(NM_DEF_FIXTURE).exec(function (err){
- if (err) { return done(err); }
- try {
- assert(didYield, new Error('Should have "yielded"!'));
- } catch (e) { return done(e); }
- return done();
- });//<.exec()>
- didYield = true;
- });//</it>
- });//</describe :: calling .exec()>
- });//</describe :: that declares itself synchronous>
- describe('that DOES NOT declare itself synchronous', function () {
- var NM_DEF_FIXTURE = {
- inputs: {},
- fn: function (inputs, exits){
- var sum = 1+1;
- return exits.success(sum);
- }
- };
- describe('calling .execSync()', function () {
- it('should throw a predictable error', function (){
- try {
- Machine.build(NM_DEF_FIXTURE).execSync();
- } catch (e) {
- // console.log('->',e);
- assert.equal(e.code,'E_USAGE');
- return;
- }//-•
- throw new Error('Expected an error, but instead it was successful.');
- });//</it>
- });//</describe :: calling .execSync()>
- describe('calling .exec()', function () {
- it('should succeed, and should yield before triggering callback', function (done){
- var didYield;
- Machine.build(NM_DEF_FIXTURE).exec(function (err){
- if (err) { return done(err); }
- try {
- assert(didYield, new Error('Should have "yielded"!'));
- } catch (e) { return done(e); }
- return done();
- });//<.exec()>
- didYield = true;
- });//</it>
- });//</describe :: calling .exec()>
- });//</describe :: that DOES NOT declare itself synchronous>
- });//</describe :: given a machine with a synchronous implementation>
- });//</describe :: flow control & artificial delay>
|