-
Notifications
You must be signed in to change notification settings - Fork 778
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
Add testTeardown
logging callback.
#471
Conversation
This is primarily useful as a way of making global checks that can fail tests, for example checking that any XMLHttpRequest initiated during a test finishes before the next test.
To me, it seems like you should just be using the actual test Moreover, I also don't believe that you'll be able to assert anything inside of logging callbacks once @Krinkle's Assertion refactor lands. |
@JamesMGreene thanks for taking the time to look and the quick response. ^_^ So, we do have a common check across many modules. The rule we want to assert is "no test leaves XHRs unresolved". This seems to me most straightforward to express in terms of before/after hooks for tests. We could wrap this in a helper that all This feels to me like exactly the sort of thing test suite hooks are good for. Are they intended to be for nothing more than logging? |
For me personally, they are not necessarily just for logging (though primarily, yes) but they are definitely NOT for assertions or cleanup, both of which I would put under Another option would be to duck-punch the |
@jzaefferer @Krinkle Differing opinions? |
@JamesMGreene do you see a particular harm in having some set of callbacks that can make assertions? Obviously it could only be for callbacks that happen at the right time in the test lifecycle. Duck-punching |
I'd rather add setup and teardown callbacks that apply to the entire testsuite. But then its pretty easy to just share stuff between modules. @hjdivad could you put together an example that uses module teardown (duck punched or not) so that we can focus more on the actual usecase? |
We have an additional patch to QUnit that we're using on Oasis at the moment, but feel free to ignore it: we're just using it to help us debug some async. issues on SauceLabs. |
Not to tangent too much but:
@jzaefferer: That's an interesting note. The most common complaint I get from our developers is that they wish there was an additional module-level Available offerings:
Potential offerings:
|
What's the usecase for that?
As mentioned, I see the use for this one, like the ajax checks that apply everywhere. I'd like to see usecases for the others. |
Nothing that can't be done at the Here's an example where I think it would make more sense to add that functionality, though: qunit-composite.js#L114-129 |
So, my thoughts:
I don't think this is worthwhile as they can just execute the "setup" operations before executing the first QUnit operation. Similarly, the "teardown" is likely completely unnecessary since the test run will be finished. The only question would be if they wanted to ensure some assertion was true at the end of their test run, this would be the right way to do it [if I'm correct that there shouldn't be assertions in logging callback handlers] as QUnit does not guarantee test execution order.
This makes sense if (4) makes sense.
We agree this one can add value.
See my previous comments.
Already available.
This is mostly stupid... just add it to your test. The only advantage for a consumer here is that QUnit would deal with the |
Related plugin: Related forum threads: |
@JamesMGreene I agree with all your comments above. |
CC: @bahmutov |
I would like to see this change integrated. We need to run some additional post test checks globally (not at the module level). Our use cases are:
|
@JamesMGreene @jzaefferer what's the status on this? Would the PR be accepted if it covered more cases (such as the ones James mentioned above)? Does it seem, in principle, reasonable in its current state? I guess I'm trying to get two things answered:
|
Yes.
This PR tries to accomplish a goal by adding new logging events. However, it should instead do so via more granularly-defined lifecycle setup/teardown-style functions than currently exist in QUnit. |
For reference, the equivalent idea from Mocha (visionmedia/mocha@lib/mocha.js#L95-L99): exports.setup = context.setup || context.beforeEach;
exports.suiteSetup = context.suiteSetup || context.before;
exports.suiteTeardown = context.suiteTeardown || context.after;
exports.teardown = context.teardown || context.afterEach; Combined with Mocha's infinitely nest-able |
I've just reviewed this discussion again and discussed it with @leobalter. Of all the suggested additional callbacks, the only one that's reasonable to us is the globally defined setup/teardown per test, "(3) Per-test setup/teardown, defined at the suite/page level" in James' comment above. Since that is a part of the testsuite and not just a reporter, it should not be implemented as a logging event. I've created #633 to suggest an alternative API. Whatever the result of that discussion, this PR is not going to land, so I'm closing it now. |
This is primarily useful as a way of making global checks that can fail
tests, for example checking that any XMLHttpRequest initiated during a test
finishes before the next test.
@cyril-sf and I have found this useful. What do others think?