Repository navigation
test: remove --proxyquire-shim from logging and pubsub packages - #9644
Conversation
There was a problem hiding this comment.
Code Review
This pull request replaces the global proxyquire dependency with a custom local proxyquire.ts implementation across multiple packages (logging-bunyan, logging-winston, logging, and pubsub), updating the corresponding test scripts and imports. Feedback on the changes highlights two main areas of improvement: first, in the new proxyquire.ts files, wrapping individual property assignments in a try...catch block inside the loop would prevent the entire copy process from aborting if a single property assignment fails; second, across several test files, replacing the .then(noop, ...) promise rejection pattern with assert.rejects would make the tests more robust and prevent silent passes on unexpected promise resolutions.
|
This seems to just create a localized shim which is better and acceptable, but adjustments to the exact tests would likely be ideal. |
…translate (#9642) ## Description Replaces proxyquire with sinon and direct stubs across four packages. ## Impact Removes --proxyquire-shim from gax, googleapis-common, error-reporting, and translate unit tests. ## Changes - **Part 1 of 5 in stacked PR series**: **#9642** -> #9643 -> #9644 -> #9645 -> #9646 (b/570680750). - `core/packages/gax`: Replace `proxyquire` in `test/unit/grpc.ts` with `sinon.stub(fs, 'existsSync')` and remove `--proxyquire-shim` from `package.json`. - `core/packages/nodejs-googleapis-common`: Replace `proxyquire` in `test/test.authplus.ts` and `test/test.http2.ts` with `sinon.stub(auth.GoogleAuth.prototype, 'getClient')` and `sinon.stub(coreHttp2, 'connect')`, and remove `--proxyquire-shim` from `package.json`. - `handwritten/error-reporting`: Stub `util.makeAuthenticatedRequestFactory` and `RequestHandler.prototype.request` directly in `test/unit/google-apis/auth-client.ts` and remove `--proxyquire-shim` from `package.json`. - `packages/google-cloud-translate`: Intercept `Module.prototype.require` directly in `test/index.ts` `before()` hook and remove `--proxyquire-shim` from `package.json`. ## Testing - Executed `pnpm test` under both Node.js and Bun (`JS_RUNTIME=bun`) in `core/packages/gax`, `core/packages/nodejs-googleapis-common`, `handwritten/error-reporting`, and `packages/google-cloud-translate`. - Verified strict lint and type checks pass via `bin/linter.mjs --strict`. ## Alternatives - Not merging this pull request was considered, which would leave these four packages dependent on the global `bin/proxyquire-bun-shim.cjs` preload shim.
…properties in proxyquire helper
…se rejection assertions
0e7ca7c to
3ab8240
Compare
…ove-proxyquire-shim-logging-pubsub
… under Bun + Jest
…ove-proxyquire-shim-logging-pubsub
…re-shim-core-dns-ds-bq # Conflicts: # core/common/test/util.ts # handwritten/datastore/package.json # pnpm-lock.yaml
… parallel turbo build race
… in arrow failure test
…ove-proxyquire-shim-logging-pubsub # Conflicts: # handwritten/logging/package.json # handwritten/pubsub/package.json # pnpm-lock.yaml
|
[Generated] Per #9643 (comment), we opened #9759 ( We are waiting for #9759 to be merged and a new release of |
## Description Adds runtime-agnostic `createProxyquire` and `proxyquire` helpers to `google-test-utils`. ## Impact Releasing `createProxyquire` in `google-test-utils` avoids extra YAML flags across stacked PRs. ## Changes - Per #9643 (comment), extracts just the `createProxyquire` and `proxyquire` implementation in `core/test-utils` (`google-test-utils`) into a standalone PR. - We want to merge and release `google-test-utils` (`core/test-utils`) with `createProxyquire` first so that the rest of the stacked PRs (#9643, #9644, #9645, #9646) can consume the published `google-test-utils` package and do not need the extra `--filter "./core/test-utils" --ignore-scripts`, `pnpm --dir core/test-utils run compile`, `ensureWorkspacePackagesLinked()`, and `run prepare --if-present` flags in the `.yaml` files (`cloudbuild.yaml` and `.github/actions/pnpm-lockfile-check/action.yaml`). - `core/test-utils/src/proxyquire.ts`: Adds `createProxyquire`, `proxyquire`, `Proxyquire`, and `ProxyquireStubs` built on `Module.prototype.require` and `require.cache` with automatic caller path resolution (`Error.prepareStackTrace`) for Node.js and Bun (`JS_RUNTIME=bun`). - `core/test-utils/src/index.ts`: Exports `createProxyquire`, `proxyquire`, `Proxyquire`, and `ProxyquireStubs`. - `core/test-utils/test/proxyquire.test.ts`: Adds unit tests covering direct/transitive `@global` stubbing, `@noCallThru` / `noCallThru()` / `callThru()`, `noPreserveCache()` / `preserveCache()`, `null` stub `MODULE_NOT_FOUND` handling, and bare module stubs. ## Testing - Executed `pnpm --dir core/test-utils test` 5x on Node.js and `JS_RUNTIME=bun MOCHA_PARALLEL=false bun --bun run --cwd core/test-utils test` 5x on Bun ($\ge 95\%$ confidence, 25/25 unit tests passing). - Verified strict lint and TypeScript checks pass via `node ./bin/linter.mjs --strict` and `ci/run_conditional_tests.sh --strict`. ## Alternatives - Including `createProxyquire` directly inside #9643 alongside the `common`, `bigquery`, `datastore`, and `google-cloud-dns` migrations was considered, but because `.npmrc` sets `link-workspace-packages=false` and `enable-pre-post-scripts=true`, doing so before releasing `google-test-utils` requires extra `--filter "./core/test-utils" --ignore-scripts` and workspace-linking flags across the YAML files in the stack. - Not merging this PR would leave those temporary YAML workarounds in the stack PRs. --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
|
||
| after(() => { | ||
| sdk.shutdown(); | ||
| return sdk.shutdown(); |
There was a problem hiding this comment.
Nice catch returning sdk.shutdown() here (and on line 506) as well as returning assert.rejects(...) in test/index.ts and test/sink.ts so Mocha properly awaits teardown and rejection assertions.
…dns (#9643) ## Description Centralizes the runtime-agnostic `proxyquire` helper in `core/test-utils` (`google-test-utils`, Path 1B) and replaces the global `--proxyquire-shim` in `core/common`, `handwritten/bigquery`, `handwritten/datastore`, and `handwritten/google-cloud-dns`. ## Impact Removes `--proxyquire-shim` from `common`, `bigquery`, `datastore`, and `google-cloud-dns` test scripts while eliminating per-package `test/proxyquire.ts` duplication by exporting `proxyquire` and `createProxyquire` from `google-test-utils`. ## Changes - **Part 2 of 5 in stacked PR series**: #9642 -> **#9643** -> #9644 -> #9645 -> #9646 (b/570091189). - `core/test-utils`: Add runtime-agnostic `src/proxyquire.ts` helper (`proxyquire`, `createProxyquire`, `Proxyquire`, `ProxyquireStubs`) built on `Module.prototype.require` and `require.cache` with automatic caller path resolution (`Error.prepareStackTrace`) and unit tests in `test/proxyquire.test.ts`. - `core/common`, `handwritten/bigquery`, `handwritten/datastore`, `handwritten/google-cloud-dns`: Import `{proxyquire}` from `'google-test-utils'`, remove per-package `test/proxyquire.ts` shims, and remove `--proxyquire-shim` from `package.json` test scripts. ## Testing - Executed `pnpm test` in `core/test-utils` and under both Node.js and Bun (`JS_RUNTIME=bun`) in `core/common`, `handwritten/bigquery`, `handwritten/datastore`, and `handwritten/google-cloud-dns`. - Verified strict lint and type checks pass via `bin/linter.mjs --strict`. ## Alternatives - Per-package `test/proxyquire.ts` files (Path 1A) were replaced with a single centralized implementation in `core/test-utils` (`google-test-utils`, Path 1B) per review discussion in b/570091189.
…9645) ## Description Replaces the global `--proxyquire-shim` in `handwritten/bigtable`, `handwritten/spanner`, and `handwritten/storage` using the centralized `proxyquire` helper from `google-test-utils` (Path 1B). ## Impact Removes `--proxyquire-shim` from `bigtable`, `spanner`, and `storage` unit test scripts without duplicating per-package `test/proxyquire.ts` helpers. ## Changes - **Part 4 of 5 in stacked PR series**: #9642 -> #9643 -> #9644 -> **#9645** -> #9646 (b/570091189). - Stacked on #9644. - `handwritten/bigtable`, `handwritten/spanner`, `handwritten/storage`: Import `{proxyquire}` from `'google-test-utils'`, remove per-package `test/proxyquire.ts` helpers, and remove `--proxyquire-shim` from `package.json` test scripts. - `handwritten/bigtable/test/base64keymap.ts`: Remove unused `proxyquire` import. - `handwritten/spanner/observability-test/helper.ts` & `spanner.ts`: Call `context.disable()` in `setGlobalContextManager` and re-register the active context manager in `EndToEnd` `beforeEach` so OpenTelemetry context propagation remains isolated across test suites. ## Testing - Executed `pnpm test` under both Node.js and Bun (`JS_RUNTIME=bun`) in `handwritten/bigtable`, `handwritten/spanner`, and `handwritten/storage`. - Verified strict lint and type checks pass via `bin/linter.mjs --strict`. ## Alternatives - Per-package `test/proxyquire.ts` files (Path 1A) were replaced with the centralized `google-test-utils` helper (Path 1B) per review discussion in b/570091189.
## 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 - **Part 5 of 5 in stacked PR series**: #9642 -> #9643 -> #9644 -> #9645 -> **#9646** (b/570680750). - Stacked on #9645. - Delete `bin/proxyquire-bun-shim.cjs`. - Remove `--proxyquire-shim`, `BUN_ENABLE_PROXYQUIRE_SHIM`, and `proxyquire-bun-shim.cjs` preloading from `bin/run-test.cjs`. - Remove `proxyquire-bun-shim.cjs` from `.mocharc.cjs` and all 11 `core/packages/*/.mocharc.js` configuration files. ## 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.
Description
Replaces the global
--proxyquire-shiminhandwritten/logging,handwritten/logging-bunyan,handwritten/logging-winston, andhandwritten/pubsubusing the centralizedproxyquirehelper fromgoogle-test-utils(Path 1B).Impact
Removes
--proxyquire-shimfromlogging,logging-bunyan,logging-winston, andpubsubtest scripts without duplicating per-packagetest/proxyquire.tshelpers.Changes
handwritten/logging,handwritten/logging-bunyan,handwritten/logging-winston,handwritten/pubsub: Import{proxyquire}from'google-test-utils', remove per-packagetest/proxyquire.tshelpers, and remove--proxyquire-shimfrompackage.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
test/proxyquire.tsfiles (Path 1A) were replaced with the centralizedgoogle-test-utilshelper (Path 1B) per review discussion in b/570091189.