Skip to content

Commit

Permalink
Fix copypaste bug for onBegin/onEachBegin callbacks
Browse files Browse the repository at this point in the history
Also added the test case which discovered this error!
  • Loading branch information
pineapplemachine committed Mar 28, 2018
1 parent aa90675 commit fb6bb72
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions canary.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,11 +686,11 @@ class CanaryTest{
async doBeginCallbacks(){
if(this.parent){
this.logVerbose(`Executing parent's onEachBegin callbacks for test "${this.name}".`);
await this.runCallbacks(true, this.parent.onEachSuccessCallbacks);
await this.runCallbacks(true, this.parent.onEachBeginCallbacks);
}
if(this.noErrors() && !this.failed && !this.aborted){
this.logVerbose(`Executing onBegin callbacks for test "${this.name}".`);
await this.runCallbacks(true, this.onSuccessCallbacks);
await this.runCallbacks(true, this.onBeginCallbacks);
}
}
// Invoke onEnd and parent's onEachEnd callbacks.
Expand Down
34 changes: 34 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,38 @@ addTest(
}
);

addTest(
async function testSuccessfulGroupCallbackOrder(){
// Set up the test
let counter = 0;
const testGroup = canary.group("Example test group", function(){
this.onBegin(function(){
assert(counter === 0);
counter++;
});
this.test("First example test", function(){
assert(counter === 1);
counter++;
});
this.test("Second example test", function(){
assert(counter === 2);
counter++;
});
this.onSuccess(function(){
assert(counter === 3);
counter++;
});
this.onEnd(function(){
assert(counter === 4);
counter++;
});
});
// Run canary
await canary.run();
// Verify correct results
assert(canary.success);
assert(counter === 5);
}
);

runTests();

0 comments on commit fb6bb72

Please sign in to comment.