Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

afterEach's run in unnatural order #357

Closed
tjmehta opened this issue May 14, 2015 · 3 comments · Fixed by #359
Assignees
Labels
bug
Milestone

Comments

@tjmehta
Copy link
Contributor

@tjmehta tjmehta commented May 14, 2015

Test.js

var lab = require('lab');
var lab = exports.lab = lab.script();

lab.experiment('experiments', function () {

    lab.before(function (done) {
        console.log('outer: before');

        done();
    });

    lab.beforeEach(function (done) {
        console.log('outer: beforeEach');

        done();
    });

    lab.afterEach(function (done) {
        console.log('outer: afterEach');

        done();
    });

    lab.after(function (done) {
        console.log('outer: after');

        done();
    });

    lab.experiment('experiment1', function () {
        lab.before(function (done) {
            console.log('inner: before');

            done();
        });

        lab.beforeEach(function (done) {
            console.log('inner: beforeEach');

            done();
        });

        lab.afterEach(function (done) {
            console.log('inner: afterEach');

            done();
        });

        lab.after(function (done) {
            console.log('inner: after');

            done();
        });

        lab.test('test', function (done) {
            console.log('test');
            done();
        });
    });
});

Output

$ lab test.js                                                                                                                                         ✘
outer: before
inner: before
outer: beforeEach
inner: beforeEach
test.
outer: afterEach # "inner:afterEach" should run before "outer:afterEach" 
inner: afterEach 
inner: after     # Notice "inner:after" runs before "outer:after"
outer: after

IMO afterEach's should run in the same order as after's so that tests
can be cleaned up from the inside-out.

@geek geek added the bug label May 14, 2015
@bkendall

This comment has been minimized.

Copy link
Contributor

@bkendall bkendall commented May 14, 2015

👍

@anandkumarpatel

This comment has been minimized.

Copy link

@anandkumarpatel anandkumarpatel commented May 15, 2015

+1 I also have this issue

@Marsup

This comment has been minimized.

Copy link
Member

@Marsup Marsup commented May 15, 2015

Instead of bringing the whole runnable org here to +1, maybe you could fix it with a PR, it would go a lot faster ;)

@geek geek closed this in #359 May 19, 2015
@geek geek self-assigned this May 19, 2015
@geek geek added this to the 5.9.0 milestone May 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.