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

fix: not.toHaveLog no longer returns a false pass when waiting for Cl… #577

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

danemauland
Copy link

Calling expect(options).not.toHaveLog(expectedLog) when the logs contain expectedLog would incorrectly pass. This happens when logs generated previously in the tests don't propagate to CloudWatch in time for the toHaveLog matcher to catch it.

To fix this, I added a new util, wrapWithRetryUntilPass, that will continue to query until the log is found or until the test times out.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 2111831727

  • 0 of 11 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.005%) to 99.73%

Totals Coverage Status
Change from base Build 2086947220: 0.005%
Covered Lines: 615
Relevant Lines: 615

💛 - Coveralls

@coveralls
Copy link

coveralls commented Apr 11, 2022

Pull Request Test Coverage Report for Build 3297002803

  • 11 of 11 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.005%) to 99.731%

Totals Coverage Status
Change from base Build 3296984775: 0.005%
Covered Lines: 617
Relevant Lines: 617

💛 - Coveralls

@AlessandroVol23
Copy link

I've got exactly that issue.
I test my EventBridge integration and there are normally two common patterns:

flag: true -> EB should consume event

flag: false -> EB shouldn't get event

It would be nice to test both. But every time I use expect().not.toHaveLog() it passes.

Copy link
Owner

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @danemauland and sorry for the late reply.
Two comments:

  1. I think we should add the same logic for the Chai integration, WDYT?
  2. Handling the negated logic (toNot) is a bit tricky. With this PR passing tests will always wait the full timeout correct? I guess it's better than to pass on failures 🙃

How long does it usually take the logs to arrive? Maybe we can adjust the default time accordingly for negated tests

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.

None yet

4 participants