Skip to content

chore: remove proxyquire-bun-shim.cjs and runner flags - #9633

Closed
danieljbruce wants to merge 5 commits into
googleapis:mainfrom
danieljbruce:fix/remove-proxyquire-bun-shim
Closed

danieljbruce wants to merge 5 commits into
googleapis:mainfrom
danieljbruce:fix/remove-proxyquire-bun-shim

Conversation

@danieljbruce

@danieljbruce danieljbruce commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

Removes bin/proxyquire-bun-shim.cjs and all remaining Mocha and runner shim configuration.

Impact

Eliminates the global Bun proxyquire preload shim from the test runner.

Changes

Testing

  • Verified unit tests across all migrated packages pass under both Node.js and Bun (JS_RUNTIME=bun) without bin/proxyquire-bun-shim.cjs.
  • Verified strict lint and type checks pass via bin/linter.mjs --strict.

Alternatives

  • Not merging this pull request was considered, which would leave dead shim code and unused --proxyquire-shim runner flags in the repository.

@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 global Bun proxyquire shim and replaces it with package-local proxyquire implementations or direct sinon stubbing across multiple packages. However, critical issues were found in the nodejs-googleapis-common package: instantiating this.GoogleAuth instead of GoogleAuth in authplus.ts will cause a runtime TypeError, and the corresponding unit tests attempt to stub an undefined prototype. The reviewer recommends instantiating GoogleAuth directly and stubbing GoogleAuth.prototype by importing it from google-auth-library.

Compute | JWT | UserRefreshClient | BaseExternalAccountClient | Impersonated
> {
this._cachedAuth = new GoogleAuth(options);
this._cachedAuth = new this.GoogleAuth(options);

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.

critical

Using this.GoogleAuth will result in a runtime TypeError: this.GoogleAuth is not a constructor because GoogleAuth is not defined as a property on the AuthPlus class or its prototype. It should be instantiated directly using the imported GoogleAuth class.

Suggested change
this._cachedAuth = new this.GoogleAuth(options);
this._cachedAuth = new GoogleAuth(options);
References
  1. When instantiating a specific client class where the class name is a local constant (and not a dynamic parameter), instantiate the class directly (e.g., new v1.InstanceAdminClient(...)) to ensure type safety and avoid unnecessary dynamic lookups or any casts.

Comment on lines 15 to +18
import * as assert from 'assert';
import {describe, it} from 'mocha';
import * as proxyquire from 'proxyquire';
import * as AuthPlus from '../src/authplus';
import {afterEach, describe, it} from 'mocha';
import * as sinon from 'sinon';
import {AuthPlus} from '../src/authplus';

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

Import GoogleAuth from google-auth-library so that its prototype can be stubbed directly in the unit tests.

Suggested change
import * as assert from 'assert';
import {describe, it} from 'mocha';
import * as proxyquire from 'proxyquire';
import * as AuthPlus from '../src/authplus';
import {afterEach, describe, it} from 'mocha';
import * as sinon from 'sinon';
import {AuthPlus} from '../src/authplus';
import * as assert from 'assert';
import {afterEach, describe, it} from 'mocha';
import * as sinon from 'sinon';
import {GoogleAuth} from 'google-auth-library';
import {AuthPlus} from '../src/authplus';

Comment on lines +38 to +41
sinon
.stub(auth.GoogleAuth.prototype, 'getClient')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.resolves({} as any);

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

Stub GoogleAuth.prototype directly instead of trying to access it via auth.GoogleAuth.prototype, which is undefined and will cause a runtime error.

Suggested change
sinon
.stub(auth.GoogleAuth.prototype, 'getClient')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.resolves({} as any);
sinon
.stub(GoogleAuth.prototype, 'getClient')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.resolves({} as any);

@danieljbruce

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 global proxyquire-bun-shim.cjs and the --proxyquire-shim flag from the test runner. Instead, it introduces a local, TypeScript-compatible proxyquire implementation across various package test directories and updates the tests to import it relatively. Additionally, several tests are refactored to use sinon stubbing directly instead of proxyquire, and Spanner observability tests are updated with improved lifecycle hooks for context manager cleanup. I have no feedback to provide as there are no review comments.

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