Skip to content

feat(wrangler): dispatching email handlers with test harness - #14685

Merged
edmundhung merged 3 commits into
mainfrom
edmundhung/email-handler-harness
Jul 29, 2026
Merged

feat(wrangler): dispatching email handlers with test harness#14685
edmundhung merged 3 commits into
mainfrom
edmundhung/email-handler-harness

Conversation

@edmundhung

@edmundhung edmundhung commented Jul 14, 2026

Copy link
Copy Markdown
Member

Fixes n/a.

This adds support for dispatching email handlers with createTestHarness

You can now call server.getWorker().email({ from, to, raw }) to dispatch directly to a Worker's email() handler and inspect its outcome, rejection reason, forwarded messages, and replies.

const result = await server.getWorker().email({
    from: "sender@example.com",
    to: "inbox@example.com",
    raw: [
        "From: Sender <sender@example.com>",
        "To: Inbox <inbox@example.com>",
        "Message-ID: <test@example.com>",
        "Subject: Test email",
        "",
        "Hello from the test harness",
    ].join("\r\n"),
});

expect(result).toMatchObject({
    outcome: "ok",
    forwards: [{ rcptTo: "archive@example.com" }],
    replies: [{ raw: expect.stringContaining("Thanks for your email") }],
});

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

@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3c6167b

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

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 Jul 14, 2026
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

✅ All changesets look good

@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@14685

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@14685

create-cloudflare

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

@cloudflare/deploy-helpers

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-auth

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 3c6167b

@ask-bonk

ask-bonk Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

@edmundhung Bonk workflow was cancelled.

View workflow run · To retry, trigger Bonk again.

@edmundhung
edmundhung marked this pull request as ready for review July 15, 2026 11:42
@workers-devprod
workers-devprod requested review from a team and penalosa and removed request for a team July 15, 2026 11:43
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/calm-mails-report.md: [@cloudflare/wrangler]
  • .changeset/tidy-pandas-email.md: [@cloudflare/wrangler]
  • packages/miniflare/src/workers/core/email.ts: [@cloudflare/wrangler]
  • packages/miniflare/test/index.spec.ts: [@cloudflare/wrangler]
  • packages/wrangler/e2e/createTestHarness.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/api/test-harness.ts: [@cloudflare/wrangler]

ask-bonk[bot]

This comment was marked as resolved.

@ask-bonk

ask-bonk Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review posted successfully to PR #14685.

I reviewed the PR and posted a batch review with two inline comments:

  1. (High) test-harness.ts:999email() calls response.json() unconditionally. Server-side validation failures (missing Message-ID, missing from/to, empty/oversized body, parse errors) return plain-text 4xx responses that bypass the format=json branch, so callers get an opaque SyntaxError instead of the descriptive error. Provided a suggestion to check response.ok/content-type and throw the server message.

  2. (Medium) email.ts:274 — the scheduler.wait(0) used to let an un-awaited setReject() cross JSRPC is a timing heuristic that could make rejectReason flaky; suggested a deterministic signal or at least a documented limitation.

github run

devin-ai-integration[bot]

This comment was marked as resolved.

@edmundhung
edmundhung requested review from a team and emily-shen and removed request for a team and penalosa July 23, 2026 11:30

@tpmmorris tpmmorris 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.

Very useful change for improving Email service UX. Some of the response interfaces could be altered to provide better data to Local Explorer in the future.

Comment thread packages/miniflare/src/workers/core/email.ts
Comment thread packages/miniflare/src/workers/core/email.ts
@workers-devprod

workers-devprod commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@edmundhung
edmundhung force-pushed the edmundhung/email-handler-harness branch from e2043a8 to a1ae02c Compare July 28, 2026 14:01

@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 Jul 28, 2026
@edmundhung
edmundhung merged commit 01d7020 into main Jul 29, 2026
70 of 71 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Jul 29, 2026
@edmundhung
edmundhung deleted the edmundhung/email-handler-harness branch July 29, 2026 11:16
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.

4 participants