-
-
Notifications
You must be signed in to change notification settings - Fork 0
Update ApolloSubscriptionServerContainerModule tests #35
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
Update ApolloSubscriptionServerContainerModule tests #35
Conversation
update tests to cover fastify integration use case
|
📝 WalkthroughWalkthroughAdds Fastify support to the apollo-subscription-ws package by introducing Fastify-related devDependencies and extending integration tests to exercise a Fastify-based Apollo server (HTTP queries + WebSocket subscriptions), while preserving existing Express tests and public API surface. Changes
Sequence Diagram(s)(Skipped — changes are limited to test additions and devDependency updates; no new multi-component runtime control-flow requiring visualization.) Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts (1)
232-439: Consider extracting common test utilities to reduce duplication.The Fastify test suite duplicates the GraphQL schema, resolvers, and test assertion logic from the Express suite. While some duplication is acceptable in integration tests for clarity, you could extract common elements like:
- GraphQL schema and resolver definitions into shared constants
- WebSocket connection/subscription test utilities
- Common assertion helpers
This would improve maintainability if the test logic needs to be updated in the future.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/apollo-subscription-ws/package.jsonpackages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{ts,tsx,js,jsx,json,md}
📄 CodeRabbit inference engine (AGENTS.md)
Use Prettier with shared configuration from @inversifyjs/foundation-prettier-config
Files:
packages/apollo-subscription-ws/package.jsonpackages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
**/package.json
📄 CodeRabbit inference engine (AGENTS.md)
**/package.json: Use workspace protocol (workspace:*) for internal dependencies in package.json
Pin development dependencies to specific versions for security and reproducibility
Files:
packages/apollo-subscription-ws/package.json
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use strict mode enabled for TypeScript across all packages
Files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
**/*.{spec,int.spec,spec-d}.ts
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{spec,int.spec,spec-d}.ts: Use Vitest for unit and integration testing with extensive test coverage
Mock external modules using vitest.fn() and vitest.mock() in tests
Files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
**/*.spec.ts
📄 CodeRabbit inference engine (AGENTS.md)
Name unit tests with *.spec.ts file extension
Files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
**/*.int.spec.ts
📄 CodeRabbit inference engine (AGENTS.md)
Name integration tests with *.int.spec.ts file extension
Files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
**/*.{spec,int.spec}.ts
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{spec,int.spec}.ts: Organize test describe blocks in four-layer structure: Class → Method → Input → Flow scopes
Use descriptive test names with 'when called, and [condition]' pattern
Files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use ESLint with shared configuration from @inversifyjs/foundation-eslint-config
Files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
🧠 Learnings (3)
📚 Learning: 2025-12-24T10:31:07.649Z
Learnt from: CR
Repo: inversify/graphql PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-24T10:31:07.649Z
Learning: Applies to **/*.{spec,int.spec,spec-d}.ts : Use Vitest for unit and integration testing with extensive test coverage
Applied to files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
📚 Learning: 2025-12-24T10:31:07.649Z
Learnt from: CR
Repo: inversify/graphql PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-24T10:31:07.649Z
Learning: Applies to **/*.{spec,int.spec,spec-d}.ts : Mock external modules using vitest.fn() and vitest.mock() in tests
Applied to files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
📚 Learning: 2025-12-27T21:04:29.742Z
Learnt from: notaphplover
Repo: inversify/graphql PR: 32
File: packages/apollo-fastify/src/apollo/controllers/buildApolloServerFastifyController.int.spec.ts:19-112
Timestamp: 2025-12-27T21:04:29.742Z
Learning: The 4-layer describe block structure (Class → Method → Input → Flow scopes) applies only to unit tests. Use this 4-layer structure for tests in files matching '**/*.spec.ts'. Do not apply to integration tests in files like '**/*.int.spec.ts'.
Applied to files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
🔇 Additional comments (3)
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts (2)
7-7: LGTM! Fastify imports are properly structured.The new imports follow the same pattern as the existing Express imports and provide the necessary types and modules for Fastify integration.
Also applies to: 11-11, 13-14
22-22: Good clarification for test organization.Renaming the describe block to explicitly mention Express improves test readability and distinguishes it from the new Fastify test suite.
packages/apollo-subscription-ws/package.json (1)
13-13: Use workspace protocol for internal @inversifyjs packages instead of pinned versions.@inversifyjs/http-fastify and @inversifyjs/http-express should use "workspace:" to match the coding guideline "Use workspace protocol (workspace:) for internal dependencies in package.json". They are currently pinned to "4.9.1", inconsistent with @inversifyjs/apollo-fastify which correctly uses "workspace:*". External dependencies (@as-integrations/fastify, fastify) are correctly pinned to latest versions (3.1.0, 5.6.2).
⛔ Skipped due to learnings
Learnt from: CR Repo: inversify/graphql PR: 0 File: AGENTS.md:0-0 Timestamp: 2025-12-24T10:31:07.649Z Learning: Applies to **/package.json : Use workspace protocol (workspace:*) for internal dependencies in package.jsonLearnt from: CR Repo: inversify/graphql PR: 0 File: AGENTS.md:0-0 Timestamp: 2025-12-24T10:31:07.649Z Learning: Applies to **/package.json : Pin development dependencies to specific versions for security and reproducibility
...pollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
Outdated
Show resolved
Hide resolved
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts (1)
238-263: Consider extracting shared test fixtures and logic.The Fastify test suite duplicates ~200 lines from the Express suite (schema definition, resolvers, HTTP request test setup, and WebSocket subscription test logic). While integration tests often maintain independence for clarity, this level of duplication creates maintenance overhead—any changes to test logic or fixtures must be applied twice.
Consider extracting:
- Common GraphQL schema and resolvers into shared constants
- WebSocket subscription test flow into a reusable helper function parameterized by server type
This would maintain test independence while reducing duplication and improving maintainability.
Example refactoring approach
// Shared test fixtures const TEST_GRAPHQL_SCHEMA: TypeSource = ` type RootQuery { hello: String! } schema { query: RootQuery subscription: RootSubscription } type RootSubscription { subscribeHello: RootQuery! } `; const TEST_GRAPHQL_RESOLVERS: IResolvers = { RootQuery: { hello: () => 'world' }, RootSubscription: { subscribeHello: { subscribe: async function* () { yield { subscribeHello: { hello: 'world' } }; yield { subscribeHello: { hello: 'world' } }; }, }, }, }; // Shared test helper async function testWebSocketSubscription(port: number): Promise<unknown[]> { const subscriptionResults: unknown[] = []; const wsClient = new WebSocket( `ws://localhost:${port}/subscriptions`, 'graphql-transport-ws', ); // ... rest of subscription test logic return subscriptionResults; }Then reference these in both Express and Fastify test suites.
Also applies to: 314-329, 344-410
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use strict mode enabled for TypeScript across all packages
Files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
**/*.{spec,int.spec,spec-d}.ts
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{spec,int.spec,spec-d}.ts: Use Vitest for unit and integration testing with extensive test coverage
Mock external modules using vitest.fn() and vitest.mock() in tests
Files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
**/*.spec.ts
📄 CodeRabbit inference engine (AGENTS.md)
Name unit tests with *.spec.ts file extension
Files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
**/*.int.spec.ts
📄 CodeRabbit inference engine (AGENTS.md)
Name integration tests with *.int.spec.ts file extension
Files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
**/*.{spec,int.spec}.ts
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{spec,int.spec}.ts: Organize test describe blocks in four-layer structure: Class → Method → Input → Flow scopes
Use descriptive test names with 'when called, and [condition]' pattern
Files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
**/*.{ts,tsx,js,jsx,json,md}
📄 CodeRabbit inference engine (AGENTS.md)
Use Prettier with shared configuration from @inversifyjs/foundation-prettier-config
Files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use ESLint with shared configuration from @inversifyjs/foundation-eslint-config
Files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
🧠 Learnings (3)
📚 Learning: 2025-12-24T10:31:07.649Z
Learnt from: CR
Repo: inversify/graphql PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-24T10:31:07.649Z
Learning: Applies to **/*.{spec,int.spec,spec-d}.ts : Mock external modules using vitest.fn() and vitest.mock() in tests
Applied to files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
📚 Learning: 2025-12-24T10:31:07.649Z
Learnt from: CR
Repo: inversify/graphql PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-24T10:31:07.649Z
Learning: Applies to **/*.{spec,int.spec,spec-d}.ts : Use Vitest for unit and integration testing with extensive test coverage
Applied to files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
📚 Learning: 2025-12-27T21:04:29.742Z
Learnt from: notaphplover
Repo: inversify/graphql PR: 32
File: packages/apollo-fastify/src/apollo/controllers/buildApolloServerFastifyController.int.spec.ts:19-112
Timestamp: 2025-12-27T21:04:29.742Z
Learning: The 4-layer describe block structure (Class → Method → Input → Flow scopes) applies only to unit tests. Use this 4-layer structure for tests in files matching '**/*.spec.ts'. Do not apply to integration tests in files like '**/*.int.spec.ts'.
Applied to files:
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts
🧬 Code graph analysis (1)
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts (3)
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.ts (1)
ApolloSubscriptionServerContainerModule(17-62)packages/apollo-fastify/src/apollo/modules/ApolloFastifyServerContainerModule.ts (1)
ApolloFastifyServerContainerModule(22-68)packages/apollo-subscription-ws/src/apollo/models/wsServerServiceIdentifier.ts (1)
wsServerServiceIdentifier(4-5)
🔇 Additional comments (3)
packages/apollo-subscription-ws/src/apollo/modules/ApolloSubscriptionServerContainerModule.int.spec.ts (3)
7-14: LGTM! Fastify imports are correctly added.The new imports for Fastify integration (context argument, server module, HTTP adapter, and instance type) are all properly used in the new test suite.
22-22: LGTM! Improved test suite description.Explicitly mentioning Express in the describe block improves clarity and distinguishes it from the new Fastify integration tests.
232-304: LGTM! Fastify integration is correctly implemented.The Fastify test suite setup properly:
- Uses Fastify-specific modules (ApolloFastifyServerContainerModule, InversifyFastifyHttpAdapter)
- Starts the server using the Promise-based
listen()API at line 298 (past review comment has been addressed ✓)- Extracts the port from
fastifyInstance.server.address()for test assertions- Configures WebSocket subscriptions via the shared ApolloSubscriptionServerContainerModule
The server listens on a random port (default for
listen()without arguments), which is appropriate for integration tests to avoid port conflicts.
Changed
Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.