|
| 1 | +# Next.js e2e test suite |
| 2 | + |
| 3 | +The tests in this directory are taken from the Next.js monorepo. |
| 4 | +[See the licence](https://github.com/vercel/next.js/blob/canary/license.md). The files in `tests` run unmodofied. The |
| 5 | +ones in `modified-tests` either have fixes to run correctly, or have tests disabled. The tests in `disabled-tests` are |
| 6 | +current disabled because of either an incompatibility or bug. |
| 7 | + |
| 8 | +The tools in `next-test-lib` are based on the equivalent tools in the Next.js monorepo. The original utilities test the |
| 9 | +Next.js code, whereas here they are used to test the Netlify runtime. For this reason only the "deploy" mode is enabled, |
| 10 | +and it builds using the runtime packages in this monorepo and deploys using the Netlify CLI. The e2e tests then run |
| 11 | +against the deployed site. |
| 12 | + |
| 13 | +The script that runs these is in |
| 14 | +[.github/workflows/e2e-next.yml](https://github.com/netlify/next-runtime/blob/main/.github/workflows/e2e-next.yml). It |
| 15 | +runs all the tests in parallel using a matrix, with each running in a separate job. The tests are run against the |
| 16 | +version of the Next Runtime that is currently in the monorepo, and the version of `next` that is in the monorepo's |
| 17 | +dependencies. |
| 18 | + |
| 19 | +To run the tests locally, the npm script `test:next` can be used, which runs the default tests. The script |
| 20 | +`test:next:all` runs all the tests, including the ones in `disabled-tests` and the other tests skipped by Jest. The |
| 21 | +script `test:next:disabled` runs only the disabled tests. Unlike in CI, these are run sequentially, so will take a long |
| 22 | +time to run, so you may want to just run a single test suite. To run a single suite run |
| 23 | +`npm run test:next:all -- the-test-name-here`, e.g. `npm run test:next:all -- streaming-ssr`. The name is matched as a |
| 24 | +pattern against the path of the test file and can be a partial match. |
| 25 | + |
| 26 | +When they are run, the tests generate the sites in a temporary directory, and then deploy them to Netlify. The e2e tests |
| 27 | +are then run against these. This can be overridden by setting the env var `SITE_URL`, which will be used instead of |
| 28 | +deploying the test site. This only makes sense when running a single test suite, because each test suite runs against a |
| 29 | +different site. |
| 30 | + |
| 31 | +The tmp directory with each test site is deleted after the tests have been run. If you want to manually build or deploy |
| 32 | +the test sites, you can run the test command, and then you can kill the test process after it has generated the site. |
| 33 | +The location of the tmp directory is printed in the console. Alternatively, set the env var `NEXT_TEST_SKIP_CLEANUP` and |
| 34 | +the site directories will all be retained. |
0 commit comments