Skip to content

test: remove --proxyquire-shim from logging and pubsub packages - #9640

Closed
danieljbruce wants to merge 3 commits into
googleapis:mainfrom
danieljbruce:fix/remove-proxyquire-shim-logging-pubsub
Closed

danieljbruce wants to merge 3 commits into
googleapis:mainfrom
danieljbruce:fix/remove-proxyquire-shim-logging-pubsub

Conversation

@danieljbruce

@danieljbruce danieljbruce commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

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

Testing

  • Executed pnpm test under both Node.js and Bun (JS_RUNTIME=bun) in handwritten/logging, handwritten/logging-bunyan, handwritten/logging-winston, and handwritten/pubsub.
  • Verified strict lint and type checks pass via bin/linter.mjs --strict.

Alternatives

  • Not merging this pull request was considered, which would keep the Logging and Pub/Sub packages dependent on the global bin/proxyquire-bun-shim.cjs preload shim.

@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 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;

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

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];
      }

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.

1 participant