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

✨ No timeout for beforeEach or afterEach #3464

Merged
merged 17 commits into from Dec 10, 2022
Merged

Conversation

dubzzz
Copy link
Owner

@dubzzz dubzzz commented Dec 9, 2022

Timeout must only focus on the code under tests, in other words the predicate. It should not be triggered because of a beforeEach being too long, or a afterEach being too long.

beforeEach and afterEach must always be run, no matter if the property timeout or not. We want to get closer to the behaviour followed by existing test runners such as jest, see:

beforeAll(() => console.log("before all"));
beforeEach(() => console.log("before each"));
afterEach(() => console.log("after each"));
afterAll(() => console.log("after all"));

test("timeouting...", async () => {
  console.log("start");
  await new Promise(() => {});
  console.log("end");
}, 100);

Which prints:

before all
before each
start
after each
after all

And still runs the code after the timeout as it cannot stops it (case where the Promise resolve after N>100ms):

  ●  Cannot log after tests are done. Did you forget to wait for something async in your test?
    Attempted to log "end".

Fixes #3236

Category:

  • ✨ Introduce new features
  • 📝 Add or update documentation
  • ✅ Add or update tests
  • 🐛 Fix a bug
  • 🏷️ Add or update types
  • ⚡️ Improve performance
  • Other(s): ...

Potential impacts:

  • Generated values
  • Shrink values
  • Performance
  • Typings
  • Other(s): ...

Timeout must only focus on the code under tests, in other words the predicate. It should not be triggered because of a beforeEach being too long, or a afterEach being too long.
@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 9, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 2b04ffa:

Sandbox Source
Vanilla Configuration
@fast-check/examples Configuration

@dubzzz dubzzz changed the title ✨ No timeout due to beforeEach or afterEach ✨ No timeout for beforeEach or afterEach Dec 9, 2022
@codecov
Copy link

codecov bot commented Dec 10, 2022

Codecov Report

Merging #3464 (2b04ffa) into main (0995ed8) will decrease coverage by 0.00%.
The diff coverage is 92.68%.

@@            Coverage Diff             @@
##             main    #3464      +/-   ##
==========================================
- Coverage   95.49%   95.49%   -0.01%     
==========================================
  Files         213      213              
  Lines        5842     5876      +34     
  Branches     1076     1090      +14     
==========================================
+ Hits         5579     5611      +32     
- Misses        263      265       +2     
Flag Coverage Δ
unit-tests 95.49% <92.68%> (-0.01%) ⬇️
unit-tests-14.x-Linux 95.43% <92.68%> (-0.05%) ⬇️
unit-tests-16.x-Linux ?
unit-tests-18.x-Linux 95.49% <92.68%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ages/fast-check/src/check/property/IRawProperty.ts 100.00% <ø> (ø)
.../fast-check/src/check/property/Property.generic.ts 98.24% <ø> (+0.20%) ⬆️
.../fast-check/src/check/property/UnbiasedProperty.ts 62.50% <66.66%> (+8.65%) ⬆️
packages/fast-check/src/check/runner/Runner.ts 95.89% <92.85%> (-2.53%) ⬇️
...-check/src/check/property/AsyncProperty.generic.ts 94.73% <100.00%> (+0.61%) ⬆️
...ck/src/check/property/IgnoreEqualValuesProperty.ts 83.33% <100.00%> (+1.51%) ⬆️
...fast-check/src/check/property/SkipAfterProperty.ts 96.15% <100.00%> (+0.50%) ⬆️
...s/fast-check/src/check/property/TimeoutProperty.ts 100.00% <100.00%> (ø)
... and 5 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@dubzzz dubzzz merged commit b330dd3 into main Dec 10, 2022
@dubzzz dubzzz deleted the no-timeout-because-hooks branch December 10, 2022 14:36
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.

afterEach not executed when 'run' ends in the case of timeouts
1 participant