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

test: refactor use-swr-refresh.test.tsx #1103

Merged

Conversation

koba04
Copy link
Collaborator

@koba04 koba04 commented Apr 5, 2021

This is a follow-up PR of #933.
I've refactored use-swr-refresh.test.tsx.

The test file is the slowest test in vercel/swr because it has many tests depend on setTimeout/setInterval timers.
Reducing the interval of timers makes tests flaky, so I've used Jest's fake timers to reduce the total test time.

  • Before
➜  yarn test                                                                                                                                                                                                                 
yarn run v1.22.10
$ jest
 PASS  test/use-swr-config-callbacks.test.tsx
 PASS  test/use-swr-concurrent-mode.test.tsx
 PASS  test/use-swr-revalidate.test.tsx
 PASS  test/use-swr-key.test.tsx
 PASS  test/use-swr-configs.test.tsx
 PASS  test/use-swr-focus.test.tsx
 PASS  test/use-swr-loading.test.tsx
 PASS  test/use-swr-offline.test.tsx
 PASS  test/use-swr-context-config.test.tsx
 PASS  test/use-swr-infinite.test.tsx
 PASS  test/use-swr-suspense.test.tsx
 PASS  test/use-swr-cache.test.tsx
 PASS  test/use-swr-integration.test.tsx
 PASS  test/use-swr-local-mutation.test.tsx
 PASS  test/use-swr-error.test.tsx
 PASS  test/use-swr-refresh.test.tsx (6.37s)

Test Suites: 16 passed, 16 total
Tests:       110 passed, 110 total
Snapshots:   55 passed, 55 total
Time:        8.228s
Ran all test suites.
✨  Done in 9.83s.
  • After
➜  yarn test
yarn run v1.22.10
$ jest
 PASS  test/use-swr-refresh.test.tsx
 PASS  test/use-swr-config-callbacks.test.tsx
 PASS  test/use-swr-concurrent-mode.test.tsx
 PASS  test/use-swr-configs.test.tsx
 PASS  test/use-swr-loading.test.tsx
 PASS  test/use-swr-revalidate.test.tsx
 PASS  test/use-swr-key.test.tsx
 PASS  test/use-swr-context-config.test.tsx
 PASS  test/use-swr-cache.test.tsx
 PASS  test/use-swr-focus.test.tsx
 PASS  test/use-swr-offline.test.tsx
 PASS  test/use-swr-suspense.test.tsx
 PASS  test/use-swr-infinite.test.tsx
 PASS  test/use-swr-integration.test.tsx
 PASS  test/use-swr-error.test.tsx
 PASS  test/use-swr-local-mutation.test.tsx

Test Suites: 16 passed, 16 total
Tests:       110 passed, 110 total
Snapshots:   23 passed, 23 total
Time:        5.803s
Ran all test suites.
✨  Done in 7.29s.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 5, 2021

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 b5077bb:

Sandbox Source
SWR-Basic Configuration
SWR-States Configuration
SWR-Infinite Configuration
SWR-SSR Configuration

@koba04 koba04 marked this pull request as ready for review April 5, 2021 15:36
Copy link
Member

@shuding shuding left a comment

Choose a reason for hiding this comment

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

Thank you! Never used Jest fake timers before but it looks awesome :)

@shuding shuding merged commit f5f3252 into vercel:master Apr 5, 2021
@koba04 koba04 deleted the refactor-use-swr-refresh-test-with-fake-timers branch April 6, 2021 01:23
@koba04
Copy link
Collaborator Author

koba04 commented Apr 6, 2021

Thank you!

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