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

Lazily execute beforeAll/afterAll code blocks (with grep) #350

Closed
nonplus opened this issue Mar 27, 2012 · 4 comments
Closed

Lazily execute beforeAll/afterAll code blocks (with grep) #350

nonplus opened this issue Mar 27, 2012 · 4 comments

Comments

@nonplus
Copy link

nonplus commented Mar 27, 2012

When using grep, I would like only the beforeAll/afterAll blocks needed by tests matching my grep to be executed.

Currently all beforeAll and afterAll callbacks get executed, regardless of whether any tests being run depend on them.

If you have a large test suite that uses beforeAll blocks to consolidate expensive setup, using grep to isolate a test may not speed up the run all that much because of this.

In the following example, when running mocha --grep Files I would expect "expensive setup needed for Database suite" not to be executed.

describe("Database", function() {
    beforeAll(function() {
        // expensive setup needed for Database suite
    });
    ...
});

describe("File", function() {
    beforeAll(function() {
        // expensive setup needed for File suite
    });
    ...
});
@guybrush
Copy link

+1

i run into this issue a lot

@tj
Copy link
Contributor

tj commented Mar 27, 2012

ah good call, I'll see if I can get this in the next release

nonplus pushed a commit to nonplus/mocha that referenced this issue Mar 28, 2012
@nonplus
Copy link
Author

nonplus commented Mar 28, 2012

@visionmedia, I've got an initial implementation that's working for me, but I'm not sure if that's the approach you would have taken. I also need to provide tests. Let me know if you want me to flesh this out and do a pull request.

BTW, I noticed a bug where if you specify multiple before/afterAll hooks, only one gets executed. My patch has that fixed (calling hookUp/Down instead of hook).

https://github.com/nonplus/mocha/commits/lazy-all

nonplus pushed a commit to nonplus/mocha that referenced this issue Mar 29, 2012
…to make sure unneeded before/after hooks aren't being called. mochajs#350
nonplus pushed a commit to nonplus/mocha that referenced this issue Mar 30, 2012
nonplus pushed a commit to nonplus/mocha that referenced this issue Apr 1, 2012
nonplus pushed a commit to nonplus/mocha that referenced this issue Apr 5, 2012
nonplus pushed a commit to nonplus/mocha that referenced this issue Apr 5, 2012
@tj
Copy link
Contributor

tj commented Jun 17, 2012

This issue has been inactive for over 1 month so I'm closing it. If you think it's still an issue re-open. - tjbot

@tj tj closed this as completed Jun 17, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants