-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Is there a way to get test status on afterEach() method ? #840
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
Comments
If we do this, it has to be t.context = someThing() Also, it would have to be for
Three stars for describing a real world need for the feature! ⭐ ⭐ ⭐ |
@subash-canapathy could you provide an example (in Mocha) of how you use this information with your Saucelabs tests? The issue you linked to doesn't provide that kind of context. |
in mocha, when you run UI tests, you typically have the afterEach block handle the session closeouts with sauceLabs depending on the status of the test. For eg: afterEach(function(){
// propagate test status/result to sauceLabs
this.driver.sauceJobStatus(this.currentTest.state)
if (this.currentTest.state == 'failed') {
// do some additional testOpsCleanup if test failed.
}
this.driver.quit()
}); Currently we have a work around for this on AVA test.beforeEach(async t => {
t.context.testStatus = false;
}
// Flip the flag if test passes - thats only when afterEach gets called
test.afterEach(async t => {
t.context.testStatus = true;
});
test.afterEach.always(async t => {
await t.context.driver.quit()
.finally(function() {
if (isSauceSuite) {
return t.context.driver.sauceJobStatus(t.context.testStatus);
}
});
}); I mean this works and gets the job done, but as a test runner, i'd rather let AVA tell me if the test has passed or failed, and be able to get that info on the after* hooks. This is essential for conditional teardowns and cleanups. |
@subash-canapathy great example, thank you. I agree would be good if AVA could provide the plumbing for this. |
Since hooks are tests in fact, is there an easy way to achieve this ..? In addition, this feature means access test "history" in a test, seems that |
I want this feature.
I'm also currently using ava for E2E testing. |
@rhysd - That is a really cool idea! |
@cgcgbcbc im not sure about Sequence.run, looking at the runner code I thought we could utilize the report callback to additionally put the status/result of the test in the context so that it still works reliably on concurrent tests (sort of like a thread-local result context) |
Any updates on this guys? Will it be done in some visible perspective? |
Same question here, I need to log noisy debug information if a test is failing. Because import test from 'ava'
test.afterEach('this only runs when test succeed', t => {
// set a success status in t.context
t.context = 'success'
})
test.afterEach.always('this always runs', t => {
if (t.context === 'success') {
console.log('this test is succeed')
} else {
console.log('this test is failed')
// log my noisy debug info
}
})
test('success', t => {
t.is(true, true, '')
})
test('fail', t => {
t.is(true, false, '')
}) You can initiate NOTE: This workaround is still not reliable if criterias mentioned #928 are met, try to avoid them:
|
I'm also looking for this option, basicly cause I'm trying to write a plugin to capture my app log, and only print it out when test is failing. since ava is runing test in paraller, it's even more importent since logging to a file would be a bit more complex |
@fruch and others, PRs or implementation specs are very much welcome for this feature. I'm happy to give feedback as you familiarize yourself with the problem and the code. |
I have something working, based on @frantic1048 idea, and that was good enough for me. it would be nicer to get the actual status in the test context, so have visibility similar to the test reporter, like test.duration and more. I understand most of it is internal, and can easily break between version. is afterEach.always being called also for skipped and todo ? (more ideas come in my head, but most of them are in the reporter category) |
No it's not. |
I have a similar issue retrieving the status of the test suite, I am talking about the full test suite's status which I need to pass to BrowserStack (which accepts passed or failed) - would be great to have the ability to retrieve this before closing browser's window either before calling the .quit() method. Oh, and I am running my tests in Mocha, not AVA and could not find a solution for the issue there as well. |
@IssueHunt has funded $40.00 to this issue.
|
Maybe it's worth introducing a new hook? For instance test.afterFail('only runs if a test failed', t => {
// log, do screenshots
}) |
In `afterEach` hooks, consult `t.passed` to determine whether the test passed. Fixes #840. Co-authored-by: Mark Wubben <[email protected]>
@novemberborn |
@sindresorhus knows how to do that 😄 |
@sindresorhus has rewarded $36.00 to @bunysae. See it on IssueHunt
|
mocha has a way of getting the test status on the after* hooks to do customized teardowns.
currentTest.status
this is required for UI tests running on saucelabs and that feature in mocha was born out of the same need: mochajs/mocha#797
It would be super useful to have the test status exposed as metadata OR contextual information
Proposal A:
t.context.result
- to contain the result object (the one which goes to the reporter)Proposal B:
t.getTestStatus()
- a method available only on the afterEach hook to get status of the test.IssueHunt Summary
Backers (Total: $40.00)
Submitted pull Requests
Tips
IssueHunt has been backed by the following sponsors. Become a sponsor
The text was updated successfully, but these errors were encountered: