Skip to content

test: Do testing with jest instead of mocha for paginator - #9224

Merged
danieljbruce merged 2 commits into
mainfrom
migrate-paginator-to-jest-cla
Aug 28, 2026
Merged

test: Do testing with jest instead of mocha for paginator#9224
danieljbruce merged 2 commits into
mainfrom
migrate-paginator-to-jest-cla

Conversation

@danieljbruce

@danieljbruce danieljbruce commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Description

Migrates the @google-cloud/paginator package test suite and configuration from Mocha, Sinon, and c8 to Jest and ts-jest.

Key changes include:

  • Dependency & Infrastructure Updates:
    • Removed legacy test dependencies (mocha, @types/mocha, sinon, @types/sinon, c8, proxyquire, @types/proxyquire).
    • Added jest, ts-jest, and @types/jest.
    • Added jest.config.js configured with ts-jest.
    • Removed .nycrc and updated .gitignore for coverage/.
    • Updated package.json test script to use jest --coverage.
  • Test Suite Migration:
    • Migrated test/index.ts and test/resource-stream.ts to native Jest assertions (expect(...).toBe(), expect(...).toEqual(), etc.).
    • Replaced proxyquire and Sinon sandboxes/stubs/spies/timers with jest.mock(), jest.spyOn(), jest.fn(), and jest.useFakeTimers().
    • Modernized asynchronous test cases to use async/await and wrapped callback-based done() handlers in try/catch blocks to prevent hanging on test failures.

commits were migrated from #9218 to pass the cla check.

Impact

  • Maintainability & Consistency: Aligns @google-cloud/paginator with repository-wide efforts to standardize test infrastructure on Jest.
  • Developer Experience: Faster test execution, native TypeScript handling via ts-jest, and integrated code coverage reporting.
  • No Runtime Impact: Purely internal test and development dependency changes; no public APIs or runtime behaviors were modified.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request migrates the testing framework for the core/paginator package from Mocha, Sinon, and Proxyquire to Jest and ts-jest. This involves updating configuration files, replacing test scripts, and rewriting test assertions and mocks to use Jest's native capabilities. Feedback on these changes highlights a major version mismatch in package.json between jest (v30) and ts-jest (v29), suggesting a downgrade to version 29 for compatibility. Additionally, the newly introduced uuid and @types/uuid dependencies are unused and should be removed to prevent unnecessary bloat.

Comment thread core/paginator/package.json Outdated
Comment on lines +34 to +46
"@types/jest": "^30.0.0",
"@types/node": "^22.13.8",
"@types/proxyquire": "^1.3.31",
"@types/sinon": "^17.0.4",
"c8": "^10.1.3",
"codecov": "^3.8.3",
"@types/uuid": "^10.0.0",
"gts": "^6.0.2",
"jest": "^30.4.2",
"jsdoc": "^4.0.4",
"jsdoc-fresh": "^6.0.0",
"jsdoc-region-tag": "^5.0.0",
"mocha": "^11.1.0",
"linkinator": "^6.1.2",
"path-to-regexp": "^8.2.0",
"proxyquire": "^2.1.3",
"sinon": "^19.0.2",
"typescript": "^5.8.2"
"ts-jest": "^29.4.10",
"typescript": "^5.8.2",
"uuid": "^11.1.0"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

This PR introduces a couple of issues in devDependencies:

  1. Jest Version Mismatch: There is a major version mismatch between jest (^30.4.2) / @types/jest (^30.0.0) and ts-jest (^29.4.10). ts-jest major versions must align with the jest major version to prevent compatibility issues and runtime errors. Since Jest 30 is not yet stable, it is highly recommended to downgrade jest and @types/jest to version 29.
  2. Unused Dependencies: Both uuid and @types/uuid have been added to devDependencies, but they are not imported or used anywhere in the codebase (the tests use the built-in crypto.randomUUID()). They should be removed to avoid unnecessary bloat.
    "@types/jest": "^29.5.12",
    "@types/node": "^22.13.8",
    "gts": "^6.0.2",
    "jest": "^29.7.0",
    "jsdoc": "^4.0.4",
    "jsdoc-fresh": "^6.0.0",
    "jsdoc-region-tag": "^5.0.0",
    "linkinator": "^6.1.2",
    "path-to-regexp": "^8.2.0",
    "ts-jest": "^29.4.10",
    "typescript": "^5.8.2"
References
  1. When managing dependencies in package.json, ensure that @types packages are kept in sync with the major version of their corresponding main packages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Made these dependency modifications

@danieljbruce danieljbruce changed the title test: do testing with jest instead of mocha test: do testing with jest instead of mocha for paginator Aug 28, 2026
'performance',
],
});
jest.useFakeTimers();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the only thing I'm a bit skeptical about because I've seen cases where a very particular subset of methods need to be faked, but its probably fine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I hit a few of those. The specific issue was that sinon started hooking stuff like nextTick(), so it was breaking tests that literally just wanted to finish on the next tick. If jest didn't make that change, it should be completely fine. If it did, we might still have to look at those.

@danieljbruce danieljbruce changed the title test: do testing with jest instead of mocha for paginator test: Do testing with jest instead of mocha for paginator Aug 28, 2026
@danieljbruce
danieljbruce marked this pull request as ready for review August 28, 2026 19:33
@danieljbruce
danieljbruce requested a review from a team as a code owner August 28, 2026 19:33
@github-actions
github-actions Bot requested a review from westarle August 28, 2026 19:39
@danieljbruce
danieljbruce merged commit c5fea74 into main Aug 28, 2026
51 checks passed
@danieljbruce
danieljbruce deleted the migrate-paginator-to-jest-cla branch August 28, 2026 20:46
@danieljbruce
danieljbruce restored the migrate-paginator-to-jest-cla branch August 28, 2026 20:48
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