Skip to content
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

Throwing in beforeAll is ignored #1213

Closed
6 tasks done
pzcfg opened this issue Apr 29, 2022 · 6 comments
Closed
6 tasks done

Throwing in beforeAll is ignored #1213

pzcfg opened this issue Apr 29, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@pzcfg
Copy link

pzcfg commented Apr 29, 2022

Describe the bug

I'm building out some tests for my project, and am trying to debug both the tests and the helper functions I'm building to setup the test states, etc.

While trying to debug why my tests weren't working, I discovered that if I throw an error inside of beforeAll, or return a promise that I reject, vitest seems to carry on as if everything completed successfully. This is making it extremely hard to debug tests, as well as disambiguate whether the problem is with my project, the test, or the test setup.

Reproduction

beforeAll(async () => {
   throw new Error("STOP")
})

or

beforeAll(async () => {
   return new Promise((resolve, reject) => { reject(); })
})

System Info

System:
    OS: macOS 12.0
    CPU: (10) arm64 Apple M1 Pro
    Memory: 97.80 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.1/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm
  Browsers:
    Chrome: 100.0.4896.127
    Safari: 15.0
  npmPackages:
    vite: ^2.9.6 => 2.9.6 
    vitest: ^0.10.0 => 0.10.0

Used Package Manager

yarn

Validations

@sheremet-va sheremet-va added the bug label May 1, 2022
@sheremet-va sheremet-va self-assigned this May 1, 2022
@sheremet-va
Copy link
Member

Everything works with your reproduction: meaning, tests fail.

https://stackblitz.com/edit/vitest-dev-vitest-xqtujg?file=test/suite.test.ts

@pzcfg
Copy link
Author

pzcfg commented May 2, 2022

Aah, I see what is happening. I have multiple describe() blocks, and even if the beforeAll() in the first block throws immediately, I don't see that error until all of the other tests have completed or timed out.

https://stackblitz.com/edit/vitest-dev-vitest-oycgdw?file=test%2Fsuite.test.ts

In our current environment, our tests or dependent on the effects of their previous ones (not ideal, I know, but it's how it is for now) so if any block fails I would like to shown the error immediately and probably exit out. Is there a configuration we can use for that?

@sheremet-va
Copy link
Member

This is not possible. describe blocks exist to prevent that :)

Try moving your tests to the same describe block, or move beforeAll to the top level.

@pzcfg
Copy link
Author

pzcfg commented May 2, 2022

Would it at least be possible to show the thrown errors immediately? I can see console logs/errors/etc. as soon as they run instead of after all tests have ended/timed out, and I did notice that I could see the errors if I essentially wrapped all of the functions in

() => {
  try {
    ...
  } catch (e) { console.error(e); }
}

but that seems excessive to have to do for the purposes of faster results/debugging

https://stackblitz.com/edit/vitest-dev-vitest-oycgdw?file=test%2Fsuite.test.ts

@sheremet-va sheremet-va added enhancement New feature or request and removed needs reproduction labels May 7, 2022
@sheremet-va
Copy link
Member

Would it at least be possible to show the thrown errors immediately?

Depends on what reporter do you use? The base reporter dynamically updates the tree and only the relevant part is visible until every test is processed.

We also have verbose reporter that shows the error immediately.

@sheremet-va sheremet-va removed their assignment May 7, 2022
@sheremet-va
Copy link
Member

I guess it would be possible to achieve with "bail" option from #1459. Closing this issue in favor of it.

@sheremet-va sheremet-va closed this as not planned Won't fix, can't repro, duplicate, stale Aug 4, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jun 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants