Repository navigation
[test-harness] Add createTestHarness() for testing a project's production build - #16798
edmundhung wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 8e3e252 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
LGTM |
@cloudflare/autoconfig
@cloudflare/build-output-utils
@cloudflare/codemods
@cloudflare/config
@cloudflare/containers-shared
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-functions
@cloudflare/pages-shared
@cloudflare/runtime-types
@cloudflare/test-harness
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-plugin
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
9c0777c to
325430c
Compare
f631654 to
a027213
Compare
a027213 to
4ac6333
Compare
4ac6333 to
7bdd341
Compare
7bdd341 to
3a953a1
Compare
3a953a1 to
3c72a19
Compare
3c72a19 to
d7c42a2
Compare
d7c42a2 to
fbd3e5c
Compare
f311c03 to
6ba7149
Compare
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
ce905ac to
6452be5
Compare
6452be5 to
28480c6
Compare
…anged From packages/wrangler/src/api/test-harness.ts and packages/wrangler/e2e/createTestHarness.test.ts, so that the next commit's diff shows what the cf test harness changes.
28480c6 to
deef5ab
Compare
…s API A v0 package for testing a project's production build with cf. Like Wrangler's createTestHarness(), it runs the project's Workers in tests, but from its build output. This commit's diff shows what changes from Wrangler's harness, and why: - Each Worker runs from a project's Build Output (`projectDir`, and `name` for a build's other Workers) rather than a Wrangler config, as in `vite preview`: secrets come from the build mode's `.dev.vars` and `.env` files, remote bindings are on, and Containers run from the build's images. - Test values go in one `envOverrides` option, written as in cloudflare.config.ts, instead of `vars`, `secrets` and `bindingOverrides`. As in production, it only replaces bindings the Worker declares, each with one that can stand in for it. - applyD1Migrations() takes the `dir`, `pattern` and `table` options of `cf d1 migrations apply`, as Build Output has no migrations config, and applies them with workers-utils' readD1Migrations() and applyD1Migrations(). - The Durable Object and Workflow helpers take the export name, since a Worker reaches its own through `ctx.exports`. Workflows are introspected through Miniflare's unsafeIntrospectWorkflow(), so they need no binding. - Test-only Workers can be inline, as Miniflare's Worker config, which Miniflare runs as given. - getWorker() is typed only from a Worker's config module. Without one, its env and export are `any`, and getEnv() and getExport() take types directly. - update() can change the number of Workers, as the harness updates one Miniflare instance, and remote sessions follow each Worker by name. - As in production, an uncaught Worker error is a 500 response, and CF-Worker names the Worker's zone.
deef5ab to
8e3e252
Compare
There was a problem hiding this comment.
✅ Approved — No blocking, warning or open findings at this commit. The earlier suggestion was answered by the author, and the code matches the answer.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🚀 Release: ✅ LGTM
Overall risk: Low.
- Changeset: The pull request adds an experimental, test-only package with a minor changeset, which matches the repository's guidance for new experimental features.
- Publishing: The package is registered in the tests for package publishing and changeset validation.
🔒 Security: ✅ LGTM
The harness is a local test tool. It runs Miniflare on 127.0.0.1 against the developer's own build output.
- Credentials: Auth uses the cf profile and fails closed in non-interactive or CI contexts. No secrets are logged.
- Remote-bindings key: The key contains no secret values.
- Dependencies: All dependencies are workspace packages or catalog entries.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
No issues found in the changed code.
- Remote sessions:
resolveWorkerInputsandupdateConfigdispose remote sessions on every failure path I traced. These cover a failed resolve, a failedsetOptions, and a Worker removed or replaced with an inline one. - Container images: The image-preparation cache belongs to each harness.
- Tests: They now cover the remote-bindings auth hook, session disposal,
envOverridesvalidation and the new handle APIs. - Eager profile resolution: Resolving the cf profile for every Build Output Worker is intended, as the author explained in the discussion.
⚡ Performance: ✅ LGTM
No performance problems found.
- Worker resolution: Workers are resolved one at a time on purpose, so a failure leaves no remote session still starting. The cost is small for a test harness.
- Image cache: Image preparation is cached per harness.
- Session cleanup: Remote sessions are disposed on startup failure, on teardown and in
update().
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: 8e3e2527
Part of DEVX-2726 (RM-31812). Stacked on #16879; #16884 adds an example on top.
Adds
@cloudflare/test-harness, the cf equivalent of Wrangler'screateTestHarness(). It runs a project's Build Output asvite previewdoes, so tests run the production build. The name is a placeholder. The first commit copies Wrangler's harness and tests unchanged, so the second commit shows what changed:Worker handles change the same way: types come from the Worker's config module, and the helpers take cf's names and options.