From 3ab8274789f55ff2ca4ffeb2ea8bc032a5377f61 Mon Sep 17 00:00:00 2001 From: Shivanee Persaud Date: Wed, 9 Sep 2026 14:48:58 -0700 Subject: [PATCH 1/3] test(gax): resolve linter warnings in apiCallable unit tests --- core/packages/gax/test/unit/apiCallable.ts | 145 ++++++++++----------- 1 file changed, 67 insertions(+), 78 deletions(-) diff --git a/core/packages/gax/test/unit/apiCallable.ts b/core/packages/gax/test/unit/apiCallable.ts index 92f8abea3fb..441a5e5728f 100644 --- a/core/packages/gax/test/unit/apiCallable.ts +++ b/core/packages/gax/test/unit/apiCallable.ts @@ -1173,8 +1173,8 @@ describe('createApiCall', () => { }); describe('Promise', () => { - it('calls api call', done => { - let deadlineArg: string; + it('calls api call', async () => { + let deadlineArg: string | undefined = undefined; function func( argument: {}, metadata: {}, @@ -1186,14 +1186,10 @@ describe('Promise', () => { } const apiCall = createApiCall(func); // eslint-disable-next-line @typescript-eslint/no-explicit-any - (apiCall as any)(null) - .then((response: number[]) => { - assert.ok(Array.isArray(response)); - assert.strictEqual(response[0], 42); - assert.ok(deadlineArg); - return done(); - }) - .catch(done); + const response = (await (apiCall as any)(null)) as number[]; + assert.ok(Array.isArray(response)); + assert.strictEqual(response[0], 42); + assert.ok(deadlineArg); }); it('emits error on rejected promise', async () => { @@ -1210,28 +1206,30 @@ describe('Promise', () => { await assert.rejects(apiCall({}, undefined)); }); - it('has cancel method', done => { + it('has cancel method', async () => { function func(argument: {}, metadata: {}, options: {}, callback: Function) { setTimeout(() => { callback(null, 42); }, 0); } - const apiCall = createApiCall(func, {cancel: done}); + const apiCall = createApiCall(func); // eslint-disable-next-line @typescript-eslint/no-explicit-any const promise = (apiCall as any)(null); - promise - .then(() => { - return done(new Error('should not reach')); - }) - .catch((err: {code: number}) => { + assert.strictEqual(typeof promise.cancel, 'function'); + promise.cancel(); + await assert.rejects( + async () => { + await promise; + }, + (err: GoogleError) => { assert(err instanceof GoogleError); assert.strictEqual(err.code, status.CANCELLED); - done(); - }); - promise.cancel(); + return true; + }, + ); }); - it('cancels retrying call', done => { + it('cancels retrying call', async () => { const retryOptions = utils.createRetryOptions(0, 0, 0, 0, 0, 0, 100); let callCount = 0; @@ -1259,18 +1257,13 @@ describe('Promise', () => { }); // eslint-disable-next-line @typescript-eslint/no-explicit-any const promise = (apiCall as any)(null); - promise - .then(() => { - return done(new Error('should not reach')); - }) - .catch(() => { - assert(callCount < 4); - done(); - }) - .catch(done); setTimeout(() => { promise.cancel(); }, 15); + await assert.rejects(async () => { + await promise; + }); + assert(callCount < 4); }); it('does not return promise when callback is supplied', done => { @@ -1326,9 +1319,9 @@ describe('retryable', () => { }); }); - it('retries the API call with promise', done => { + it('retries the API call with promise', async () => { let toAttempt = 3; - let deadlineArg: string; + let deadlineArg: string | undefined = undefined; function func( argument: {}, metadata: {}, @@ -1344,18 +1337,14 @@ describe('retryable', () => { callback(null, 1729); } const apiCall = createApiCall(func, settings); - apiCall({}, undefined) - .then(resp => { - assert.ok(Array.isArray(resp)); - assert.strictEqual(resp[0], 1729); - assert.strictEqual(toAttempt, 0); - assert.ok(deadlineArg); - return done(); - }) - .catch(done); + const resp = (await apiCall({}, undefined)) as [number, unknown, unknown]; + assert.ok(Array.isArray(resp)); + assert.strictEqual(resp[0], 1729); + assert.strictEqual(toAttempt, 0); + assert.ok(deadlineArg); }); - it('cancels in the middle of retries', done => { + it('cancels in the middle of retries', async () => { let callCount = 0; // eslint-disable-next-line @typescript-eslint/no-explicit-any function func(argument: {}, metadata: {}, options: {}, callback: Function) { @@ -1373,14 +1362,15 @@ describe('retryable', () => { } const apiCall = createApiCall(func, settings); const promise = apiCall({}, undefined); - promise - .then(() => { - return done(new Error('should not reach')); - }) - .catch((err: Error) => { + await assert.rejects( + async () => { + await promise; + }, + (err: Error) => { assert(err instanceof Error); - done(); - }); + return true; + }, + ); }); it("doesn't retry if no codes", done => { @@ -1566,7 +1556,7 @@ describe('retryable', () => { }); }); - it.skip('retries with exponential backoff', done => { + it.skip('retries with exponential backoff', async () => { const startTime = new Date(); const spy = sinon.spy(fail); @@ -1576,23 +1566,28 @@ describe('retryable', () => { settings: {timeout: 0, retry: retryOptions}, }); - void apiCall({}, undefined, err => { - assert(err instanceof Error); - assert.strictEqual(err!.code, FAKE_STATUS_CODE_1); - assert(err!.note); - const now = new Date(); - assert( - now.getTime() - startTime.getTime() >= backoff.totalTimeoutMillis!, - ); - const callsLowerBound = - backoff.totalTimeoutMillis! / - (backoff.maxRetryDelayMillis + backoff.maxRpcTimeoutMillis!); - const callsUpperBound = - backoff.totalTimeoutMillis! / backoff.initialRetryDelayMillis; - assert(spy.callCount > callsLowerBound); - assert(spy.callCount < callsUpperBound); - done(); - }).catch(done); + await assert.rejects( + async () => { + await apiCall({}, undefined); + }, + (err: GoogleError) => { + assert(err instanceof Error); + assert.strictEqual(err!.code, FAKE_STATUS_CODE_1); + assert(err!.note); + const now = new Date(); + assert( + now.getTime() - startTime.getTime() >= backoff.totalTimeoutMillis!, + ); + const callsLowerBound = + backoff.totalTimeoutMillis! / + (backoff.maxRetryDelayMillis + backoff.maxRpcTimeoutMillis!); + const callsUpperBound = + backoff.totalTimeoutMillis! / backoff.initialRetryDelayMillis; + assert(spy.callCount > callsLowerBound); + assert(spy.callCount < callsUpperBound); + return true; + }, + ); }); it.skip('reports A/B testing', () => { @@ -1640,12 +1635,12 @@ describe('retryable', () => { }); }); - it('forwards metadata to builder', done => { + it('forwards metadata to builder', async () => { function func(argument: {}, metadata: {}, options: {}, callback: Function) { callback(null, {}); } - let gotHeaders: {h1?: string; h2?: string}; + let gotHeaders: {h1?: string; h2?: string} = {}; const mockBuilder = (abTest: {}, headers: {}) => { gotHeaders = headers; }; @@ -1659,14 +1654,8 @@ describe('retryable', () => { h1: 'val1', h2: 'val2', }; - void apiCall({}, {otherArgs: {headers}}).then(() => { - try { - assert.strictEqual(gotHeaders.h1, 'val1'); - assert.strictEqual(gotHeaders.h2, 'val2'); - return done(); - } catch (err) { - return done(err); - } - }); + await apiCall({}, {otherArgs: {headers}}); + assert.strictEqual(gotHeaders.h1, 'val1'); + assert.strictEqual(gotHeaders.h2, 'val2'); }); }); From 8104f5fd78962827c66d1b825fb9bf33887a5ed3 Mon Sep 17 00:00:00 2001 From: Shivanee Persaud Date: Thu, 10 Sep 2026 11:34:12 -0700 Subject: [PATCH 2/3] style(gax): apply GTS and Prettier formatting fixes --- core/packages/gax/src/apitypes.ts | 10 ++-------- core/packages/gax/src/fallbackServiceStub.ts | 7 ++++--- .../gax/src/paginationCalls/pagedApiCaller.ts | 2 +- core/packages/gax/src/streamingCalls/streaming.ts | 12 +++++++++--- core/packages/gax/src/transcoding.ts | 10 +++++++--- core/packages/gax/test/unit/pagedIteration.ts | 3 +-- core/packages/gax/test/unit/streamArrayParser.ts | 3 +-- core/packages/gax/test/unit/streaming.ts | 2 +- core/packages/gax/test/unit/transcoding.ts | 13 ++++++++----- 9 files changed, 34 insertions(+), 28 deletions(-) diff --git a/core/packages/gax/src/apitypes.ts b/core/packages/gax/src/apitypes.ts index 6004cc63a64..a7141cf1d1c 100644 --- a/core/packages/gax/src/apitypes.ts +++ b/core/packages/gax/src/apitypes.ts @@ -35,10 +35,7 @@ export interface GRPCCallResult { // when it might be useful for users. export interface RequestType { [index: string]: - | string - | number - | RequestType - | Array; + string | number | RequestType | Array; } export type ResponseType = {} | null; export type NextPageRequestType = { @@ -85,10 +82,7 @@ export type BiDiStreamingCall = ( options: {}, ) => Duplex & GRPCCallResult; export type GRPCCall = - | UnaryCall - | ServerStreamingCall - | ClientStreamingCall - | BiDiStreamingCall; + UnaryCall | ServerStreamingCall | ClientStreamingCall | BiDiStreamingCall; // GAX wraps gRPC calls so that the wrapper functions return either a // cancellable promise, or a stream (also cancellable!) diff --git a/core/packages/gax/src/fallbackServiceStub.ts b/core/packages/gax/src/fallbackServiceStub.ts index b096ffc81f6..5171ec905ad 100644 --- a/core/packages/gax/src/fallbackServiceStub.ts +++ b/core/packages/gax/src/fallbackServiceStub.ts @@ -14,7 +14,9 @@ * limitations under the License. */ -import type {Response as NodeFetchResponse} from 'node-fetch' with {'resolution-mode': 'import'}; +import type {Response as NodeFetchResponse} from 'node-fetch' with { + 'resolution-mode': 'import', +}; import {AuthClient, GoogleAuth, gaxios} from 'google-auth-library'; import * as serializer from 'proto3-json-serializer'; @@ -35,8 +37,7 @@ import type {Agent as HttpsAgent} from 'https'; // - https://github.com/node-fetch/node-fetch#custom-agent // - https://github.com/googleapis/gax-nodejs/pull/1534 let agentOption: - | ((parsedUrl: {protocol: string}) => HttpAgent | HttpsAgent) - | null = null; + ((parsedUrl: {protocol: string}) => HttpAgent | HttpsAgent) | null = null; if (isNodeJS()) { const http = require('http'); const https = require('https'); diff --git a/core/packages/gax/src/paginationCalls/pagedApiCaller.ts b/core/packages/gax/src/paginationCalls/pagedApiCaller.ts index c75f14bc197..0cb2bf5efa1 100644 --- a/core/packages/gax/src/paginationCalls/pagedApiCaller.ts +++ b/core/packages/gax/src/paginationCalls/pagedApiCaller.ts @@ -21,8 +21,8 @@ import { SimpleCallbackFunction, UnaryCall, RequestType, + APICallback, } from '../apitypes'; -import {APICallback} from '../apitypes'; import {OngoingCall, OngoingCallPromise} from '../call'; import {CallOptions} from '../gax'; import {GoogleError} from '../googleError'; diff --git a/core/packages/gax/src/streamingCalls/streaming.ts b/core/packages/gax/src/streamingCalls/streaming.ts index 81f6566049a..d223d0e80b1 100644 --- a/core/packages/gax/src/streamingCalls/streaming.ts +++ b/core/packages/gax/src/streamingCalls/streaming.ts @@ -16,7 +16,14 @@ /* This file describes the gRPC-streaming. */ -import {Duplex, DuplexOptions, Readable, Stream, Writable} from 'stream'; +import { + Duplex, + DuplexOptions, + Readable, + Stream, + Writable, + PassThrough, +} from 'stream'; import { APICallback, @@ -24,6 +31,7 @@ import { GRPCCallResult, RequestType, SimpleCallbackFunction, + ResponseType, } from '../apitypes'; import { RetryOptions, @@ -32,8 +40,6 @@ import { } from '../gax'; import {GoogleError} from '../googleError'; import {Status} from '../status'; -import {PassThrough} from 'stream'; -import {ResponseType} from '../apitypes'; // eslint-disable-next-line @typescript-eslint/no-var-requires const duplexify: DuplexifyConstructor = require('duplexify'); // eslint-disable-next-line @typescript-eslint/no-var-requires diff --git a/core/packages/gax/src/transcoding.ts b/core/packages/gax/src/transcoding.ts index 070612ec117..f855c8875ac 100644 --- a/core/packages/gax/src/transcoding.ts +++ b/core/packages/gax/src/transcoding.ts @@ -137,7 +137,9 @@ function validateUriPath(propertyName: string, value: string): void { // valid domain-scoped resource segments (e.g. projects/example.com:project-id). const segments = value.split('/'); if (segments.some(segment => segment === '.' || segment === '..')) { - throw new Error(`Value for ${propertyName} must not contain segments that are exactly . or ..`); + throw new Error( + `Value for ${propertyName} must not contain segments that are exactly . or ..`, + ); } } } @@ -164,7 +166,9 @@ export function buildQueryStringComponents( } else { resultList.push( `${prefix}${encodeWithoutSlashes(key)}=${encodeWithoutSlashes( - requestValue === null || requestValue === undefined ? 'null' : requestValue.toString(), + requestValue === null || requestValue === undefined + ? 'null' + : requestValue.toString(), )}`, ); } @@ -187,7 +191,7 @@ export function buildQueryStringComponents( export function encodeWithSlashes(str: string): string { return encodeURIComponent(str).replace( /[!'()*]/g, // Characters preserved by encodeURIComponent - character => '%' + character.charCodeAt(0).toString(16).toUpperCase() + character => '%' + character.charCodeAt(0).toString(16).toUpperCase(), ); } diff --git a/core/packages/gax/test/unit/pagedIteration.ts b/core/packages/gax/test/unit/pagedIteration.ts index 6d40bc66bc8..75ff5c6ba76 100644 --- a/core/packages/gax/test/unit/pagedIteration.ts +++ b/core/packages/gax/test/unit/pagedIteration.ts @@ -20,14 +20,13 @@ import assert from 'assert'; import * as pumpify from 'pumpify'; import * as sinon from 'sinon'; -import {PassThrough} from 'stream'; +import {PassThrough, Stream} from 'stream'; import streamEvents from 'stream-events'; import {PageDescriptor} from '../../src/paginationCalls/pageDescriptor'; import {APICallback, GaxCall, RequestType} from '../../src/apitypes'; import {describe, it, beforeEach} from 'mocha'; import * as util from './utils'; -import {Stream} from 'stream'; import * as gax from '../../src/gax'; import * as warnings from '../../src/warnings'; diff --git a/core/packages/gax/test/unit/streamArrayParser.ts b/core/packages/gax/test/unit/streamArrayParser.ts index ca9da211b27..6eaab47b111 100644 --- a/core/packages/gax/test/unit/streamArrayParser.ts +++ b/core/packages/gax/test/unit/streamArrayParser.ts @@ -17,10 +17,9 @@ import assert from 'assert'; import {StreamArrayParser} from '../../src/streamArrayParser'; import {before, describe, it} from 'mocha'; -import {pipeline} from 'stream'; +import {pipeline, PassThrough} from 'stream'; import path = require('path'); import protobuf = require('protobufjs'); -import {PassThrough} from 'stream'; import {toProtobufJSON} from './utils'; interface User { diff --git a/core/packages/gax/test/unit/streaming.ts b/core/packages/gax/test/unit/streaming.ts index e9e54dba21b..0480b63b6e3 100644 --- a/core/packages/gax/test/unit/streaming.ts +++ b/core/packages/gax/test/unit/streaming.ts @@ -27,13 +27,13 @@ import { RequestType, CancellableStream, SimpleCallbackFunction, + APICallback, } from '../../src/apitypes'; import {createApiCall} from '../../src/createApiCall'; import {StreamingApiCaller} from '../../src/streamingCalls/streamingApiCaller'; import * as gax from '../../src/gax'; import {StreamDescriptor} from '../../src/streamingCalls/streamDescriptor'; import * as streaming from '../../src/streamingCalls/streaming'; -import {APICallback} from '../../src/apitypes'; import * as warnings from '../../src/warnings'; import internal = require('stream'); import {StreamArrayParser} from '../../src/streamArrayParser'; diff --git a/core/packages/gax/test/unit/transcoding.ts b/core/packages/gax/test/unit/transcoding.ts index 3d1d613adf1..5eb901223f2 100644 --- a/core/packages/gax/test/unit/transcoding.ts +++ b/core/packages/gax/test/unit/transcoding.ts @@ -382,7 +382,7 @@ describe('gRPC to HTTP transcoding', () => { assert.strictEqual(encodeWithSlashes(unreserved), unreserved); // Reserved and special characters: should be percent encoded, including !\'()* - const specialChars = "!\'()*"; + const specialChars = "!'()*"; const encoded = encodeWithSlashes(specialChars); // ! -> %21, ' -> %27, ( -> %28, ) -> %29, * -> %2A assert.strictEqual(encoded, '%21%27%28%29%2A'); @@ -440,7 +440,7 @@ describe('gRPC to HTTP transcoding', () => { applyPattern( 'projects/*/locations/*/agents/*/sessions/**', 'projects/p/locations/l/agents/a/sessions/agents/../subagent', - 'session' + 'session', ); }, /Value for session must not contain segments that are exactly \. or \.\./); }); @@ -450,7 +450,7 @@ describe('gRPC to HTTP transcoding', () => { applyPattern( 'projects/*/locations/*/agents/*/sessions/**', 'projects/p/locations/l/agents/a/sessions/agents/./subagent', - 'session' + 'session', ); }, /Value for session must not contain segments that are exactly \. or \.\./); }); @@ -459,9 +459,12 @@ describe('gRPC to HTTP transcoding', () => { const res = applyPattern( 'projects/*/locations/*/agents/*/sessions/**', 'projects/p/locations/l/agents/a/sessions/..?$foo=BAR#', - 'session' + 'session', + ); + assert.strictEqual( + res, + 'projects/p/locations/l/agents/a/sessions/..%3F%24foo%3DBAR%23', ); - assert.strictEqual(res, 'projects/p/locations/l/agents/a/sessions/..%3F%24foo%3DBAR%23'); }); it('applyPattern should handle optional unmatched groups gracefully without throwing TypeErrors', () => { From 42fa124626cafae3853889141809e26dfecf9eb4 Mon Sep 17 00:00:00 2001 From: Shivanee Persaud Date: Thu, 17 Sep 2026 15:54:35 -0700 Subject: [PATCH 3/3] chore(gax): resolve remaining eslint errors across the package Clears all 58 ESLint rule errors reported for core/packages/gax, leaving the package at zero errors. Source fixes: - pagedApiCaller: terminate the pagination chain with .catch() instead of a second then() argument (promise/catch-or-return). - longrunning: throw the error rather than returning Promise.reject() (promise/no-return-wrap). - iamService, locationService: convert close() to async/await so the stub teardown no longer needs a then() callback (promise/always-return). Test fixes (bundling, longrunning, pagedIteration, regapic): - Add explicit terminal returns to then() callbacks that fell through (promise/always-return). - Terminate done()-style chains with .catch(done) so assertion failures surface as test failures instead of unhandled rejections (promise/catch-or-return). The 9 remaining reported "errors" are pre-existing TSConfig parsing errors from the nested test sub-projects (browser-test, showcase-*, test-application), which are excluded by .eslintignore and by bin/linter.mjs. Verified: eslint clean, tsc --noEmit clean, 535 unit tests passing. --- core/packages/gax/src/iamService.ts | 10 +- core/packages/gax/src/locationService.ts | 10 +- .../gax/src/longRunningCalls/longrunning.ts | 2 +- .../gax/src/paginationCalls/pagedApiCaller.ts | 11 +- core/packages/gax/test/unit/bundling.ts | 6 +- core/packages/gax/test/unit/longrunning.ts | 16 + core/packages/gax/test/unit/pagedIteration.ts | 5 + core/packages/gax/test/unit/regapic.ts | 335 ++++++++++-------- 8 files changed, 230 insertions(+), 165 deletions(-) diff --git a/core/packages/gax/src/iamService.ts b/core/packages/gax/src/iamService.ts index cb4eeadb931..6dca02b2efd 100644 --- a/core/packages/gax/src/iamService.ts +++ b/core/packages/gax/src/iamService.ts @@ -381,15 +381,13 @@ export class IamClient { * * The client will no longer be usable and all future behavior is undefined. */ - close(): Promise { + async close(): Promise { this.initialize().catch(console.error); if (!this._terminated) { - return this.iamPolicyStub!.then(stub => { - this._terminated = true; - stub.close(); - }); + const stub = await this.iamPolicyStub!; + this._terminated = true; + stub.close(); } - return Promise.resolve(); } } export interface IamClient { diff --git a/core/packages/gax/src/locationService.ts b/core/packages/gax/src/locationService.ts index 08ed1b0cdb3..165d9148745 100644 --- a/core/packages/gax/src/locationService.ts +++ b/core/packages/gax/src/locationService.ts @@ -518,15 +518,13 @@ export class LocationsClient { * The client will no longer be usable and all future behavior is undefined. * @returns {Promise} A promise that resolves when the client is closed. */ - close(): Promise { + async close(): Promise { this.initialize().catch(console.error); if (!this._terminated) { - return this.locationsStub!.then(stub => { - this._terminated = true; - stub.close(); - }); + const stub = await this.locationsStub!; + this._terminated = true; + stub.close(); } - return Promise.resolve(); } } diff --git a/core/packages/gax/src/longRunningCalls/longrunning.ts b/core/packages/gax/src/longRunningCalls/longrunning.ts index 492406c0811..c3740b8fda4 100644 --- a/core/packages/gax/src/longRunningCalls/longrunning.ts +++ b/core/packages/gax/src/longRunningCalls/longrunning.ts @@ -200,7 +200,7 @@ export class Operation extends EventEmitter { callback(err); return; } - return Promise.reject(err); + throw err; }, ); diff --git a/core/packages/gax/src/paginationCalls/pagedApiCaller.ts b/core/packages/gax/src/paginationCalls/pagedApiCaller.ts index 0cb2bf5efa1..acf46fa8ea0 100644 --- a/core/packages/gax/src/paginationCalls/pagedApiCaller.ts +++ b/core/packages/gax/src/paginationCalls/pagedApiCaller.ts @@ -164,10 +164,13 @@ export class PagedApiCaller implements APICaller { const maxResults = settings.maxResults || -1; const resourceCollector = new ResourceCollector(apiCall, maxResults); - resourceCollector.processAllPages(request).then( - resources => ongoingCall.callback(null, resources), - err => ongoingCall.callback(err), - ); + resourceCollector + .processAllPages(request) + .then(resources => { + ongoingCall.callback(null, resources); + return null; + }) + .catch(err => ongoingCall.callback(err)); } fail(ongoingCall: OngoingCallPromise, err: GoogleError): void { diff --git a/core/packages/gax/test/unit/bundling.ts b/core/packages/gax/test/unit/bundling.ts index 51651a640da..915e672c7e9 100644 --- a/core/packages/gax/test/unit/bundling.ts +++ b/core/packages/gax/test/unit/bundling.ts @@ -915,8 +915,8 @@ describe('bundleable', () => { warnStub.restore(); done(err); } - apiCall({field2: 'id1'}, undefined).then(callback, error); - apiCall({field2: 'id2'}, undefined).then(callback, error); + apiCall({field2: 'id1'}, undefined).then(callback).catch(error); + apiCall({field2: 'id2'}, undefined).then(callback).catch(error); }); it('suppresses bundling behavior by call options', done => { @@ -965,11 +965,13 @@ describe('bundleable', () => { if (expectedSuccess && expectedFailure) { done(); } + return null; }) .catch(done); const p = apiCall({field1: [1, 2, 3], field2: 'id'}, undefined); p.then(() => { done(new Error('should not succeed')); + return null; }).catch(err => { assert(err instanceof GoogleError); assert.strictEqual(err!.code, status.CANCELLED); diff --git a/core/packages/gax/test/unit/longrunning.ts b/core/packages/gax/test/unit/longrunning.ts index d8e14f14552..be85ee7aac7 100644 --- a/core/packages/gax/test/unit/longrunning.ts +++ b/core/packages/gax/test/unit/longrunning.ts @@ -179,6 +179,7 @@ describe('longrunning', () => { assert.strictEqual(operation.metadata, METADATA_VAL); assert.deepStrictEqual(rawResponse, PENDING_OP); done(); + return null; }) .catch(done); }); @@ -266,6 +267,7 @@ describe('longrunning', () => { assert.strictEqual(client.getOperation.callCount, 0); done(); }); + return null; }) .catch(done); }); @@ -294,6 +296,7 @@ describe('longrunning', () => { assert.strictEqual(client.getOperation.callCount, 1); done(); }); + return null; }) .catch(error => { done(error); @@ -327,6 +330,7 @@ describe('longrunning', () => { }), undefined, ); + return null; }) .catch(error => { done(error); @@ -359,6 +363,7 @@ describe('longrunning', () => { assert.deepStrictEqual(rawResponse, SUCCESSFUL_OP); assert.strictEqual(client.getOperation.callCount, 1); done(); + return null; }) .catch(error => { done(error); @@ -383,6 +388,7 @@ describe('longrunning', () => { }) .then(() => { done(new Error('Should not get here.')); + return null; }) .catch(error => { assert(error instanceof Error); @@ -417,6 +423,7 @@ describe('longrunning', () => { assert.deepStrictEqual(rawResponse, SUCCESSFUL_OP); assert.strictEqual(client.getOperation.callCount, expectedCalls); done(); + return null; }) .catch(err => { done(err); @@ -467,6 +474,7 @@ describe('longrunning', () => { }) .then(() => { done(new Error('should not get here')); + return null; }) .catch(err => { assert.strictEqual(client.getOperation.callCount, expectedCalls); @@ -498,6 +506,7 @@ describe('longrunning', () => { assert.strictEqual(metadata, METADATA_VAL); assert.deepStrictEqual(rawResponse, BAD_OP); done(); + return null; }) .catch(done); }); @@ -528,12 +537,14 @@ describe('longrunning', () => { assert.strictEqual(client.cancelOperation.called, true); assert.strictEqual(client.cancelGetOperationSpy.called, true); done(); + return null; }) .catch(done); return p; }) .then(() => { done(new Error('should not get here')); + return null; }) .catch(err => { done(err); @@ -569,6 +580,7 @@ describe('longrunning', () => { operation.on('error', () => { done('should not get here'); }); + return null; }) .catch(err => { done(err); @@ -602,6 +614,7 @@ describe('longrunning', () => { assert.strictEqual(err.message, 'operation error'); done(); }); + return null; }) .catch(err => { done(err); @@ -638,6 +651,7 @@ describe('longrunning', () => { assert.strictEqual(err.message, googleError.message); done(); }); + return null; }) .catch(err => { done(err); @@ -691,6 +705,7 @@ describe('longrunning', () => { operation.removeAllListeners(); done(); }); + return null; }) .catch(err => { done(err); @@ -732,6 +747,7 @@ describe('longrunning', () => { ); done(); }); + return null; }) .catch(err => { done(err); diff --git a/core/packages/gax/test/unit/pagedIteration.ts b/core/packages/gax/test/unit/pagedIteration.ts index 75ff5c6ba76..3aa59b610ce 100644 --- a/core/packages/gax/test/unit/pagedIteration.ts +++ b/core/packages/gax/test/unit/pagedIteration.ts @@ -80,6 +80,7 @@ describe('paged iteration', () => { ); warnStub.restore(); done(); + return null; }) .catch(done); }); @@ -94,6 +95,7 @@ describe('paged iteration', () => { assert.ok(Array.isArray(results)); assert.deepStrictEqual(results[0], expected); done(); + return null; }) .catch(done); }); @@ -146,6 +148,7 @@ describe('paged iteration', () => { expected++; } done(); + return null; }) .catch(done); }); @@ -209,6 +212,7 @@ describe('paged iteration', () => { // @ts-ignore response type assert.strictEqual(resources[0].length, pageSize * pagesToStream); done(); + return null; }) .catch(done); }); @@ -229,6 +233,7 @@ describe('paged iteration', () => { expected++; } assert.strictEqual(spy.callCount, 3); + return null; }); }); diff --git a/core/packages/gax/test/unit/regapic.ts b/core/packages/gax/test/unit/regapic.ts index c630d2c8b21..276f97dbcd6 100644 --- a/core/packages/gax/test/unit/regapic.ts +++ b/core/packages/gax/test/unit/regapic.ts @@ -103,6 +103,7 @@ describe('REGAPIC', () => { done(err); } }); + return null; }); }); @@ -139,6 +140,7 @@ describe('REGAPIC', () => { done(err); } }); + return null; }); }); @@ -160,6 +162,7 @@ describe('REGAPIC', () => { done(err); } }); + return null; }); }); @@ -182,6 +185,7 @@ describe('REGAPIC', () => { done(err); } }); + return null; }); }); @@ -214,6 +218,7 @@ describe('REGAPIC', () => { done(err); } }); + return null; }); }); @@ -232,21 +237,25 @@ describe('REGAPIC', () => { new Response(Buffer.from(JSON.stringify(responseObject))), ); - gaxGrpc.createStub(libraryService, stubOptions).then(libStub => { - libStub.getShelf(requestObject, {}, {}, (err?: {}, result?: {}) => { - assert.strictEqual(spy.getCall(0).returnValue?.queryString, ''); - assert.strictEqual(err, null); - assert.strictEqual( - 'shelf-name', - (result as {name: {}; theme: {}; type: {}}).name, - ); - assert.strictEqual( - 'TYPEONE', - (result as {name: {}; theme: {}; type: {}}).type, - ); - done(); - }); - }, /* catch: */ done); + gaxGrpc + .createStub(libraryService, stubOptions) + .then(libStub => { + libStub.getShelf(requestObject, {}, {}, (err?: {}, result?: {}) => { + assert.strictEqual(spy.getCall(0).returnValue?.queryString, ''); + assert.strictEqual(err, null); + assert.strictEqual( + 'shelf-name', + (result as {name: {}; theme: {}; type: {}}).name, + ); + assert.strictEqual( + 'TYPEONE', + (result as {name: {}; theme: {}; type: {}}).type, + ); + done(); + }); + return null; + }) + .catch(done); }); it('should support enum conversion in proto message request using symbolic name', done => { @@ -263,13 +272,17 @@ describe('REGAPIC', () => { new Response(Buffer.from(JSON.stringify(shelf))), ); - gaxGrpc.createStub(libraryService, stubOptions).then(libStub => { - libStub.createShelf(requestObject, {}, {}, (err?: {}) => { - assert.strictEqual(spy.getCall(0).returnValue?.queryString, ''); - assert.strictEqual(err, null); - done(); - }); - }, /* catch: */ done); + gaxGrpc + .createStub(libraryService, stubOptions) + .then(libStub => { + libStub.createShelf(requestObject, {}, {}, (err?: {}) => { + assert.strictEqual(spy.getCall(0).returnValue?.queryString, ''); + assert.strictEqual(err, null); + done(); + }); + return null; + }) + .catch(done); }); it('should support enum conversion in proto message request using type value', done => { @@ -286,13 +299,17 @@ describe('REGAPIC', () => { new Response(Buffer.from(JSON.stringify(shelf))), ); - gaxGrpc.createStub(libraryService, stubOptions).then(libStub => { - libStub.createShelf(requestObject, {}, {}, (err?: {}) => { - assert.strictEqual(spy.getCall(0).returnValue?.queryString, ''); - assert.strictEqual(err, null); - done(); - }); - }, /* catch: */ done); + gaxGrpc + .createStub(libraryService, stubOptions) + .then(libStub => { + libStub.createShelf(requestObject, {}, {}, (err?: {}) => { + assert.strictEqual(spy.getCall(0).returnValue?.queryString, ''); + assert.strictEqual(err, null); + done(); + }); + return null; + }) + .catch(done); }); }); @@ -330,7 +347,9 @@ describe('REGAPIC', () => { ); done(); }); - }, done); + return null; + }) + .catch(done); }); it('should request numeric enums if passed as symbolic name', done => { @@ -362,7 +381,9 @@ describe('REGAPIC', () => { assert.strictEqual(err, null); done(); }); - }, /* catch: */ done); + return null; + }) + .catch(done); }); it('should preserve query string when appending numeric enums parameter', done => { @@ -393,7 +414,9 @@ describe('REGAPIC', () => { assert.strictEqual(err, null); done(); }); - }, done); + return null; + }) + .catch(done); }); it('should request numeric enums if passed as an unknown number', done => { @@ -421,7 +444,9 @@ describe('REGAPIC', () => { assert.strictEqual(err, null); done(); }); - }, done); + return null; + }) + .catch(done); }); }); @@ -441,36 +466,40 @@ describe('REGAPIC', () => { new Response(Buffer.from(JSON.stringify(responseObject))), ); - gaxGrpc.createStub(libraryService, stubOptions).then(libStub => { - libStub.getBook(requestObject, {}, {}, (err?: {}, result?: {}) => { - assert.strictEqual(err, null); - assert.strictEqual( - 'book-name', - ( - result as { - name: {}; - author: {}; - title: {}; - read: false; - bookId: {}; - } - ).name, - ); - assert.strictEqual( - '9007199254740992', - ( - result as { - name: {}; - author: {}; - title: {}; - read: false; - bookId: {}; - } - ).bookId, - ); - done(); - }); - }, /* catch: */ done); + gaxGrpc + .createStub(libraryService, stubOptions) + .then(libStub => { + libStub.getBook(requestObject, {}, {}, (err?: {}, result?: {}) => { + assert.strictEqual(err, null); + assert.strictEqual( + 'book-name', + ( + result as { + name: {}; + author: {}; + title: {}; + read: false; + bookId: {}; + } + ).name, + ); + assert.strictEqual( + '9007199254740992', + ( + result as { + name: {}; + author: {}; + title: {}; + read: false; + bookId: {}; + } + ).bookId, + ); + done(); + }); + return null; + }) + .catch(done); }); it('small number long data type conversion in proto message response', done => { @@ -488,36 +517,40 @@ describe('REGAPIC', () => { new Response(Buffer.from(JSON.stringify(responseObject))), ); - gaxGrpc.createStub(libraryService, stubOptions).then(libStub => { - libStub.getBook(requestObject, {}, {}, (err?: {}, result?: {}) => { - assert.strictEqual(err, null); - assert.strictEqual( - 'book-name', - ( - result as { - name: {}; - author: {}; - title: {}; - read: false; - bookId: {}; - } - ).name, - ); - assert.strictEqual( - '42', - ( - result as { - name: {}; - author: {}; - title: {}; - read: false; - bookId: {}; - } - ).bookId, - ); - done(); - }); - }, done); + gaxGrpc + .createStub(libraryService, stubOptions) + .then(libStub => { + libStub.getBook(requestObject, {}, {}, (err?: {}, result?: {}) => { + assert.strictEqual(err, null); + assert.strictEqual( + 'book-name', + ( + result as { + name: {}; + author: {}; + title: {}; + read: false; + bookId: {}; + } + ).name, + ); + assert.strictEqual( + '42', + ( + result as { + name: {}; + author: {}; + title: {}; + read: false; + bookId: {}; + } + ).bookId, + ); + done(); + }); + return null; + }) + .catch(done); }); it('long data type conversion in proto message request', done => { @@ -536,36 +569,40 @@ describe('REGAPIC', () => { new Response(Buffer.from(JSON.stringify(responseObject))), ); - gaxGrpc.createStub(libraryService, stubOptions).then(libStub => { - libStub.getBook(requestObject, {}, {}, (err?: {}, result?: {}) => { - assert.strictEqual(err, null); - assert.strictEqual( - 'book-name', - ( - result as { - name: {}; - author: {}; - title: {}; - read: false; - bookId: {}; - } - ).name, - ); - assert.strictEqual( - bookId.toString(), - ( - result as { - name: {}; - author: {}; - title: {}; - read: false; - bookId: {}; - } - ).bookId, - ); - done(); - }); - }, done); + gaxGrpc + .createStub(libraryService, stubOptions) + .then(libStub => { + libStub.getBook(requestObject, {}, {}, (err?: {}, result?: {}) => { + assert.strictEqual(err, null); + assert.strictEqual( + 'book-name', + ( + result as { + name: {}; + author: {}; + title: {}; + read: false; + bookId: {}; + } + ).name, + ); + assert.strictEqual( + bookId.toString(), + ( + result as { + name: {}; + author: {}; + title: {}; + read: false; + bookId: {}; + } + ).bookId, + ); + done(); + }); + return null; + }) + .catch(done); }); }); describe('should support json minification', () => { @@ -606,7 +643,9 @@ describe('REGAPIC', () => { ); done(); }); - }, /* catch: */ done); + return null; + }) + .catch(done); }); it('should not send prettyPrint setting when json minification is not requested', done => { const requestObject = {name: 'shelves/shelf-name'}; @@ -622,28 +661,32 @@ describe('REGAPIC', () => { new Response(Buffer.from(JSON.stringify(responseObject))), ); - gaxGrpc.createStub(libraryService, stubOptions).then(libStub => { - libStub.getShelf(requestObject, {}, {}, (err?: {}, result?: {}) => { - assert.strictEqual( - 'string', - typeof spy.getCall(0).returnValue?.queryString, - ); - assert.doesNotMatch( - spy.getCall(0).returnValue?.queryString, - /prettyPrint/, - ); - assert.strictEqual(err, null); - assert.strictEqual( - 'shelf-name', - (result as {name: {}; theme: {}; type: {}}).name, - ); - assert.strictEqual( - 100, - (result as {name: {}; theme: {}; type: {}}).type, - ); - done(); - }); - }, /* catch: */ done); + gaxGrpc + .createStub(libraryService, stubOptions) + .then(libStub => { + libStub.getShelf(requestObject, {}, {}, (err?: {}, result?: {}) => { + assert.strictEqual( + 'string', + typeof spy.getCall(0).returnValue?.queryString, + ); + assert.doesNotMatch( + spy.getCall(0).returnValue?.queryString, + /prettyPrint/, + ); + assert.strictEqual(err, null); + assert.strictEqual( + 'shelf-name', + (result as {name: {}; theme: {}; type: {}}).name, + ); + assert.strictEqual( + 100, + (result as {name: {}; theme: {}; type: {}}).type, + ); + done(); + }); + return null; + }) + .catch(done); }); }); });