Skip to content

feat(wrangler): add test harness resource accessors#14287

Merged
edmundhung merged 2 commits into
mainfrom
edmundhung/add-harness-resource-accessors
Jun 15, 2026
Merged

feat(wrangler): add test harness resource accessors#14287
edmundhung merged 2 commits into
mainfrom
edmundhung/add-harness-resource-accessors

Conversation

@edmundhung

@edmundhung edmundhung commented Jun 13, 2026

Copy link
Copy Markdown
Member

Fixes n/a.

This adds per-Worker resource accessors to createTestHarness(), so tests can inspect the same local resources that a Worker used while handling a request.

For example:

const server = createTestHarness({
  workers: [{ configPath: "./wrangler.jsonc" }],
});

await server.listen();

const worker = server.getWorker("api-worker");

// Exercise the Worker code that writes to storage.
await worker.fetch("/create-user", {
  method: "POST",
  body: JSON.stringify({ email: "user@example.com" }),
});

// Assert the resulting storage state directly.
const db = await worker.getD1Database("DB");
const latestUser = await db
  .prepare("SELECT id, email FROM users ORDER BY created_at DESC LIMIT 1")
  .first<{ id: string; email: string }>();

expect(latestUser.email).toBe("user@example.com");

const bucket = await worker.getR2Bucket("BUCKET");
const avatar = await bucket.get(`avatars/${latestUser.id}.png`);

expect(avatar).not.toBeNull();

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: I will add it seperately.

A picture of a cute animal (not mandatory, but encouraged)


Open in Devin Review

@changeset-bot

changeset-bot Bot commented Jun 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: af427f8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
miniflare Patch
wrangler Minor
@cloudflare/deploy-helpers Patch
@cloudflare/pages-shared Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

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

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Jun 13, 2026
@workers-devprod workers-devprod requested review from a team and ascorbic and removed request for a team June 13, 2026 20:10
@workers-devprod

workers-devprod commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@github-actions

github-actions Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

✅ All changesets look good

@ask-bonk

ask-bonk Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

miniflare.dispatchFetch (line 664) — Miniflare's dispatchFetch does await this.ready internally (which drains its own #runtimeMutex), so the wrangler-level runtimeMessageMutex.drained() removal doesn't compromise correctness for the getWorker().fetch() path either. The proxy-worker mutex is only relevant for the proxy-based server.fetch() path (line 682-691), which still goes through proxyWorker and is unaffected.

My analysis is complete. The change is well-reasoned:

  1. The Miniflare error message improvement is sound and all old references are updated.
  2. Removing runtimeMessageMutex.drained() from getRuntimeMiniflare is safe because Miniflare's own internal #runtimeMutex (via await this.ready) gates all proxy/dispatch operations on the #mf instance.
  3. The Promise.all startup change correctly adds waitForReloadComplete with no listener-attachment race.
  4. The new accessors are consistent with the existing fetch/scheduled implementations and properly scope by worker name.
  5. Multiworker shared-runtime model is correctly handled.

The only minor observation (empty-string worker name → "the worker" message instead of naming it) is cosmetic and not reachable through the public test-harness API, since resolveWorkerName never returns an empty string. Not actionable.

No logic bugs, security issues, backward-compat violations, or incorrect API behavior found.

LGTM

github run

devin-ai-integration[bot]

This comment was marked as resolved.

@pkg-pr-new

pkg-pr-new Bot commented Jun 13, 2026

Copy link
Copy Markdown
create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@14287

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14287

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@14287

miniflare

npm i https://pkg.pr.new/miniflare@14287

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@14287

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@14287

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@14287

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@14287

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@14287

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@14287

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@14287

wrangler

npm i https://pkg.pr.new/wrangler@14287

commit: af427f8

@petebacondarwin petebacondarwin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of questions/suggestions - nothing blocking.

Comment thread packages/miniflare/src/index.ts Outdated
Comment thread packages/miniflare/src/index.ts Outdated

@workers-devprod workers-devprod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Jun 15, 2026
@edmundhung edmundhung merged commit 41f391f into main Jun 15, 2026
76 of 78 checks passed
@edmundhung edmundhung deleted the edmundhung/add-harness-resource-accessors branch June 15, 2026 09:41
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants