-
-
Notifications
You must be signed in to change notification settings - Fork 124
Fix fedify/next test-each failure, add fedify/next tests #978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a36052f
6a91433
e3212ca
39c65d5
c63b718
fe605d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -304,11 +304,15 @@ shell = "nu -c" | |
| run = ''' | ||
| let pkgs = ($env.usage_packages | split row " " | where ($it | is-not-empty)) | ||
| mise run prepare-each ...$pkgs | ||
| mise run check-each ...$pkgs | ||
| for pkg in $pkgs { | ||
| print $"Running tests for package: ($pkg)" | ||
| deno task --filter $"@fedify/($pkg)" test | ||
| if ($"packages/($pkg)/deno.json" | path exists) { | ||
| mise run check-each $pkg | ||
| print $"Running Deno tests for package: ($pkg)" | ||
| deno task --filter $"@fedify/($pkg)" test | ||
| } | ||
| print $"Running Node.js tests for package: ($pkg)" | ||
| pnpm --filter $"@fedify/($pkg)" test | ||
| print $"Running Bun tests for package: ($pkg)" | ||
| pnpm --filter $"@fedify/($pkg)" test:bun | ||
|
Comment on lines
+313
to
316
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add checking package.json for Node and Bun? For example, |
||
| } | ||
| ''' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,8 @@ | |
| "build:self": "tsdown", | ||
| "build": "pnpm --filter @fedify/next... run build:self", | ||
| "prepack": "pnpm build", | ||
| "prepublish": "pnpm build" | ||
| "prepublish": "pnpm build", | ||
| "test": "node --experimental-transform-types --test", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing TS files directly doesn't work well with Next.js, I think. How about testing built files only? Like |
||
| "test:bun": "bun test" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { | ||
| createFederation, | ||
| InProcessMessageQueue, | ||
| MemoryKvStore, | ||
| } from "@fedify/fedify"; | ||
| import { test } from "@fedify/fixture"; | ||
| import { strict as assert } from "node:assert"; | ||
|
2chanhaeng marked this conversation as resolved.
|
||
| import { | ||
| fedifyWith, | ||
| integrateFederation, | ||
| isFederationRequest, | ||
| isNodeInfoRequest, | ||
| } from "./index.ts"; | ||
|
|
||
| test("Accept header detection", () => { | ||
| const request = new Request("https://example.com/", { | ||
| headers: { | ||
| Accept: "application/activity+json", | ||
| }, | ||
| }); | ||
|
|
||
| assert.strictEqual(isFederationRequest(request), true); | ||
| }); | ||
|
|
||
| test("Content-Type header detection", () => { | ||
| const request = new Request("https://example.com/", { | ||
| method: "POST", | ||
| headers: { | ||
| "Content-Type": "application/activity+json", | ||
| }, | ||
| }); | ||
|
|
||
| assert.strictEqual(isFederationRequest(request), true); | ||
| }); | ||
|
|
||
| test("NodeInfo route detection", () => { | ||
| const request1 = new Request("https://example.com/.well-known/nodeinfo", {}); | ||
|
|
||
| const request2 = new Request( | ||
| "https://example.com/.well-known/x-nodeinfo2", | ||
| {}, | ||
| ); | ||
|
|
||
| assert.strictEqual(isNodeInfoRequest(request1), true); | ||
| assert.strictEqual(isNodeInfoRequest(request2), true); | ||
| }); | ||
|
|
||
| test("Non-federation request delegation", async () => { | ||
| const federation = createFederation({ | ||
| kv: new MemoryKvStore(), | ||
| queue: new InProcessMessageQueue(), | ||
| }); | ||
| const customMiddleware = (request: Request) => { | ||
| if (request.url === "https://example.com/test") { | ||
| return new Response("Custom middleware response"); | ||
| } | ||
| return new Response("Default response"); | ||
| }; | ||
| const middleware = fedifyWith(federation)(customMiddleware); | ||
|
|
||
| const request = new Request("https://example.com/", { | ||
| headers: { | ||
| Accept: "text/html", | ||
| }, | ||
| }); | ||
|
|
||
| const request2 = new Request("https://example.com/test", { | ||
| headers: { | ||
| Accept: "text/html", | ||
| }, | ||
| }); | ||
|
|
||
| assert.strictEqual(isFederationRequest(request), false); | ||
| assert.strictEqual(isFederationRequest(request2), false); | ||
|
|
||
| const response1 = await middleware(request); | ||
| const response2 = await middleware(request2); | ||
|
|
||
| assert.strictEqual(await response1.text(), "Default response"); | ||
| assert.strictEqual(await response2.text(), "Custom middleware response"); | ||
| }); | ||
|
|
||
| test("Custom not-found/not acceptable handler", async () => { | ||
| const federation = createFederation({ | ||
| kv: new MemoryKvStore(), | ||
| queue: new InProcessMessageQueue(), | ||
| }); | ||
|
|
||
| // Set up a dispatcher that always returns null to simulate a not acceptable scenario | ||
| federation.setActorDispatcher("/users/{identifier}", () => null); | ||
|
|
||
| const handler = integrateFederation(federation, undefined, { | ||
| onNotFound: () => new Response("Custom not found", { status: 418 }), | ||
| onNotAcceptable: () => | ||
| new Response("Custom not acceptable", { status: 418 }), | ||
| }); | ||
|
|
||
| const response1 = await handler( | ||
| new Request("https://example.com/missing", { | ||
| headers: { Accept: "application/activity+json" }, | ||
| }), | ||
| ); | ||
|
|
||
| assert.strictEqual(response1.status, 418); | ||
| assert.strictEqual(await response1.text(), "Custom not found"); | ||
|
|
||
| const response2 = await handler( | ||
| new Request("https://example.com/users/123", { | ||
| headers: { Accept: "text/html" }, | ||
| }), | ||
| ); | ||
|
|
||
| assert.strictEqual(response2.status, 418); | ||
| assert.strictEqual(await response2.text(), "Custom not acceptable"); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: fedify-dev/fedify
Length of output: 2803
🏁 Script executed:
Repository: fedify-dev/fedify
Length of output: 7414
Check root Deno workspace membership before running Deno tasks.
packages/<pkg>/deno.jsonexists for every package, so the current condition runscheck-eachanddeno task --filtereven for packages not listed underdeno.json.workspace. Gate these commands on the package being present in the rootdeno.jsonworkspace as well as having a package-local Deno config.🤖 Prompt for AI Agents