Skip to content

--fail-fast is not so fast #2497

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

Closed
timepp opened this issue May 23, 2020 · 2 comments
Closed

--fail-fast is not so fast #2497

timepp opened this issue May 23, 2020 · 2 comments

Comments

@timepp
Copy link

timepp commented May 23, 2020

test("geo", t => {
    let rect = [10, 20, 60, 80]
    let cases = [
        [10, 20, 10, 20],
        [60, 80, 60, 80],
        // many many more lines removed for readability here
        [15, 21, 15, 20],
        [15, 77, 15, 80],
        [50, 40, 60, 40]
    ]
    for (const c of cases) {
        t.log(c)
        const [x, y, xe, ye] = c
        t.deepEqual(geo.nearestPointInRectangle(x, y, ...rect), [xe, ye])
    }
})

I used to write related cases in the above way which is very clean. One of these cases in middle was failed.

My expectation is that ava stop execution on the failed case and I can know exactly which case was failed by simply looking at the last console output (via t.log(c)).

But ava --fail-fast didn't stop the execution and all cases are printed out finally, causing me unable to know which case was fail.

@novemberborn
Copy link
Member

--fail-fast stops AVA from starting new tests. It cannot interrupt any tests that are already running.

What you're encountering is that a failed assertion doesn't stop a test implementation from executing. #2455 will give you a way of recognizing when this is the case.

That said, have a look at t.try(). It will let you home in on just the failed cases:

test("geo", async t => {
    let rect = [10, 20, 60, 80]
    let cases = [
        [10, 20, 10, 20],
        [60, 80, 60, 80],
        // many many more lines removed for readability here
        [15, 21, 15, 20],
        [15, 77, 15, 80],
        [50, 40, 60, 40]
    ]
    for (const c of cases) {
        const attempt = await t.try(tt => {
            tt.log(c)
            const [x, y, xe, ye] = c
            tt.deepEqual(geo.nearestPointInRectangle(x, y, ...rect), [xe, ye])
        })
        attempt.commit({retainLogs: !attempt.passed})
    }
})

(I'm closing this issue for housekeeping purposes, but let's keep the conversation going.)

@timepp
Copy link
Author

timepp commented May 25, 2020

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants