-
Notifications
You must be signed in to change notification settings - Fork 780
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
New test reporter hook #1475
Comments
@Krinkle / @trentmwillis: #1480 is a WIP on how this would work. I hope this provides more clarity. |
Thanks @ventuno. I think this seems out of scope for reporting events, which are meant to be async, deterministic and react only to the information given to them. I like your use case though, and hope this is something we could make work within the QUnit runtime. For example, through the |
Thanks for looking into this @Krinkle. A function call in the
Does that make sense? |
@ventuno Absolutely! I wanted to understand if the timing and overall contract of The way I've handled this in projects myself is by wrapping the const orgModule = QUnit.module;
let nested = false;
QUnit.module = function (name, executeNow) {
if (nested || typeof executeNow !== 'function') {
// Ignore nested modules, already inherits parent hooks.
// Ignore non-scoped modules.
return orgModule.apply(this, arguments);
}
const orgExecute = executeNow;
executeNow = function (hooks) {
hooks.beforeEach(function () {
// Do global setup, e.g. sinon sandbox, app fixtures, etc.
});
hooks.afterEach(function () {
// Do global teardown, e.g. restore sandbox, or assert zero open transactions.
});
nested = true;
const ret = orgExecute.apply(this, arguments);
nested = false;
return ret;
};
return orgModule(name, executeNow);
}; This reduces the "hackiness" factor by a lot, but remains rather hacky still. Perhaps an officially supported "global hook" would make sense. E.g. a way to implicitly add In terms of ergonomics, I imagine it could work something like this: QUnit.hooks.afterEach((assert) => {
/* … */
}); |
FWIW, ember-qunit's test isolation validation should make this much better. |
@Krinkle - In order to implement that we ultimately did end up monkey patching
|
Thanks @Krinkle, something like the proposed |
Two micro optimisations: * Move the declaration of the hooks object to where the internal module is created more generally. Adding the property later seems confusing and was less optimal. * Move two utility functions from within processModule() to outside of it as they didn't use any of its scope and thus were needlessly being re-allocated for every registered test module. Clarity: * Move `module.hooks` and `module.stats` property definitions to the module object literal rather than creating them sometime later as dynamic properties. * Clarify that the unnamed module is not (and should not become) a "global module". I was thinking of doing this as a way to implement the upcoming global QUnit.hooks feature, but then remembered that these are two distinct concepts that I think are best kept separate. This is preparation for #1475, ref https://github.com/qunitjs/qunitjs.com/issues/161.
@rwjblue I'd love to know if the global @ventuno I suggest we add |
Idea
Introduce a new Test Reporter hook (e.g.:
beforeTestEnd
) that is triggered when a test ends but beforeafter*
hooks are triggered.Context
Recently I found myself trying to improve the logging of failed tests, in particular tests failing non-deterministically (e.g.: flaky).
The idea is to provide the ability log (together with the failed assertion) the information about the environment when the test run completes.
Take an Ember component as an example, one might want to log additional information like:
The above is currently impossible because
testDone
/testEnd
hooks are triggered afterafter*
hooks which is normally used to clean up the test environment for the next test to run. So accessingQUnit.config.current.testEnvironment
intestDone
/testEnd
does not provide any useful information.Proposed solution
Test frameworks cannot obviously provide any framework-specific functionality, but can provide the test environment information when reporting so that 3rd party test reporters built on top of the common
js-reporters
interface.My proposal is to introduce a new hook
beforeTestEnd
hook (not sure if we would need abeforeSuiteEnd
as well) which is called beforeafter*
hooks and passes the testEnvironment (when available) as an argument.Ideally this should be part of the
js-reporters
standard, but I wanted to introduce the idea to the QUnit community first.@Krinkle / @trentmwillis thoughts?
The text was updated successfully, but these errors were encountered: