rsnext/test
Gal Schlezinger e05c31df17
Throw an error when target: 'serverless' is used with Middleware (#37819)
Serverless target is deprecated, so we don't support it in Middleware as it's a new feature,
but we need to have a good error message for that. This commit solves that.

## Related

* Fixes #37433



## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-06-19 13:17:18 +00:00
..
.stats-app Add middleware size stats (#37519) 2022-06-07 17:05:48 +00:00
__mocks__ Use Edge Runtime for running Edge Functions locally (#37024) 2022-05-30 12:01:36 +00:00
development Display full refresh warning even when error has occurred (#37425) 2022-06-19 00:00:14 +00:00
e2e Ensure query params are populated correctly with middleware (#37784) 2022-06-17 10:28:25 -05:00
integration Detect pnpm correctly when installing missing dependencies (#37813) 2022-06-19 12:33:23 +00:00
lib Display full refresh warning even when error has occurred (#37425) 2022-06-19 00:00:14 +00:00
production Throw an error when target: 'serverless' is used with Middleware (#37819) 2022-06-19 13:17:18 +00:00
unit Refactor server routing (#37725) 2022-06-16 21:43:01 +00:00
.gitignore
jest-setup-after-env.ts Update azure config (#33999) 2022-02-04 13:42:22 -06:00
readme.md Add handling for testing against deployments (#36285) 2022-04-20 12:23:09 +00:00
test-file.txt Add additional file serving tests (#12479) 2020-05-04 11:58:19 -05:00

Writing tests for Next.js

Getting Started

You can set-up a new test using yarn new-test which will start from a template related to the test type.

Test Types in Next.js

  • e2e: These tests will run against next dev, next start, and deployed to Vercel
  • 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. Ideally we don't add new test suites here as tests here are not isolated from the monorepo.
  • 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 test suites 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.

If a test suite already exists that relates closely to the item being tested (e.g. hash navigation relates to existing navigation test suites) the new checks can be added in the existing test suite.

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.