Skip to content

test: fix typescript issues related to tests#22

Merged
SimonLoir merged 1 commit intomainfrom
test/fix-typescript-tests
Nov 8, 2025
Merged

test: fix typescript issues related to tests#22
SimonLoir merged 1 commit intomainfrom
test/fix-typescript-tests

Conversation

@SimonLoir
Copy link
Copy Markdown
Contributor

@SimonLoir SimonLoir commented Nov 8, 2025

  • Replaced createCaller implementation with a t.createCallerFactory tied to appRouter.
  • Adjusted test cases to use caller.health instead of directly invoking .ping().
  • Modified tsconfig.json to set module as esnext and moduleResolution as Bundler.
  • Updated test scripts in package.json to set ENCRYPTION_SECRET.
  • Added @jest/globals to devDependencies and synced pnpm-lock.yaml.

Summary by CodeRabbit

  • Chores
    • Updated testing framework configuration and dependencies for improved test execution
    • Added new development testing dependency
    • Enhanced TypeScript compiler options for better module resolution and bundler compatibility
    • Refactored internal testing utilities architecture

…istency

- Replaced `createCaller` implementation with a `t.createCallerFactory` tied to `appRouter`.
- Adjusted test cases to use `caller.health` instead of directly invoking `.ping()`.
- Modified `tsconfig.json` to set `module` as `esnext` and `moduleResolution` as `Bundler`.
- Updated test scripts in `package.json` to set `ENCRYPTION_SECRET`.
- Added `@jest/globals` to `devDependencies` and synced `pnpm-lock.yaml`.
Copilot AI review requested due to automatic review settings November 8, 2025 13:15
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 8, 2025

Walkthrough

The PR refactors the test createCaller helper from a generic function accepting router and context parameters to a pre-bound factory method tied to the app router. Test script invocations transition from NODE_OPTIONS='--experimental-vm-modules' to ENCRYPTION_SECRET=abc. TypeScript configuration is updated with ES module and bundler resolution settings.

Changes

Cohort / File(s) Summary
Test Configuration
packages/api/package.json
Updated test, test:watch, and test:coverage scripts to use ENCRYPTION_SECRET=abc instead of NODE_OPTIONS='--experimental-vm-modules'; added @jest/globals v^30.2.0 as devDependency.
Test Helper Refactoring
packages/api/src/__tests__/utils/createCaller.ts
Replaced generic function createCaller(router, ctx) with pre-bound factory t.createCallerFactory(appRouter), removing router and context parameters.
Test Helper Exports
packages/api/src/__tests__/utils/index.ts
Changed from named export export { createCaller } to wildcard re-export export * for createCaller; reformatted mockContext export block.
Test Updates
packages/api/src/__tests__/routers/health.test.ts
Updated test helper invocation from createCaller(healthRouter, ctx) to createCaller(ctx) and changed route access from caller.ping() to caller.health.ping(); added timestamp ISO validation assertion.
Test Procedure Updates
packages/api/src/__tests__/routers/trpc.test.ts
Added signal: undefined property to testProcedure invocations.
TypeScript Build Configuration
packages/api/tsconfig.json
Added compiler options module: esnext and moduleResolution: Bundler; reformatted include and exclude arrays to single-line format.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

  • Verify createCaller binding: Ensure t.createCallerFactory(appRouter) correctly binds to the app router and functions as expected across all test files.
  • Test route access patterns: Confirm that updated test calls via caller.health.ping() and similar hierarchical routes work as intended.
  • TypeScript configuration impact: Validate that module: esnext and moduleResolution: Bundler don't introduce unintended behavioral changes or build issues.
  • Environment variable transition: Verify that tests properly consume ENCRYPTION_SECRET=abc and that no dependencies on the old NODE_OPTIONS remain.

Possibly related PRs

Poem

🐰 A caller now bound to the app's steady heart,
No routers to pass—just context to start,
With factories fresh and configs so fine,
The tests hop along in a tRPC line!

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'test: fix typescript issues related to tests' is vague and generic, using the non-descriptive term 'fix typescript issues' without conveying what specific TypeScript problems were resolved. Consider a more specific title such as 'test: refactor createCaller to use factory pattern' or 'test: update test infrastructure for esnext modules' to clearly indicate the primary changes.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/fix-typescript-tests

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7d2ea1c and 70e2c9b.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • packages/api/package.json (2 hunks)
  • packages/api/src/__tests__/routers/health.test.ts (2 hunks)
  • packages/api/src/__tests__/routers/trpc.test.ts (6 hunks)
  • packages/api/src/__tests__/utils/createCaller.ts (1 hunks)
  • packages/api/src/__tests__/utils/index.ts (1 hunks)
  • packages/api/tsconfig.json (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/api/src/__tests__/utils/createCaller.ts (1)
packages/api/src/trpc.ts (1)
  • t (4-4)
packages/api/src/__tests__/routers/health.test.ts (2)
packages/api/src/__tests__/utils/createCaller.ts (1)
  • createCaller (4-4)
packages/api/src/__tests__/utils/mockContext.ts (1)
  • createMockContext (6-15)
🔇 Additional comments (7)
packages/api/tsconfig.json (1)

4-5: LGTM! Modern ES module configuration.

The module: esnext and moduleResolution: Bundler settings appropriately configure TypeScript for modern ES module and bundler-based workflows, aligning with the "type": "module" in package.json.

packages/api/src/__tests__/utils/createCaller.ts (1)

1-4: Clean refactor to factory-bound caller.

The migration from a generic createCaller(router, ctx) to a factory-bound createCaller(ctx) simplifies the test API and ensures consistent usage with appRouter. The implementation correctly uses tRPC's createCallerFactory pattern.

packages/api/package.json (2)

14-16: Test environment configuration updated appropriately.

Replacing NODE_OPTIONS='--experimental-vm-modules' with ENCRYPTION_SECRET=abc aligns with the TypeScript module configuration changes. The hardcoded secret value is acceptable for the test environment.


32-32: Good addition of Jest types.

Adding @jest/globals provides proper TypeScript definitions for Jest globals and matches the Jest version already in use.

packages/api/src/__tests__/routers/trpc.test.ts (1)

23-23: Correct addition of required signal property.

Adding signal: undefined to the test procedure invocations satisfies the tRPC procedure call signature. This field represents an AbortSignal for request cancellation, and undefined is the appropriate value for these test scenarios.

Also applies to: 33-33, 61-61, 71-71, 92-92

packages/api/src/__tests__/routers/health.test.ts (1)

8-10: Correctly updated to new test API.

The tests properly use the refactored createCaller(ctx) signature and access the health router through the explicit namespace path caller.health.ping(). All test cases are consistently updated.

Also applies to: 18-20, 29-32

packages/api/src/__tests__/utils/index.ts (1)

1-5: Clean export consolidation.

The refactored exports maintain the same public API surface while using cleaner syntax. The wildcard export for createCaller appropriately handles the module's single export.


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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the testing infrastructure for the API package, migrating to tRPC v11's createCallerFactory API and modernizing the test setup. The changes include adding Jest globals as an explicit dependency, updating TypeScript compiler options for module resolution, and refactoring the test utilities to use a more streamlined caller pattern.

Key Changes:

  • Refactored createCaller test utility to use tRPC v11's createCallerFactory API, binding it to the full appRouter
  • Added @jest/globals v30.2.0 as an explicit devDependency
  • Updated test scripts to remove NODE_OPTIONS='--experimental-vm-modules' and add ENCRYPTION_SECRET environment variable
  • Modified TypeScript config to use esnext module and Bundler moduleResolution

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pnpm-lock.yaml Adds lockfile entry for @jest/globals v30.2.0 dependency
packages/api/package.json Adds @jest/globals dependency and updates test scripts to set ENCRYPTION_SECRET instead of NODE_OPTIONS
packages/api/tsconfig.json Overrides base config with esnext module and Bundler moduleResolution, reformats include/exclude arrays
packages/api/src/__tests__/utils/createCaller.ts Refactors from generic router caller to appRouter-specific caller factory
packages/api/src/__tests__/utils/index.ts Changes from named export to wildcard export for createCaller
packages/api/src/__tests__/routers/health.test.ts Updates test calls to use new caller API pattern (caller.health.ping instead of caller.ping)
packages/api/src/__tests__/routers/trpc.test.ts Adds signal: undefined parameter to procedure test calls and removes trailing whitespace
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/api/tsconfig.json
Comment thread packages/api/tsconfig.json
Comment thread packages/api/src/__tests__/utils/createCaller.ts
@SimonLoir SimonLoir merged commit e993e90 into main Nov 8, 2025
10 checks passed
@SimonLoir SimonLoir deleted the test/fix-typescript-tests branch November 8, 2025 13:21
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.

2 participants