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

chore: avoid silent test failures by flushing Promises after each test #5066

Merged
merged 6 commits into from
Jan 14, 2022

Conversation

dbjorge
Copy link
Contributor

@dbjorge dbjorge commented Jan 14, 2022

Details

This PR adds a new setup step to each of our test suites which forces Jest to flush all Promises in a globally applied afterEach fixture.

This forces Jest to flush any pending resolved Promises that a test might have forgotten to handle before Jest considers that test to be completed. That way, if a test leaks a Promise, the resulting error message gets logged as a failure in the responsible test and includes a nice, Jest-formatted stack, instead of test "passing" and the error as a Node UnhandledProjmiseRejectionWarning with no stack or test context.

This is intended to work in tandem with #5061, allowing it to go in as a last-resort while mitigating the poor logging that we get if it's actually triggered (by avoiding having it need to trigger in the common case)

Motivation

Avoids silent test failures (eg, the one that currently exists in injector-controller.test.ts)

Context

jestjs/jest#10784 (comment)

Pull request checklist

  • [n/a] Addresses an existing issue: #0000
  • Ran yarn fastpass
  • Added/updated relevant unit test(s) (and ran yarn test)
  • Verified code coverage for the changes made. Check coverage report at: <rootDir>/test-results/unit/coverage
  • PR title AND final merge commit title both start with a semantic tag (fix:, chore:, feat(feature-name):, refactor:). See CONTRIBUTING.md.
  • [n/a] (UI changes only) Added screenshots/GIFs to description above
  • [n/a] (UI changes only) Verified usability with NVDA/JAWS

@dbjorge dbjorge marked this pull request as ready for review January 14, 2022 22:46
@dbjorge dbjorge requested a review from a team as a code owner January 14, 2022 22:46
@dbjorge dbjorge merged commit 2800128 into microsoft:main Jan 14, 2022
@dbjorge dbjorge deleted the flush-promises-after-each-test branch January 14, 2022 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants