You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test: add e2e tests of the build+preview use case (#8905)
* test: add e2e tests of the build+preview use case
* fixups
* add npm install retries
* clarify mock registry usage
* fix retry logic
* ensure seeded directory is cleaned between tests
* don't rely upon pre/post npm hooks
* faster e2e tests
* skip AI e2e tests if there is no account id or api token
* fix up README
* allow package install beforeAll hook to run for up to 200 secs
* don't crash if killing test process fails
* skip e2e build tests on Windows
This directory contains e2e test that give more confidence that the plugin will work in real world scenarios outside the comfort of this monorepo.
3
+
This directory contains e2e tests that give more confidence that the plugin will work in real world scenarios outside the comfort of this monorepo.
4
4
5
5
In general, these tests create test projects by copying a fixture from the `fixtures` directory into a temporary directory and then installing the local builds of the plugin along with its dependencies.
6
6
@@ -9,44 +9,49 @@ In general, these tests create test projects by copying a fixture from the `fixt
9
9
Simply use turbo to run the tests from the root of the monorepo.
10
10
This will also ensure that the required dependencies have all been built before running the tests.
11
11
12
+
You will need to provide CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN for the Workers AI tests to pass.
These tests use a mock npm registry where the built plugin has been published.
19
21
20
-
The registry is booted up and loaded with the local build of the plugin and its local dependencies in the global-setup.ts file that runs once at the start of the e2e test run, and the server is killed and its caches removed at the end of the test run.
22
+
The registry is booted up and loaded with the local build of the plugin and its local dependencies in the global-setup.ts file that runs once at the start of the e2e test run, and the server is killed and its caches removed at the end of the test run. The mock npm registry will delegate to the standard public npm registry for non-local dependency requests (e.g. vite, typescript, etc).
21
23
22
-
The Vite `test` function is an extended with additional helpers to setup clean copies of fixtures outside of the monorepo so that they can be isolated from any other dependencies in the project.
24
+
There is a `seed()` helper to setup a clean copy of a fixture outside of the monorepo so that it can be isolated from any other dependencies in the project.
-makes a copy of the named fixture into a temporary directory,
38
+
- The `seed()` helper creates a `beforeAll()` block:
39
+
-make a copy of the named fixture into a temporary directory,
38
40
- updates the vite-plugin dependency in the package.json to match the local version
39
-
- runs `npm install` (or equivalent package manager command) in the temporary project
41
+
- runs `npm install` (or equivalent package manager command) in the temporary project - the dependencies are installed from the mock npm registry mentioned above.
40
42
- returns the path to the directory containing the copy (`projectPath` above)
43
+
- The `seed()` helper also creates an `afterAll()` block:
41
44
- the temporary directory will be deleted at the end of the test.
42
45
- The `runCommand()` helper simply executes a one-shot command and resolves when it has exited. You can use this to install the dependencies of the fixture from the mock npm registry.
43
-
- The `viteDev()` helper boots up the `vite dev` command and returns an object that can be used to monitor its output. The process will be killed at the end of the test.
44
-
- The `waitForReady()` helper will resolve when the`vite dev` process has output its ready message, from which it will parse the url that can be fetched in the test.
46
+
- The `runLongLived()` helper runs an npm script (from the package.json scripts section) and returns an object that can be used to monitor its output. The process will be killed at the end of the test.
47
+
- The `waitForReady()` helper will resolve when a`vite dev`long lived process has output a ready message, from which it will parse the url that can be fetched in the test.
45
48
- The `fetchJson()` helper makes an Undici fetch to the url parsing the response into JSON. It will retry every 250ms for up to 10 secs to minimize flakes.
46
49
47
-
## Debugging the tests
50
+
## Debugging e2e tests
48
51
49
-
You can provide the following environment variables to get access to the logs and the actual files being tested:
52
+
You can control the logging and cleanup via environment variables:
50
53
51
-
-`NODE_DEBUG=vite-plugin:test` - this will display debugging log messages as well as the streamed output from the commands being run.
52
-
-`CLOUDFLARE_VITE_E2E_KEEP_TEMP_DIRS=1` - this will prevent the temporary directory containing the test project from being deleted, so that you can go and play with it manually.
54
+
- Keep the temporary directory after the tests have completed: `CLOUDFLARE_VITE_E2E_KEEP_TEMP_DIRS=true`
55
+
- See debug logs for the tests: `NODE_DEBUG=vite-plugin:test`
56
+
- See debug logs for the mock npm registry: `NODE_DEBUG=mock-npm-registry`
0 commit comments