-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Output every failed assertion or just the first one (currently outputs just the last one) #121
Comments
This is strange. BDD/TDD style assertions should throw if the assertion fails. Can you comment out Also, you're missing |
Is |
test('foo', t => {
t.plan(2);
var a = 2;
var b = 3;
var c = 4;
try {
t.ok(a === b);
console.log('a === b did NOT throw');
} catch (e) {
console.log('a === b DID throw');
}
try {
t.ok(b === c);
console.log('b === c did NOT throw');
} catch (e) {
console.log('a === b DID throw');
}
t.end();
}); output:
|
This is a bug within |
No, I don't think so. The API seems modeled after It is a bit confusing coming from mocha, etc. But can be fairly handy (especially when your test framework actually shows you every failed assertion 😉). It might just be that the second/third/... failed assertion is the one that has the truly helpful hint that helps you identify the problem. This is why I prefer Option 1 from above
|
I agree that showing all failed assertions would be nice, instead of just dying on the first one. |
Yes, it was modeled after I'm open to supporting showing all assertion failures. I just didn't see the point when I first made AVA. There has been some times that I could have used this since then, though. Note to self: No matter what we go for we should at least more clearly document the behavior. @vdemedes What do you think? |
Honestly, I'm not sure about this one. I agree with @Qix-, it is a bit weird, that failed assertion does not throw. I realize it would be handy in some cases, but it also has its downsides. Imagine I have a test with Promise A, 5 assertions, then another Promise B inside and 5 more assertions. If it does not fail early, the whole code will be executed and I'll get a ton of errors just for one test. And where I'll start looking to fixing it? Right, from the first failed assertion. |
@sindresorhus even with I think we all agree that the first test failure is the most important, but I don't think it is necessary to change to a throwing behavior if you don't like the verbosity of printing out all those failures - just don't print them (or print them in an ultra compact form). Here is the current output:
It might be cool to print all the assertions with dots and x's:
I could also get behind slightly more output:
Also, the |
@jamestalmage I liked your idea on this:
But, there's one reason it is just not possible with AVA - Parallelism. AVA executes all tests in parallel, so there's no way we can modify previous output, because other tests might've displayed in the meantime. |
By the time the promise test |
We haven't to, |
There is order within an individual test. |
@jamestalmage that is correct, my oversight ;) |
I was just thinking about displaying the assert progress live. |
@jamestalmage The syntactical order need not match the run-time order: setTimeout(() => t.ok(true), 2000);
setTimeout(() => t.fail(), 500); |
Two options there:
|
FYI: extracting line number from power-assert would be easy enough. If we change empower(assert,
powerAssertFormatter({
renderers: [
powerAssertRenderers.AssertionRenderer,
powerAssertRenderers.SuccinctRenderer
]
}),
{
destructive: true,
modifyMessageOnRethrow: true,
saveContextOnRethrow: true,
patterns: module.exports.PATTERNS
}
); then
{
source: {
content: "t.is(foo, bar)",
filepath: "/path/to/some_test.js",
line: 1
},
args: [
{
value: "foo",
events: [
{
value: "foo",
espath: "arguments/0"
}
]
},
{
value: "bar",
events: [
{
value: "bar",
espath: "arguments/1"
}
]
}
]
}
|
I'm ok with switching to showing the first assertion instead of the last, but I'm still undecided about showing multiple asserts. |
What if we created an alternate one-line format for all the subsequent failures: |
Showing the last assertion makes absolutely zero sense. const ctx = new Context('test', 'hello\n new\n again\n back\n sustain\nroot');
t.ok(ctx.scope.spaces === 0);
t.ok(ctx.inIndent === true);
t.ok(ctx.skip(5));
t.ok(ctx.inIndent === false);
t.ok(ctx.peek() === '\n');
t.ok(ctx.read() === '\n');
t.ok(ctx.inIndent === true);
t.ok(ctx.peek() === ' ');
t.ok(ctx.scope.spaces === 0);
t.ok(ctx.read() === ' ');
t.ok(ctx.inIndent === true);
t.ok(ctx.scope.spaces === 1);
t.end(); In the above, the last assertion is the only one that shows up, leading me to initially believe everything leading up to it was ok. Low and behold, I commented it out and the one before it ( Incredibly counter-intuitive. |
@Qix- Totally agree. Not sure why I did this initially. |
output:
It would be better if either:
The text was updated successfully, but these errors were encountered: