rsnext/test
Steven 0a04ab7478
Fix leaking internal config to user-defined loader prop in next/image (#36013)
The `config` was changed from a global variable to a function parameter of the `loader()` function in PR https://github.com/vercel/next.js/pull/33559 as an implementation detail, not as a public API. It was not meant to be used by the end user which is why it was [undocumented](https://nextjs.org/docs/api-reference/next/image#loader).

This config is meant for the default Image Optimization API. Since the `loader` prop bypasses the default Image Optimization API in favor of a custom function, that config is no longer be relevant because the function can implement the optimization url however it desires.

- Fixes #35115
2022-04-08 22:19:25 +00:00
..
.stats-app remove commons chunk config (#34445) 2022-02-19 22:26:54 +00:00
development Emotion SWC Plugin - Allow for jsxImportSource to be configurable (#35963) 2022-04-07 14:33:38 +02:00
e2e Continue testing react v17 with e2e tests (#35787) 2022-03-31 17:35:00 -05:00
integration Fix leaking internal config to user-defined loader prop in next/image (#36013) 2022-04-08 22:19:25 +00:00
lib test: organize react 18 tests (#36003) 2022-04-08 15:29:35 +00:00
production allow to provide postcss plugin options as a string (#35173) 2022-04-08 16:58:50 +00:00
unit Revert "fix the dynamic routing of middleware" (#35932) 2022-04-06 14:35:52 +00:00
.gitignore Universal Webpack (#3578) 2018-01-30 16:44:44 +01:00
jest-setup-after-env.ts Update azure config (#33999) 2022-02-04 13:42:22 -06:00
readme.md [docs] Fix 404 link for testing example. (#33407) 2022-01-17 19:08:52 +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 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. 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.