Skip to content

Add an async context data test for @fedify/express - #985

Open
Jae-Hyuk-Jang wants to merge 4 commits into
fedify-dev:mainfrom
Jae-Hyuk-Jang:test/express-async-context-data
Open

Add an async context data test for @fedify/express#985
Jae-Hyuk-Jang wants to merge 4 commits into
fedify-dev:mainfrom
Jae-Hyuk-Jang:test/express-async-context-data

Conversation

@Jae-Hyuk-Jang

@Jae-Hyuk-Jang Jae-Hyuk-Jang commented Aug 7, 2026

Copy link
Copy Markdown

Summary

integrateFederation()'s contextDataFactory may return a plain value or a Promise, but only the synchronous path had test coverage.
This adds a regression test for the async path, verifying the middleware waits for the factory to resolve and passes the resolved value to federation.fetch().

Also adds the missing test script (package.json) and test task (deno.json) for @fedify/express so the suite actually runs under mise run test:node / test-each.

Fixes #855

Test plan

  • mise run check-each express
  • deno test --allow-all (packages/express)
  • node --experimental-transform-types --test (packages/express)

AI disclosure

This change was written with assistance from Claude Code (claude-sonnet-5), reviewed and verified by me.

integrateFederation() accepts a contextDataFactory that may return
either a plain value or a Promise, but only the synchronous path was
covered. Add a test that verifies the middleware waits for an async
factory to resolve and passes the resolved value to federation.fetch().

Also wire up the test script/task in package.json and deno.json so
mise run test:node and test-each actually run it.

Changelog: none
Assisted-by: Claude Code:claude-sonnet-5
@netlify

netlify Bot commented Aug 7, 2026

Copy link
Copy Markdown

Deploy Preview for fedify-json-schema canceled.

Name Link
🔨 Latest commit cd288b2
🔍 Latest deploy log https://app.netlify.com/projects/fedify-json-schema/deploys/6a7814220ec6a5000802330b

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 50d84419-ee79-4d26-ae0c-c021e2d334d9

📥 Commits

Reviewing files that changed from the base of the PR and between 9e6c38a and cd288b2.

📒 Files selected for processing (1)
  • packages/express/src/index.test.ts
💤 Files with no reviewable changes (1)
  • packages/express/src/index.test.ts

📝 Walkthrough

Walkthrough

The Express package adds Deno, Node, and Bun test commands. New middleware tests verify that integrateFederation() awaits asynchronous context data, passes the resolved value to federation.fetch(), writes the response, and does not call next().

Changes

Express async context test

Layer / File(s) Summary
Async context middleware validation
packages/express/src/index.test.ts, packages/express/deno.json, packages/express/package.json
The test adds mock request and response helpers, verifies asynchronous context resolution and federation fetch input, captures the response, and confirms that next() is not called. Deno, Node, and Bun commands run the package test suite.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

  • fedify-dev/fedify#988 — Adds a comparable asynchronous context-data integration test for the Fresh adapter.

Suggested labels: component/integration

Suggested reviewers: dahlia

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the added asynchronous context data test for @fedify/express.
Description check ✅ Passed The description explains the async regression test, added test commands, validation steps, and linked issue.
Linked Issues check ✅ Passed The PR adds the required async contextDataFactory test and verifies resolution before federation.fetch() receives the value [#855].
Out of Scope Changes check ✅ Passed The changes are limited to the requested regression test and package test configuration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/express/src/index.test.ts`:
- Around line 65-88: Update the async contextDataFactory test to use a deferred
promise and track federation.fetch invocation; assert fetch remains uncalled
before resolving the promise, then resolve it and verify the existing response
and middleware behavior after completion.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 67407354-e127-4371-939c-d560137a9e46

📥 Commits

Reviewing files that changed from the base of the PR and between 15ad151 and 64bcda0.

📒 Files selected for processing (3)
  • packages/express/deno.json
  • packages/express/package.json
  • packages/express/src/index.test.ts

Comment thread packages/express/src/index.test.ts
The previous test only checked the resolved value, not that
federation.fetch() stays uncalled until the async contextDataFactory
promise resolves. Use a deferred promise to assert the ordering
directly, per CodeRabbit's review on fedify-dev#985.

Changelog: none
Assisted-by: Claude Code:claude-sonnet-5

@sij411 sij411 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since integrateFederation() only assigns send, json, and removeHeader and never calls their existing implementations, could these methods be omitted from the initial response mock?

@2chanhaeng 2chanhaeng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution! Please check my comment.

Comment thread packages/express/package.json Outdated
The package had a Node test script but no Bun equivalent, so the
suite never ran under Bun. Mirror the elysia package's pattern.

Changelog: none
Assisted-by: Claude Code:claude-sonnet-5

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/express/package.json`:
- Line 62: Add an engines.node declaration in packages/express/package.json
covering the Node versions that support --experimental-transform-types, or
replace that flag with a test command compatible with the package’s declared
Node support baseline. Keep the test script’s behavior unchanged for supported
runtimes.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 06c7d757-01e1-434f-a281-caebe31bfec5

📥 Commits

Reviewing files that changed from the base of the PR and between a59ed13 and 9e6c38a.

📒 Files selected for processing (1)
  • packages/express/package.json

Comment thread packages/express/package.json
integrateFederation() only overwrites send, json, and removeHeader
with no-ops; it never calls their existing implementations, so the
mock response doesn't need them.

Changelog: none
Assisted-by: Claude Code:claude-sonnet-5
@Jae-Hyuk-Jang

Copy link
Copy Markdown
Author

Since integrateFederation() only assigns send, json, and removeHeader and never calls their existing implementations, could these methods be omitted from the initial response mock?

Good catch, removed them — thanks!

@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.
see 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an async context data test for @fedify/express

3 participants