Skip to content

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

Open
Jae-Hyuk-Jang wants to merge 2 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 2 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 a59ed13
🔍 Latest deploy log https://app.netlify.com/projects/fedify-json-schema/deploys/6a75d36c76d96d00089672e3

@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: f1fa9291-c81f-44d6-a883-3a18c07fa7fe

📥 Commits

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

📒 Files selected for processing (1)
  • packages/express/src/index.test.ts

📝 Walkthrough

Walkthrough

The Express package adds Deno and Node 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 covers asynchronous context resolution, federation fetch input, response output, and next() suppression. Deno and Node test commands run the package test suite.

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

Possibly related PRs

  • fedify-dev/fedify#969 — Adds a comparable context-data integration test for another framework 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 accurately explains the async regression test and the added test commands.
Linked Issues check ✅ Passed The test verifies promise resolution, delayed federation.fetch(), and propagation of the resolved context value required by issue #855.
Out of Scope Changes check ✅ Passed The package test scripts support the stated testing objective, and all changes relate to issue #855.
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?

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

2 participants