Repository navigation
chore: remove proxyquire-bun-shim.cjs and runner flags - #9633
danieljbruce wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
| this._cachedAuth = new this.GoogleAuth(options); | |
| this._cachedAuth = new GoogleAuth(options); |
References
- 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.
| 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'; |
There was a problem hiding this comment.
Import GoogleAuth from google-auth-library so that its prototype can be stubbed directly in the unit tests.
| 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'; |
| sinon | ||
| .stub(auth.GoogleAuth.prototype, 'getClient') | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| .resolves({} as any); |
There was a problem hiding this comment.
Stub GoogleAuth.prototype directly instead of trying to access it via auth.GoogleAuth.prototype, which is undefined and will cause a runtime error.
| 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); |
|
/gemini review |
There was a problem hiding this comment.
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.
6851c3b to
c6eb98e
Compare
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
bin/proxyquire-bun-shim.cjs.--proxyquire-shim,BUN_ENABLE_PROXYQUIRE_SHIM, andproxyquire-bun-shim.cjspreloading frombin/run-test.cjs.proxyquire-bun-shim.cjsfrom.mocharc.cjsand all 11core/packages/*/.mocharc.jsconfiguration files.Testing
JS_RUNTIME=bun) withoutbin/proxyquire-bun-shim.cjs.bin/linter.mjs --strict.Alternatives
--proxyquire-shimrunner flags in the repository.