rsnext/test
Kam Figy b95bc4b74b
Prevent storing page props cache when in SSG + preview mode (#30757)
In Next 12, `router.replace()` treats the page props cache as authoritative when fetching SSG props in preview mode. This makes sense outside preview mode (static props won't change), but within preview mode this prevents reloading the preview data dynamically without force-refreshing the page.

This PR fixes the problem by instructing Next to bypass the props cache if it's an SSG route AND preview mode is on.

Repro: https://github.com/kamsar/next-replace-previewmode-staticprops/blob/main/pages/index.js



## Bug

- [x] Related issues linked using `fixes #number`: Fixes https://github.com/vercel/next.js/issues/30756
- [ ] Integration tests added: Did not find existing tests for the router, but I'd be happy to write one if someone could point me in the right direction.
2021-11-02 00:42:29 +00:00
..
.stats-app Remove extra config for PR stats (#30478) 2021-10-27 14:30:39 -05:00
development Enable SWC by default when there is no custom Babel config (#29811) 2021-10-23 10:21:44 +02:00
e2e Move outputFileTracing config up (#30295) 2021-10-25 23:22:45 -05:00
integration Prevent storing page props cache when in SSG + preview mode (#30757) 2021-11-02 00:42:29 +00:00
lib remove Object.fromEntries polyfill for node 10 in test utils (#30657) 2021-10-30 12:51:59 +02:00
production Revert incremental config to fix missing types (#30644) 2021-10-29 23:16:11 -05:00
unit Split Set-Cookie header correctly (#30560) 2021-10-28 17:46:58 +00:00
.eslintrc.json [ESLint] Remove error when file patterns are unmatched + ESLint setup changes (#27119) 2021-07-16 20:19:08 +02:00
.gitignore Universal Webpack (#3578) 2018-01-30 16:44:44 +01:00
jest-setup-after-env.ts Update test set-up to leverage playwright when able to (#28634) 2021-09-13 14:36:25 +02:00
readme.md Update test set-up to leverage playwright when able to (#28634) 2021-09-13 14:36:25 +02:00
test-file.txt Add additional file serving tests (#12479) 2020-05-04 11:58:19 -05:00

Writing tests for Next.js

Test types in Next.js

  • e2e: These tests will run against next dev and next start
  • development: These tests only run against next dev
  • production: These tests will run against next start.
  • integration: These tests run misc checks and modes and is where tests used to be added before we added more specific folders. We should not add any more tests here.
  • unit: These are very fast tests that should run without a browser or running next and should be testing a specific utility.

For the e2e, production, and development tests the createNext utility should be used and an example is available here. This creates an isolated Next.js install to ensure nothing in the monorepo is relied on accidentally causing incorrect tests.

All new tests should be written in TypeScript either .ts (or .tsx for unit tests). This will help ensure we catch smaller issues in tests that could cause flakey or incorrect tests.

Best practices

  • When checking for a condition that might take time, ensure it is waited for either using the browser waitForElement or using the check util in next-test-utils.
  • When applying a fix, ensure the test fails without the fix. This makes sure the test will properly catch regressions.