Skip to content

Commit 1b02c0a

Browse files
Matt LyonAlexis Sellier
Matt Lyon
authored and
Alexis Sellier
committed
bugfix: only add setup vals to context once
see test case, this was failing before because it was overwriting the previous context value.
1 parent d83b203 commit 1b02c0a

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

lib/vows.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,11 @@ vows.tell = function (topic, tests) {
220220
// functions have access to all the previous context topics in their
221221
// arguments list.
222222
// It is defined and invoked at the same time.
223-
// If it encouters a `setup` function, it waits for the returned
223+
// If it encounters a `setup` function, it waits for the returned
224224
// promise to emit (the topic), at which point it runs the functions under it,
225225
// passing the topic as an argument.
226226
(function run(ctx) {
227+
var ctxAdded = false;
227228
if (typeof(ctx.tests["setup"]) === 'function') {
228229
// Run the setup, passing the previous context topics
229230
setup = ctx.tests.setup.apply(this, ctx.topics);
@@ -237,6 +238,13 @@ vows.tell = function (topic, tests) {
237238
return function () { emitter.emit("success", val) };
238239
}(setup)); setup = emitter;
239240
}
241+
242+
setup.addListener('success', function (val) {
243+
// Once the setup fires, add the return value
244+
// to the beginning of the topics list, so it
245+
// becomes the first argument for the next setup.
246+
ctx.topics.unshift(val);
247+
});
240248
} else { setup = null }
241249

242250
// Now run the tests, or sub-contexts
@@ -260,10 +268,6 @@ vows.tell = function (topic, tests) {
260268
if (setup) {
261269
setup.addListener("success", function (vow, ctx) {
262270
return function (val) {
263-
// Once the setup fires, add the return value
264-
// to the beginning of the topics list, so it
265-
// becomes the first argument for the next setup.
266-
ctx.topics.unshift(val);
267271
return run(new(Context)(vow, ctx));
268272
};
269273
}(vow, ctx));

test/vows-test.js

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ vows.tell("Vows", {
5858
"the parent topics": function (topics) {
5959
assert.equal(topics.join(), [4, 3, 2, 1].join());
6060
}
61+
},
62+
63+
"from": {
64+
setup: function (c, b, a) { return promiser([4, c, b, a])() },
65+
66+
"the parent topics": function(topics) {
67+
assert.equal(topics.join(), [4, 3, 2, 1].join());
68+
}
6169
}
6270
}
6371
}

0 commit comments

Comments
 (0)