Synchronous Vows #162

Closed
wants to merge 1 commit into
from

2 participants

@seebees

Array literal and 'next' are syntactic sugar for nested Context.

This should make it easy to run Synchronous vows without a nesting headache.

Detail below, Fixes #53

This is not ready to merge, but I'm off my plane and would like someone to comment before going farther.
Also, the addition of synchronous tests almost make we want to copy the vows-tests.js and re-write every case. Hopefully I don't need to be that crazy.

context.js
Context is now an EventEmitter
Each Context knows it's children and parent
Each Context also receive an array of vows.
addVow added to Context.prototype to push vow onto Context.
nextTopics added to Context.prototype to handle new 'next' declaration to use in synchronous Context
tryEnd added to Context.prototype to emit event when this Context (and all it's children) are 'complete'

vows.js
vow.binding.context.addVow, need to add the vow to the Context
vows.tryEnd(batch, vow), need to pass the vow to tryEnd so we can call Context.tryEnd(vow)

suite.js
added 'next' to all Object.keys(tests).filter
you can not have both a topic and a next declaration
the topic when running all vows is: topic || next. Need a bit of logic magic to make this work
use ctx.nextTopics() to get the right topics to pass to the topic function
add a uuid to the vow object. (need a better implementation then Math.random())
if Array.isArray(ctx.tests) we may need to waitForSibling (this is that for the sake of which we did all this)
tryEnd is defined here, added a vow param, and if we have one, tryEnd the Context

@seebees seebees Synchronous Vows
Array literal and 'next' are syntactic sugar for nested Context.

This should make it easy to run Synchronous vows without a nesting headache.

context.js
  Context is now an EventEmitter
  Each Context knows it's children and parent
  Each Context also receive an array of vows.
  addVow added to Context.prototype to push vow onto Context.
  nextTopics added to Context.prototype to handle new 'next' declaration to use in synchronous Context
  tryEnd added to Context.prototype to emit event when this Context (and all it's children) are 'complete'

vows.js
  vow.binding.context.addVow, need to add the vow to the Context
  vows.tryEnd(batch, vow), need to pass the vow to tryEnd so we can call Context.tryEnd(vow)

suite.js
  added 'next' to all Object.keys(tests).filter
  you can not have both a topic and a next declaration
  the topic when running all vows is: topic || next.  Need a bit of logic magic to make this work
  use ctx.nextTopics() to get the right topics to pass to the topic function
  add a uuid to the vow object.  (need a better implementation then Math.random())
  if Array.isArray(ctx.tests) we may need to waitForSibling (this is that for the sake of which we did all this)
  tryEnd is defined here, added a vow param, and if we have one, tryEnd the Context
4384867
@indexzero
vowsjs member

@seebees Could you provider some sample usage about how this change would affect writing vows based tests?

@seebees

@indexzero is this what you are looking for?

Most importantly, there should be no change to existing vows. Once the syntax/idea is approved I would want people to be able to write things like:

vows.describe("Simple Syncronous Vows").addBatch([
{
  topic: someTopic,
  "some vow": function(ret) {/*check*/}
},
{
  next: function(lastTopic) {/*do next thing*/},
  "some other vow": function(ret) {/*check*/}
}]);

I'm really doing this in response to the request in #53. So if you want it to work some other way let me know. After this, I'm thinking TAP output...

@indexzero
vowsjs member

💯 this will go into 0.9.0

@indexzero indexzero closed this Nov 4, 2014
@indexzero
vowsjs member

Whoops! Didn't mean to close that.

@indexzero indexzero reopened this Nov 4, 2014
@indexzero indexzero added the v0.9.0 label Nov 4, 2014
@indexzero
vowsjs member

Cherry-picked into the v0.9.x branch. Boy was that hard to merge three years later!

@indexzero indexzero closed this Nov 22, 2014
@indexzero indexzero referenced this pull request Nov 22, 2014
Merged

v0.9.0-rc1 #328

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment