Repository navigation
test: remove --proxyquire-shim from logging and pubsub packages - #9640
danieljbruce wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request removes the --proxyquire-shim test flag across multiple packages and replaces the global proxyquire dependency with either a custom local implementation or direct sinon stubbing. In packages/google-cloud-translate/test/index.ts, proxyquire is replaced with a manual Module.prototype.require override. A critical feedback item points out that if the required module was not previously cached, the stubbed version remains in require.cache after the hook finishes, potentially polluting subsequent tests. It is recommended to explicitly delete the module from the cache in this scenario.
| Translate = require('../src/v2').Translate; | ||
| } finally { | ||
| mod.prototype.require = origRequire; | ||
| if (cached) require.cache[v2Path] = cached; |
There was a problem hiding this comment.
If cached is undefined (meaning the module was not previously loaded), the stubbed version of ../src/v2 remains in require.cache after the before hook finishes. This will pollute subsequent tests that require ../src/v2 by serving them the stubbed version instead of the real one. To prevent test pollution, explicitly delete the module from require.cache if it was not previously cached.
if (cached) {
require.cache[v2Path] = cached;
} else {
delete require.cache[v2Path];
}
Description
Replaces global proxyquire shim with local test helper in logging and pubsub.
Impact
Removes --proxyquire-shim from logging, logging-bunyan, logging-winston, and pubsub test scripts.
Changes
handwritten/logging,handwritten/logging-bunyan,handwritten/logging-winston,handwritten/pubsub: Add localtest/proxyquire.tshelper built onModule.prototype.requireandrequire.cache../proxyquireand remove--proxyquire-shimfrom theirpackage.jsontest scripts.Testing
pnpm testunder both Node.js and Bun (JS_RUNTIME=bun) inhandwritten/logging,handwritten/logging-bunyan,handwritten/logging-winston, andhandwritten/pubsub.bin/linter.mjs --strict.Alternatives
bin/proxyquire-bun-shim.cjspreload shim.