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

allow --require'd modules to register runner hooks #286

Closed
wants to merge 1 commit into from

Conversation

timbertson
Copy link

There may be a better way of doing this, but I needed a way for a --require to be able to hook into the runner's emitted events.

@uipoet
Copy link

uipoet commented Mar 9, 2012

+1. expect.js module has a function called expect that I can't get without requiring manually in every test file.

@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 Jun 17, 2012
@tj
Copy link
Contributor

tj commented Jun 17, 2012

I see what you're going for here, I think it's a bit magical though. I think it would be fine just to tell the user to add afterEach(mylib.checkSomething), at least it's explicit that way

@timbertson
Copy link
Author

This means that tests will silently succeed (when they shouldn't) every time a user forgets this.

So while I agree that it's not hard, I still think it should be foolproof (by not requiring the user remember anything). If you can think of a better way to achieve the same effect, I'm all ears.

@timbertson
Copy link
Author

Also, just re-reading the original post - the patch works for not just afterEach, but allows listening for any emitted event. Surely that is a useful feature for any kind of plugin that wants to monitor the running of tests.

@tj
Copy link
Contributor

tj commented Jun 20, 2012

im just not a fan of implicit magic, when you can have simple explicit magic haha

@timbertson
Copy link
Author

Ok so you won't merge this one, but perhaps the problem can be addressed in a way that doesn't require user intervention in every single test file?

For example, how about allowing a "mocha-init.js" in the test root, which allows setup including adding hooks or afterEach blocks that affect the entire test suite. Explicit, but not arduous.

It could even replace mocha.opts eventually - whatever you have in mocha.opts could become something like:

mocha.addOpts("--growl", "--etc")

The fact that it's just js allows for additional composability and flexibility (e.g only adding --growl if growl is installed)

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

Successfully merging this pull request may close these issues.

3 participants