Closed tymfear closed 4 years ago
Agreed. We can update t.passed
once the test completes, and then it'll be accurate in a teardown.
We run the teardowns here:
https://github.com/avajs/ava/blob/983ce0cb714fe0b35b48834c0911ebd4cf8e71d6/lib/test.js#L728
A little later is the code that determines whether the test passed:
https://github.com/avajs/ava/blob/983ce0cb714fe0b35b48834c0911ebd4cf8e71d6/lib/test.js#L732-L733
We can move that up, and assign this.testPassed = passed
. That should do the trick.
Teardown tests live here:
https://github.com/avajs/ava/blob/75cbc3b2a53d3b8530266b10bed71b838bc11fec/test-tap/test.js#L750
@novemberborn, so I did the following change https://github.com/tymfear/ava/pull/1/files
Tested in manually - it works.
But I have no idea on how to create a test for that. Was thinking of something like
test('t.passed is set in teardown for passing test', t => {
return ava(a => {
a.teardown(() => {
t.is(result.passed, true) // <-------- Don't know how to reach the "passed" value as context is not passed to teardowns
});
a.pass();
}).run().then(result => {
t.is(result.passed, true);
});
});
Any idea on this?
Coz the only idea I have is to pass context to teardowns, but that's a huge breaking change (at least it looks to me like it is, not sure). And doing that for testing purpose only seems a bit of overengineering.
But on the other hand, probably it is right way to be consistent with different hooks? And passing context to teardown will remove need for the change I did.
Note: by passing context I mean the t
-like object with at least the following values
{
context,
passed,
title
}
@novemberborn Ok, I found solution on how to create test for the change, but still what are your opinion of passing t
-like object to teardowns?
This seems like a pretty interesting issue. But it is already being handled. Kudos to you @tymfear
Please provide details about:
t.teardown
callback when test has failedt.passed
isundefined
.t.passed
to be defined. Sincet.teardown
might be used instead oftest.afterEach
hook it should have similar capabilities.Code example: