diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 1b3626833..d1e8b5e6e 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -9,9 +9,9 @@ branchProtectionRules: - "ci/kokoro: System test" - docs - lint - - test (10) - test (12) - test (14) + - test (16) - cla/google - windows - OwlBot Post Processor diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 25251dbb7..f447b84ab 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [10, 12, 14] + node: [12, 14, 16] steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 diff --git a/.kokoro/continuous/node10/common.cfg b/.kokoro/continuous/node10/common.cfg deleted file mode 100644 index 894795cb4..000000000 --- a/.kokoro/continuous/node10/common.cfg +++ /dev/null @@ -1,34 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -# Build logs will be here -action { - define_artifacts { - regex: "**/*sponge_log.xml" - } -} - -# Bring in codecov.io token into the build as $KOKORO_KEYSTORE_DIR/73713_dpebot_codecov_token -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "dpebot_codecov_token" - } - } -} - -# Download trampoline resources. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" - -# Use the trampoline script to run in docker. -build_file: "nodejs-pubsub/.kokoro/trampoline_v2.sh" - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:10-user" -} -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/nodejs-pubsub/.kokoro/test.sh" -} diff --git a/.kokoro/continuous/node10/docs.cfg b/.kokoro/continuous/node10/docs.cfg deleted file mode 100644 index c8c5ddbe3..000000000 --- a/.kokoro/continuous/node10/docs.cfg +++ /dev/null @@ -1,4 +0,0 @@ -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/nodejs-pubsub/.kokoro/docs.sh" -} diff --git a/.kokoro/continuous/node10/test.cfg b/.kokoro/continuous/node10/test.cfg deleted file mode 100644 index 609c0cf0a..000000000 --- a/.kokoro/continuous/node10/test.cfg +++ /dev/null @@ -1,9 +0,0 @@ -# Bring in codecov.io token into the build as $KOKORO_KEYSTORE_DIR/73713_dpebot_codecov_token -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "dpebot_codecov_token" - } - } -} diff --git a/.kokoro/continuous/node8/common.cfg b/.kokoro/continuous/node8/common.cfg deleted file mode 100644 index 623fa5f51..000000000 --- a/.kokoro/continuous/node8/common.cfg +++ /dev/null @@ -1,24 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -# Build logs will be here -action { - define_artifacts { - regex: "**/*sponge_log.xml" - } -} - -# Download trampoline resources. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" - -# Use the trampoline script to run in docker. -build_file: "nodejs-pubsub/.kokoro/trampoline.sh" - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:8-user" -} -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/nodejs-pubsub/.kokoro/test.sh" -} diff --git a/.kokoro/continuous/node8/test.cfg b/.kokoro/continuous/node8/test.cfg deleted file mode 100644 index e69de29bb..000000000 diff --git a/.kokoro/presubmit/node10/common.cfg b/.kokoro/presubmit/node10/common.cfg deleted file mode 100644 index 894795cb4..000000000 --- a/.kokoro/presubmit/node10/common.cfg +++ /dev/null @@ -1,34 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -# Build logs will be here -action { - define_artifacts { - regex: "**/*sponge_log.xml" - } -} - -# Bring in codecov.io token into the build as $KOKORO_KEYSTORE_DIR/73713_dpebot_codecov_token -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "dpebot_codecov_token" - } - } -} - -# Download trampoline resources. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" - -# Use the trampoline script to run in docker. -build_file: "nodejs-pubsub/.kokoro/trampoline_v2.sh" - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:10-user" -} -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/nodejs-pubsub/.kokoro/test.sh" -} diff --git a/.kokoro/presubmit/node10/docs.cfg b/.kokoro/presubmit/node10/docs.cfg deleted file mode 100644 index c8c5ddbe3..000000000 --- a/.kokoro/presubmit/node10/docs.cfg +++ /dev/null @@ -1,4 +0,0 @@ -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/nodejs-pubsub/.kokoro/docs.sh" -} diff --git a/.kokoro/presubmit/node10/lint.cfg b/.kokoro/presubmit/node10/lint.cfg deleted file mode 100644 index 219d3808d..000000000 --- a/.kokoro/presubmit/node10/lint.cfg +++ /dev/null @@ -1,4 +0,0 @@ -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/nodejs-pubsub/.kokoro/lint.sh" -} diff --git a/.kokoro/presubmit/node10/test.cfg b/.kokoro/presubmit/node10/test.cfg deleted file mode 100644 index e69de29bb..000000000 diff --git a/.kokoro/presubmit/node8/common.cfg b/.kokoro/presubmit/node8/common.cfg deleted file mode 100644 index 623fa5f51..000000000 --- a/.kokoro/presubmit/node8/common.cfg +++ /dev/null @@ -1,24 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -# Build logs will be here -action { - define_artifacts { - regex: "**/*sponge_log.xml" - } -} - -# Download trampoline resources. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" - -# Use the trampoline script to run in docker. -build_file: "nodejs-pubsub/.kokoro/trampoline.sh" - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:8-user" -} -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/nodejs-pubsub/.kokoro/test.sh" -} diff --git a/.kokoro/presubmit/node8/test.cfg b/.kokoro/presubmit/node8/test.cfg deleted file mode 100644 index e69de29bb..000000000 diff --git a/package.json b/package.json index 8df7d1c88..e458284d4 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "license": "Apache-2.0", "author": "Google Inc.", "engines": { - "node": ">=10" + "node": ">=12.0.0" }, "repository": "googleapis/nodejs-pubsub", "main": "./build/src/index.js", @@ -57,8 +57,8 @@ "@types/long": "^4.0.0", "arrify": "^2.0.0", "extend": "^3.0.2", - "google-auth-library": "^7.0.0", - "google-gax": "2.30.4", + "google-auth-library": "^8.0.2", + "google-gax": "^3.0.1", "is-stream-ended": "^0.1.4", "lodash.snakecase": "^4.1.1", "p-defer": "^3.0.0" @@ -80,12 +80,12 @@ "c8": "^7.0.0", "codecov": "^3.0.0", "execa": "^5.0.0", - "gts": "^2.0.0", + "gts": "^3.1.0", "jsdoc": "^3.6.2", "jsdoc-fresh": "^1.0.1", "jsdoc-region-tag": "^1.0.2", "linkinator": "^2.0.0", - "mocha": "^8.0.0", + "mocha": "^9.2.2", "mv": "^2.1.1", "ncp": "^2.0.0", "null-loader": "^4.0.0", @@ -94,7 +94,7 @@ "sinon": "^14.0.0", "tmp": "^0.2.0", "ts-loader": "^9.0.0", - "typescript": "^3.8.3", + "typescript": "^4.6.4", "uuid": "^8.0.0", "webpack": "^5.0.0", "webpack-cli": "^4.0.0", diff --git a/samples/package.json b/samples/package.json index 6d4ad77f7..c16017ff9 100644 --- a/samples/package.json +++ b/samples/package.json @@ -9,7 +9,7 @@ "author": "Google Inc.", "repository": "googleapis/nodejs-pubsub", "engines": { - "node": ">=10" + "node": ">=12.0.0" }, "scripts": { "test": "mocha build/system-test --timeout 600000", diff --git a/src/message-queues.ts b/src/message-queues.ts index a46e71927..e8f431720 100644 --- a/src/message-queues.ts +++ b/src/message-queues.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {CallOptions, grpc} from 'google-gax'; +import {CallOptions, grpc, ServiceError} from 'google-gax'; import defer = require('p-defer'); import {Message, Subscriber} from './subscriber'; @@ -214,7 +214,7 @@ export class AckQueue extends MessageQueue { try { await client.acknowledge(reqOpts, this._options.callOptions!); } catch (e) { - throw new BatchError(e, ackIds, 'acknowledge'); + throw new BatchError(e as ServiceError, ackIds, 'acknowledge'); } } } @@ -258,7 +258,7 @@ export class ModAckQueue extends MessageQueue { try { await client.modifyAckDeadline(reqOpts, this._options.callOptions!); } catch (e) { - throw new BatchError(e, ackIds, 'modifyAckDeadline'); + throw new BatchError(e as ServiceError, ackIds, 'modifyAckDeadline'); } }); diff --git a/test/pubsub.ts b/test/pubsub.ts index d908973d5..fc3595234 100644 --- a/test/pubsub.ts +++ b/test/pubsub.ts @@ -29,7 +29,6 @@ import {Topic} from '../src/topic'; import * as util from '../src/util'; import {Schema, SchemaTypes} from '../src'; import {ISchema, SchemaViews} from '../src/schema'; - // eslint-disable-next-line @typescript-eslint/no-var-requires const PKG = require('../../package.json'); const sandbox = sinon.createSandbox(); @@ -150,7 +149,7 @@ describe('PubSub', () => { let PubSub: typeof pubsubTypes.PubSub; const PROJECT_ID = 'test-project'; - let pubsub: pubsubTypes.PubSub; + let pubsub: Partial; const OPTIONS = { projectId: PROJECT_ID, } as pubsubTypes.ClientConfig; @@ -272,7 +271,7 @@ describe('PubSub', () => { }); it('should not be in the opened state after close()', async () => { - await pubsub.close(); + await pubsub.close?.(); assert.strictEqual(pubsub.isOpen, false); }); @@ -340,13 +339,13 @@ describe('PubSub', () => { it('should throw if no Topic is provided', async () => { await assert.rejects(async () => { - await pubsub.createSubscription(undefined!, undefined!); + await pubsub.createSubscription?.(undefined!, undefined!); }, /A Topic is required for a new subscription\./); }); it('should throw if no subscription name is provided', async () => { await assert.rejects(async () => { - await pubsub.createSubscription(TOPIC_NAME, undefined!); + await pubsub.createSubscription?.(TOPIC_NAME, undefined!); }, /A subscription name is required./); }); @@ -355,7 +354,7 @@ describe('PubSub', () => { callback(null, apiResponse); }; - pubsub.createSubscription(TOPIC, SUB_NAME, done); + pubsub.createSubscription?.(TOPIC, SUB_NAME, done); }); it('should allow undefined/optional configuration options', done => { @@ -377,7 +376,7 @@ describe('PubSub', () => { setImmediate(done); return SUBSCRIPTION as subby.Subscription; }; - pubsub.createSubscription(TOPIC, SUB_NAME, opts, assert.ifError); + pubsub.createSubscription?.(TOPIC, SUB_NAME, opts, assert.ifError); }); it('should create a Topic object from a string', done => { @@ -389,7 +388,7 @@ describe('PubSub', () => { return TOPIC; }; - pubsub.createSubscription(TOPIC_NAME, SUB_NAME, assert.ifError); + pubsub.createSubscription?.(TOPIC_NAME, SUB_NAME, assert.ifError); }); it('should send correct request', done => { @@ -418,7 +417,7 @@ describe('PubSub', () => { done(); }; - pubsub.createSubscription(TOPIC, SUB_NAME, options, assert.ifError); + pubsub.createSubscription?.(TOPIC, SUB_NAME, options, assert.ifError); }); it('should pass options to the api request', done => { @@ -450,7 +449,7 @@ describe('PubSub', () => { done(); }; - pubsub.createSubscription(TOPIC, SUB_NAME, options, assert.ifError); + pubsub.createSubscription?.(TOPIC, SUB_NAME, options, assert.ifError); }); it('should discard flow control options', done => { @@ -481,7 +480,7 @@ describe('PubSub', () => { done(); }; - pubsub.createSubscription(TOPIC, SUB_NAME, options, assert.ifError); + pubsub.createSubscription?.(TOPIC, SUB_NAME, options, assert.ifError); }); it('should format the metadata', done => { @@ -500,7 +499,12 @@ describe('PubSub', () => { done(); }; - pubsub.createSubscription(TOPIC, SUB_NAME, fakeMetadata, assert.ifError); + pubsub.createSubscription?.( + TOPIC, + SUB_NAME, + fakeMetadata, + assert.ifError + ); }); describe('error', () => { @@ -529,7 +533,7 @@ describe('PubSub', () => { done(); } - pubsub.createSubscription(TOPIC_NAME, SUB_NAME, callback); + pubsub.createSubscription?.(TOPIC_NAME, SUB_NAME, callback); }); }); @@ -563,7 +567,7 @@ describe('PubSub', () => { done(); } - pubsub.createSubscription(TOPIC_NAME, SUB_NAME, callback); + pubsub.createSubscription?.(TOPIC_NAME, SUB_NAME, callback); }); }); }); @@ -605,7 +609,7 @@ describe('PubSub', () => { }); it('should return an error & API response', done => { - pubsub.createTopic('new-topic', (err, topic, apiResponse_) => { + pubsub.createTopic?.('new-topic', (err, topic, apiResponse_) => { assert.strictEqual(err, error); assert.strictEqual(topic, null); assert.strictEqual(apiResponse_, apiResponse); @@ -632,7 +636,7 @@ describe('PubSub', () => { return topicInstance as Topic; }; - pubsub.createTopic(topicName, (err, topic) => { + pubsub.createTopic?.(topicName, (err, topic) => { assert.ifError(err); assert.strictEqual(topic, topicInstance); done(); @@ -640,7 +644,7 @@ describe('PubSub', () => { }); it('should pass apiResponse to callback', done => { - pubsub.createTopic('new-topic', (err, topic, apiResponse_) => { + pubsub.createTopic?.('new-topic', (err, topic, apiResponse_) => { assert.ifError(err); assert.strictEqual(apiResponse_, apiResponse); done(); @@ -659,7 +663,7 @@ describe('PubSub', () => { it('should throw if no subscription name is provided', async () => { await assert.rejects(async () => { - await pubsub.detachSubscription(undefined!); + await pubsub.detachSubscription?.(undefined!); }, /A subscription name is required./); }); @@ -668,7 +672,7 @@ describe('PubSub', () => { .stub(pubsub, 'request') .callsArgOnWith(1, undefined, undefined, apiResponse); - pubsub.detachSubscription(SUB_NAME, (err, response) => { + pubsub.detachSubscription?.(SUB_NAME, (err, response) => { assert.strictEqual(response, apiResponse); done(); }); @@ -679,7 +683,7 @@ describe('PubSub', () => { .stub(pubsub, 'request') .callsArgOnWith(1, undefined, undefined, apiResponse); - pubsub.detachSubscription(SUB_NAME, undefined!, (_err, _response) => { + pubsub.detachSubscription?.(SUB_NAME, undefined!, (_err, _response) => { assert.strictEqual(_response, apiResponse); done(); }); @@ -692,7 +696,7 @@ describe('PubSub', () => { return SUBSCRIPTION as subby.Subscription; }); - await pubsub.detachSubscription(SUB_NAME); + await pubsub.detachSubscription?.(SUB_NAME); }); it('should send correct request', done => { @@ -713,7 +717,7 @@ describe('PubSub', () => { done(); }); - pubsub.detachSubscription(SUB_NAME, options, assert.ifError); + pubsub.detachSubscription?.(SUB_NAME, options, assert.ifError); }); it('should pass options to the api request', done => { @@ -732,7 +736,7 @@ describe('PubSub', () => { done(); }); - pubsub.detachSubscription(SUB_NAME, options, assert.ifError); + pubsub.detachSubscription?.(SUB_NAME, options, assert.ifError); }); }); @@ -755,10 +759,10 @@ describe('PubSub', () => { }); it('should do nothing if correct options are not set', () => { - pubsub.determineBaseUrl_(); + pubsub.determineBaseUrl_?.(); - assert.strictEqual(pubsub.options.servicePath, undefined); - assert.strictEqual(pubsub.options.port, undefined); + assert.strictEqual(pubsub.options?.servicePath, undefined); + assert.strictEqual(pubsub.options?.port, undefined); }); it('should use the apiEndpoint option', () => { @@ -766,10 +770,10 @@ describe('PubSub', () => { const testingUrl = 'localhost:8085'; setHost(defaultBaseUrl_); - pubsub.options.apiEndpoint = testingUrl; - pubsub.determineBaseUrl_(); + pubsub!.options!.apiEndpoint = testingUrl; + pubsub.determineBaseUrl_?.(); - assert.strictEqual(pubsub.options.servicePath, 'localhost'); + assert.strictEqual(pubsub.options?.servicePath, 'localhost'); assert.strictEqual(pubsub.options.port, 8085); assert.strictEqual(pubsub.options.sslCreds, fakeCreds); assert.strictEqual(pubsub.isEmulator, true); @@ -777,34 +781,34 @@ describe('PubSub', () => { it('should remove slashes from the baseUrl', () => { setHost('localhost:8080/'); - pubsub.determineBaseUrl_(); - assert.strictEqual(pubsub.options.servicePath, 'localhost'); + pubsub.determineBaseUrl_?.(); + assert.strictEqual(pubsub.options?.servicePath, 'localhost'); assert.strictEqual(pubsub.options.port, 8080); setHost('localhost:8081//'); - pubsub.determineBaseUrl_(); + pubsub.determineBaseUrl_?.(); assert.strictEqual(pubsub.options.servicePath, 'localhost'); assert.strictEqual(pubsub.options.port, 8081); }); it('should set the port to undefined if not set', () => { setHost('localhost'); - pubsub.determineBaseUrl_(); - assert.strictEqual(pubsub.options.servicePath, 'localhost'); + pubsub.determineBaseUrl_?.(); + assert.strictEqual(pubsub.options?.servicePath, 'localhost'); assert.strictEqual(pubsub.options.port, undefined); }); it('should set the port to 80 for http with no port specified', () => { setHost('http://localhost/'); - pubsub.determineBaseUrl_(); - assert.strictEqual(pubsub.options.servicePath, 'localhost'); - assert.strictEqual(pubsub.options.port, 80); + pubsub.determineBaseUrl_?.(); + assert.strictEqual(pubsub.options?.servicePath, 'localhost'); + assert.strictEqual(pubsub.options?.port, 80); }); it('should set the port to 443 for https with no port specified', () => { setHost('https://localhost/'); - pubsub.determineBaseUrl_(); - assert.strictEqual(pubsub.options.servicePath, 'localhost'); + pubsub.determineBaseUrl_?.(); + assert.strictEqual(pubsub.options?.servicePath, 'localhost'); assert.strictEqual(pubsub.options.port, 443); }); @@ -817,9 +821,9 @@ describe('PubSub', () => { }; setHost('localhost'); - pubsub.options.grpc = fakeGrpc as unknown as typeof gax.grpc; - pubsub.determineBaseUrl_(); - assert.strictEqual(pubsub.options.sslCreds, fakeCredentials); + pubsub!.options!.grpc = fakeGrpc as unknown as typeof gax.grpc; + pubsub.determineBaseUrl_?.(); + assert.strictEqual(pubsub.options?.sslCreds, fakeCredentials); }); // This tests both the EMULATOR environment variable and detecting @@ -836,8 +840,8 @@ describe('PubSub', () => { }); it('should use the PUBSUB_EMULATOR_HOST env var', () => { - pubsub.determineBaseUrl_(); - assert.strictEqual(pubsub.options.servicePath, 'localhost'); + pubsub.determineBaseUrl_?.(); + assert.strictEqual(pubsub.options?.servicePath, 'localhost'); assert.strictEqual(pubsub.options.port, 9090); assert.strictEqual(pubsub.isEmulator, true); }); @@ -858,9 +862,9 @@ describe('PubSub', () => { }); it('should use the CLOUDSDK_API_ENDPOINT_OVERRIDES_PUBSUB env var', () => { - pubsub.determineBaseUrl_(); - assert.strictEqual(pubsub.options.servicePath, server); - assert.strictEqual(pubsub.options.port, 443); + pubsub.determineBaseUrl_?.(); + assert.strictEqual(pubsub.options?.servicePath, server); + assert.strictEqual(pubsub.options?.port, 443); assert.strictEqual(pubsub.isEmulator, false); assert.strictEqual(pubsub.options.sslCreds, undefined); }); @@ -878,11 +882,11 @@ describe('PubSub', () => { }); it('should accept a query and a callback', done => { - pubsub.getSnapshots({}, done); + pubsub.getSnapshots?.({}, done); }); it('should accept just a callback', done => { - pubsub.getSnapshots(done); + pubsub.getSnapshots?.(done); }); it('should build the right request', done => { @@ -917,7 +921,7 @@ describe('PubSub', () => { done(); }; - pubsub.getSnapshots(options, assert.ifError); + pubsub.getSnapshots?.(options, assert.ifError); }); it('should return Snapshot instances with metadata', done => { @@ -929,7 +933,7 @@ describe('PubSub', () => { }); // eslint-disable-next-line @typescript-eslint/no-explicit-any - pubsub.getSnapshots((err: any, snapshots: any) => { + pubsub.getSnapshots?.((err: any, snapshots: any) => { assert.ifError(err); assert.strictEqual(snapshots![0], snapshot); assert.strictEqual( @@ -951,7 +955,7 @@ describe('PubSub', () => { callback(err_, snapshots_, nextQuery_, apiResponse_); }; - pubsub.getSnapshots((err, snapshots, apiResponse) => { + pubsub.getSnapshots?.((err, snapshots, apiResponse) => { assert.strictEqual(err, err_); assert.deepStrictEqual(snapshots, snapshots_); assert.strictEqual(apiResponse, nextQuery_); @@ -970,11 +974,11 @@ describe('PubSub', () => { }); it('should accept a query and a callback', done => { - pubsub.getSubscriptions({}, done); + pubsub.getSubscriptions?.({}, done); }); it('should accept just a callback', done => { - pubsub.getSubscriptions(done); + pubsub.getSubscriptions?.(done); }); it('should pass the correct arguments to the API', done => { @@ -1002,7 +1006,7 @@ describe('PubSub', () => { done(); }; - pubsub.getSubscriptions(options, assert.ifError); + pubsub.getSubscriptions?.(options, assert.ifError); }); it('should pass options to API request', done => { @@ -1017,11 +1021,11 @@ describe('PubSub', () => { done(); }; - pubsub.getSubscriptions(opts, assert.ifError); + pubsub.getSubscriptions?.(opts, assert.ifError); }); it('should return Subscription instances', done => { - pubsub.getSubscriptions( + pubsub.getSubscriptions?.( ( err: gax.grpc.ServiceError | null, subscriptions?: subby.Subscription[] | null @@ -1043,7 +1047,7 @@ describe('PubSub', () => { callback(err_, subs_, nextQuery_, apiResponse_); }; - pubsub.getSubscriptions( + pubsub.getSubscriptions?.( ( err: gax.grpc.ServiceError | null, subs?: subby.Subscription[] | null, @@ -1072,7 +1076,7 @@ describe('PubSub', () => { done(); }; - pubsub.getSubscriptions(opts, assert.ifError); + pubsub.getSubscriptions?.(opts, assert.ifError); }); it('should create a topic instance from a name', done => { @@ -1092,7 +1096,7 @@ describe('PubSub', () => { return fakeTopic as Topic; }; - pubsub.getSubscriptions(opts, assert.ifError); + pubsub.getSubscriptions?.(opts, assert.ifError); }); }); }); @@ -1108,11 +1112,11 @@ describe('PubSub', () => { }); it('should accept a query and a callback', done => { - pubsub.getTopics({}, done); + pubsub.getTopics?.({}, done); }); it('should accept just a callback', done => { - pubsub.getTopics(done); + pubsub.getTopics?.(done); }); it('should build the right request', done => { @@ -1147,7 +1151,7 @@ describe('PubSub', () => { done(); }; - pubsub.getTopics(options, assert.ifError); + pubsub.getTopics?.(options, assert.ifError); }); it('should return Topic instances with metadata', done => { @@ -1159,7 +1163,7 @@ describe('PubSub', () => { }; // eslint-disable-next-line @typescript-eslint/no-explicit-any - pubsub.getTopics((err: any, topics: any) => { + pubsub.getTopics?.((err: any, topics: any) => { assert.ifError(err); assert.strictEqual(topics![0], topic); // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -1178,7 +1182,7 @@ describe('PubSub', () => { callback(err_, topics_, nextQuery_, apiResponse_); }; - pubsub.getTopics((err, topics, apiResponse) => { + pubsub.getTopics?.((err, topics, apiResponse) => { assert.strictEqual(err, err_); assert.deepStrictEqual(topics, topics_); assert.strictEqual(apiResponse, nextQuery_); @@ -1210,10 +1214,10 @@ describe('PubSub', () => { }); it('should throw if the PubSub is already closed', done => { - pubsub.close((err: Error | null) => { + pubsub.close?.((err: Error | null) => { assert.strictEqual(err, null); - pubsub.request(CONFIG, (errInner: Error | null) => { + pubsub.request?.(CONFIG, (errInner: Error | null) => { assert.notStrictEqual(errInner, null); assert.strictEqual( errInner!.message.indexOf('closed PubSub object') >= 0, @@ -1230,7 +1234,7 @@ describe('PubSub', () => { done(); }; - pubsub.request(CONFIG, assert.ifError); + pubsub.request?.(CONFIG, assert.ifError); }); it('should return error from getClient_', done => { @@ -1239,7 +1243,7 @@ describe('PubSub', () => { callback(expectedError); }; - pubsub.request(CONFIG, (err: gax.grpc.ServiceError | null) => { + pubsub.request?.(CONFIG, (err: gax.grpc.ServiceError | null) => { assert.strictEqual(expectedError, err); done(); }); @@ -1260,7 +1264,7 @@ describe('PubSub', () => { pubsub.getClient_ = (config, callback: Function) => { callback(null, fakeClient); }; - pubsub.request(CONFIG, assert.ifError); + pubsub.request?.(CONFIG, assert.ifError); }); it('should replace the project id token on reqOpts', done => { @@ -1270,12 +1274,11 @@ describe('PubSub', () => { assert.strictEqual(projectId, PROJECT_ID); done(); }; - pubsub.request(CONFIG, assert.ifError); + pubsub.request?.(CONFIG, assert.ifError); }); }); describe('getClientAsync_', () => { - // eslint-disable-next-line @typescript-eslint/class-name-casing const FAKE_CLIENT_INSTANCE = class { close() {} }; @@ -1293,11 +1296,11 @@ describe('PubSub', () => { describe('closeAllClients_', () => { it('should close out any open client', async () => { // Create a client that we'll close. - const client = await pubsub.getClientAsync_(CONFIG); + const client = await pubsub!.getClientAsync_!(CONFIG); // Stub out its close method, and verify it gets called. const stub = sandbox.stub(client, 'close').resolves(); - await pubsub.closeAllClients_(); + await pubsub.closeAllClients_?.(); assert.strictEqual(stub.called, true); }); @@ -1310,29 +1313,29 @@ describe('PubSub', () => { }); it('should get and cache the project ID', async () => { - sandbox.stub(pubsub.auth, 'getProjectId').resolves(PROJECT_ID); + sandbox.stub(pubsub!.auth!, 'getProjectId').resolves(PROJECT_ID); - await pubsub.getClientAsync_(CONFIG); + await pubsub.getClientAsync_?.(CONFIG); assert.strictEqual(pubsub.projectId, PROJECT_ID); - assert.strictEqual(pubsub.options.projectId, PROJECT_ID); + assert.strictEqual(pubsub.options?.projectId, PROJECT_ID); }); it('should get the project ID if placeholder', async () => { pubsub.projectId = '{{projectId}}'; - sandbox.stub(pubsub.auth, 'getProjectId').resolves(PROJECT_ID); + sandbox.stub(pubsub!.auth!, 'getProjectId').resolves(PROJECT_ID); - await pubsub.getClientAsync_(CONFIG); + await pubsub.getClientAsync_?.(CONFIG); assert.strictEqual(pubsub.projectId, PROJECT_ID); }); it('should return auth errors that occur', async () => { const error = new Error('err'); - sandbox.stub(pubsub.auth, 'getProjectId').rejects(error); + sandbox.stub(pubsub!.auth!, 'getProjectId').rejects(error); try { - await pubsub.getClientAsync_(CONFIG); + await pubsub.getClientAsync_?.(CONFIG); throw new Error('getClientAsync_ should have thrown an error'); } catch (e) { assert.strictEqual(e, error); @@ -1343,9 +1346,9 @@ describe('PubSub', () => { pubsub.isEmulator = true; const error = new Error('err'); - sandbox.stub(pubsub.auth, 'getProjectId').rejects(error); + sandbox.stub(pubsub!.auth!, 'getProjectId').rejects(error); - await pubsub.getClientAsync_(CONFIG); + await pubsub.getClientAsync_?.(CONFIG); assert.strictEqual(pubsub.projectId, ''); }); @@ -1353,14 +1356,14 @@ describe('PubSub', () => { pubsub.projectId = PROJECT_ID; const error = new Error('getProjectId should not be called.'); - sandbox.stub(pubsub.auth, 'getProjectId').rejects(error); + sandbox.stub(pubsub!.auth!, 'getProjectId').rejects(error); - await pubsub.getClientAsync_(CONFIG); + await pubsub.getClientAsync_?.(CONFIG); }); }); it('should cache the client', async () => { - delete pubsub.api.fakeClient; + delete pubsub.api?.fakeClient; let numTimesFakeClientInstantiated = 0; @@ -1370,10 +1373,10 @@ describe('PubSub', () => { return FAKE_CLIENT_INSTANCE; }; - await pubsub.getClientAsync_(CONFIG); - assert.strictEqual(pubsub.api.FakeClient, FAKE_CLIENT_INSTANCE); + await pubsub.getClientAsync_?.(CONFIG); + assert.strictEqual(pubsub.api?.FakeClient, FAKE_CLIENT_INSTANCE); - await pubsub.getClientAsync_(CONFIG); + await pubsub.getClientAsync_?.(CONFIG); assert.strictEqual(numTimesFakeClientInstantiated, 1); }); @@ -1386,7 +1389,7 @@ describe('PubSub', () => { return FAKE_CLIENT_INSTANCE; }; - const client = await pubsub.getClientAsync_(CONFIG); + const client = await pubsub.getClientAsync_?.(CONFIG); assert.strictEqual(client, FAKE_CLIENT_INSTANCE); }); }); @@ -1403,7 +1406,7 @@ describe('PubSub', () => { .withArgs(CONFIG) .resolves(FAKE_CLIENT_INSTANCE); - pubsub.getClient_(CONFIG, (err, client) => { + pubsub.getClient_?.(CONFIG, (err, client) => { assert.ifError(err); assert.strictEqual(client, FAKE_CLIENT_INSTANCE); done(); @@ -1414,7 +1417,7 @@ describe('PubSub', () => { const error = new Error('err'); sandbox.stub(pubsub, 'getClientAsync_').rejects(error); - pubsub.getClient_(CONFIG, err => { + pubsub.getClient_?.(CONFIG, err => { assert.strictEqual(err, error); done(); }); @@ -1450,7 +1453,7 @@ describe('PubSub', () => { done(); }; - pubsub.request(CONFIG, assert.ifError); + pubsub.request?.(CONFIG, assert.ifError); }); it('should return error from getting the client', done => { @@ -1460,7 +1463,7 @@ describe('PubSub', () => { callback(error); }; - pubsub.request(CONFIG, (err: gax.ServiceError | null) => { + pubsub.request?.(CONFIG, (err: gax.ServiceError | null) => { assert.strictEqual(err, error); done(); }); @@ -1474,7 +1477,7 @@ describe('PubSub', () => { done(); }; - pubsub.request(CONFIG, assert.ifError); + pubsub.request?.(CONFIG, assert.ifError); }); it('should call the client method correctly', done => { @@ -1504,7 +1507,7 @@ describe('PubSub', () => { callback(null, fakeClient); }; - pubsub.request(CONFIG, assert.ifError); + pubsub.request?.(CONFIG, assert.ifError); }); }); @@ -1518,7 +1521,7 @@ describe('PubSub', () => { it('should return a Snapshot object', () => { const SNAPSHOT_NAME = 'new-snapshot'; - const snapshot = pubsub.snapshot(SNAPSHOT_NAME); + const snapshot = pubsub.snapshot?.(SNAPSHOT_NAME); const args = (snapshot as {} as FakeSnapshot).calledWith_; assert(snapshot instanceof FakeSnapshot); @@ -1534,7 +1537,7 @@ describe('PubSub', () => { it('should return a Subscription object', () => { // tslint:disable-next-line only-arrow-functions subscriptionOverride = function () {}; - const subscription = pubsub.subscription(SUB_NAME, {}); + const subscription = pubsub.subscription?.(SUB_NAME, {}); assert(subscription instanceof subscriptionOverride); }); @@ -1547,7 +1550,7 @@ describe('PubSub', () => { assert.strictEqual(name, SUB_NAME); done(); }; - pubsub.subscription(SUB_NAME); + pubsub.subscription?.(SUB_NAME); }); it('should honor settings', done => { @@ -1560,7 +1563,7 @@ describe('PubSub', () => { assert.strictEqual(options, CONFIG); done(); }; - pubsub.subscription(SUB_NAME, CONFIG); + pubsub.subscription?.(SUB_NAME, CONFIG); }); it('should throw if a name is not provided', () => { @@ -1580,13 +1583,13 @@ describe('PubSub', () => { }); it('should return a Topic object', () => { - assert(pubsub.topic('new-topic') instanceof FakeTopic); + assert(pubsub.topic?.('new-topic') instanceof FakeTopic); }); it('should pass the correct args', () => { const fakeName = 'with-options'; const fakeOptions = {}; - const topic = pubsub.topic(fakeName, fakeOptions); + const topic = pubsub.topic?.(fakeName, fakeOptions); const [ps, name, options] = (topic as {} as FakeTopic).calledWith_; @@ -1605,9 +1608,9 @@ describe('PubSub', () => { it('should close the schema client when it has been opened', async () => { // Force it to create a client. - const client = await pubsub.getSchemaClient_(); - sandbox.stub(client, 'close').resolves(); - await pubsub.close(); + const client = await pubsub.getSchemaClient_?.(); + sandbox.stub(client!, 'close').resolves(); + await pubsub.close?.(); }); // I feel like this ought to be a test, but something in getSchemaClient_() @@ -1623,10 +1626,10 @@ describe('PubSub', () => { const schemaId = 'id'; const type = SchemaTypes.Avro; const definition = 'def'; - const name = Schema.formatName_(pubsub.projectId, schemaId); + const name = Schema.formatName_(pubsub.projectId!, schemaId); // Grab the schema client it'll be using so we can stub it. - const client = await pubsub.getSchemaClient_(); + const client = await pubsub.getSchemaClient_!(); const def = defer(); sandbox.stub(client, 'createSchema').callsFake(req => { assert.strictEqual(req.parent, pubsub.name); @@ -1637,7 +1640,7 @@ describe('PubSub', () => { def.resolve(); }); const result = await Promise.all([ - pubsub.createSchema(schemaId, type, definition), + pubsub.createSchema!(schemaId, type, definition), def, ]); assert.strictEqual(result[0].id, schemaId); @@ -1645,7 +1648,7 @@ describe('PubSub', () => { it('calls down to listSchemas correctly', async () => { // Grab the schema client it'll be using so we can stub it. - const client = await pubsub.getSchemaClient_(); + const client = await pubsub.getSchemaClient_!(); sandbox.stub(client, 'listSchemasAsync').callsFake((req, gaxOpts) => { assert.strictEqual(req!.parent, pubsub.name); @@ -1663,7 +1666,7 @@ describe('PubSub', () => { }); const ids = [] as string[]; - for await (const s of pubsub.listSchemas(SchemaViews.Basic, {})) { + for await (const s of pubsub.listSchemas!(SchemaViews.Basic, {})) { ids.push(s.name!); } @@ -1673,30 +1676,30 @@ describe('PubSub', () => { it('defaults to BASIC for listSchemas', async () => { // Grab the schema client it'll be using so we can stub it. - const client = await pubsub.getSchemaClient_(); + const client = await pubsub.getSchemaClient_?.(); - sandbox.stub(client, 'listSchemasAsync').callsFake(req => { + sandbox.stub(client!, 'listSchemasAsync').callsFake(req => { assert.strictEqual(req!.view, 'BASIC'); // eslint-disable-next-line @typescript-eslint/no-explicit-any return toAsync([]) as any; }); // eslint-disable-next-line @typescript-eslint/no-unused-vars - for await (const s of pubsub.listSchemas()) { + for await (const s of pubsub.listSchemas!()) { break; } }); it('returns a proper Schema object from schema()', async () => { - const schema = pubsub.schema('foo'); - assert.strictEqual(schema.id, 'foo'); + const schema = pubsub.schema?.('foo'); + assert.strictEqual(schema!.id, 'foo'); - const name = await schema.getName(); - assert.strictEqual(name, Schema.formatName_(pubsub.projectId, 'foo')); + const name = await schema!.getName(); + assert.strictEqual(name, Schema.formatName_(pubsub!.projectId!, 'foo')); }); it('calls validateSchema() on the client when validateSchema() is called', async () => { - const client = await pubsub.getSchemaClient_(); + const client = await pubsub.getSchemaClient_!(); const ischema: ISchema = { name: 'test', type: SchemaTypes.Avro, @@ -1713,7 +1716,7 @@ describe('PubSub', () => { called = true; }); - await pubsub.validateSchema(ischema, {}); + await pubsub.validateSchema!(ischema, {}); assert.ok(called); }); }); diff --git a/test/subscription.ts b/test/subscription.ts index a5699b8a1..1fdaa36f9 100644 --- a/test/subscription.ts +++ b/test/subscription.ts @@ -95,7 +95,7 @@ class FakeSubscriber extends EventEmitter { describe('Subscription', () => { // tslint:disable-next-line variable-name let Subscription: typeof subby.Subscription; - let subscription: subby.Subscription; + let subscription: Partial; const PROJECT_ID = 'test-project'; const SUB_NAME = 'test-subscription'; @@ -183,7 +183,7 @@ describe('Subscription', () => { it('should open the subscriber when a listener is attached', () => { const stub = sandbox.stub(subscriber, 'open'); - subscription.on('message', () => {}); + subscription.on?.('message', () => {}); assert.strictEqual(stub.callCount, 1); }); @@ -191,8 +191,8 @@ describe('Subscription', () => { const stub = sandbox.stub(subscriber, 'close'); const cb = () => {}; - subscription.on('message', cb); - subscription.removeListener('message', cb); + subscription.on?.('message', cb); + subscription.removeListener?.('message', cb); assert.strictEqual(stub.callCount, 1); }); @@ -200,7 +200,7 @@ describe('Subscription', () => { it('should emit messages', done => { const message = {}; - subscription.on('message', (msg: Message) => { + subscription.on?.('message', (msg: Message) => { assert.strictEqual(msg, message); done(); }); @@ -211,7 +211,7 @@ describe('Subscription', () => { it('should emit errors', done => { const error = new Error('err'); - subscription.on('error', (err: Error) => { + subscription.on?.('error', (err: Error) => { assert.strictEqual(err, error); done(); }); @@ -220,7 +220,7 @@ describe('Subscription', () => { }); it('should emit close events', done => { - subscription.on('close', done); + subscription.on?.('close', done); subscriber.emit('close'); }); }); @@ -330,7 +330,7 @@ describe('Subscription', () => { describe('close', () => { it('should call the success callback', done => { sandbox.stub(subscriber, 'close').resolves(); - subscription.close(done); + subscription.close?.(done); }); it('should pass back any errors that occurs', done => { @@ -338,7 +338,7 @@ describe('Subscription', () => { sandbox.stub(subscriber, 'close').rejects(fakeErr); - subscription.close(err => { + subscription!.close!((err: Error | undefined) => { assert.strictEqual(err, fakeErr); done(); }); @@ -356,14 +356,14 @@ describe('Subscription', () => { const expectedError = /Subscriptions can only be created when accessed through Topics/; delete subscription.topic; - await assert.rejects(subscription.create(), expectedError); + await assert.rejects(subscription.create!(), expectedError); }); it('should pass the correct params', () => { const fakeOptions = {}; const stub = sandbox.stub(PUBSUB, 'createSubscription'); - subscription.create(fakeOptions, assert.ifError); + subscription.create?.(fakeOptions, assert.ifError); const [topic, name, options] = stub.lastCall.args; assert.strictEqual(topic, TOPIC_NAME); @@ -374,7 +374,7 @@ describe('Subscription', () => { it('should optionally accept options', () => { const stub = sandbox.stub(PUBSUB, 'createSubscription'); - subscription.create(assert.ifError); + subscription.create?.(assert.ifError); const options = stub.lastCall.args[2]; assert.deepStrictEqual(options, {}); @@ -385,7 +385,7 @@ describe('Subscription', () => { const fakeResponse = {}; const stub = sandbox.stub(PUBSUB, 'createSubscription'); - subscription.create((err, sub, resp) => { + subscription.create?.((err, sub, resp) => { assert.strictEqual(err, fakeErr); assert.strictEqual(sub, null); assert.strictEqual(resp, fakeResponse); @@ -401,7 +401,7 @@ describe('Subscription', () => { const fakeSub = new Subscription(PUBSUB, SUB_FULL_NAME); const fakeResponse = {}; - subscription.create(err => { + subscription.create?.(err => { assert.ifError(err); assert.strictEqual(subscription.metadata, fakeResponse); done(); @@ -416,7 +416,7 @@ describe('Subscription', () => { const fakeResponse = {}; const stub = sandbox.stub(PUBSUB, 'createSubscription'); - subscription.create((err, sub, resp) => { + subscription.create?.((err, sub, resp) => { assert.ifError(err); assert.strictEqual(sub, subscription); assert.strictEqual(resp, fakeResponse); @@ -457,7 +457,7 @@ describe('Subscription', () => { done(); }; - subscription.createSnapshot(SNAPSHOT_NAME, assert.ifError); + subscription.createSnapshot?.(SNAPSHOT_NAME, assert.ifError); }); it('should optionally accept gax options', done => { @@ -468,7 +468,7 @@ describe('Subscription', () => { done(); }; - subscription.createSnapshot(SNAPSHOT_NAME, gaxOpts, assert.ifError); + subscription.createSnapshot?.(SNAPSHOT_NAME, gaxOpts, assert.ifError); }); it('should pass back any errors to the callback', done => { @@ -479,7 +479,7 @@ describe('Subscription', () => { callback(error, apiResponse); }; - subscription.createSnapshot(SNAPSHOT_NAME, (err, snapshot, resp) => { + subscription.createSnapshot?.(SNAPSHOT_NAME, (err, snapshot, resp) => { assert.strictEqual(err, error); assert.strictEqual(snapshot, null); assert.strictEqual(resp, apiResponse); @@ -499,7 +499,7 @@ describe('Subscription', () => { callback(null, apiResponse); }; - subscription.createSnapshot(SNAPSHOT_NAME, (err, snapshot, resp) => { + subscription.createSnapshot?.(SNAPSHOT_NAME, (err, snapshot, resp) => { assert.ifError(err); assert.strictEqual(snapshot, fakeSnapshot); assert.strictEqual(snapshot!.metadata, apiResponse); @@ -519,7 +519,7 @@ describe('Subscription', () => { }); it('should return the debug events to the callback', done => { - subscription.on('debug', err => { + subscription.on?.('debug', err => { assert.strictEqual(err, error); done(); }); @@ -544,7 +544,7 @@ describe('Subscription', () => { done(); }; - subscription.delete(assert.ifError); + subscription.delete?.(assert.ifError); }); it('should optionally accept gax options', done => { @@ -555,7 +555,7 @@ describe('Subscription', () => { done(); }; - subscription.delete(gaxOpts, assert.ifError); + subscription.delete?.(gaxOpts, assert.ifError); }); describe('success', () => { @@ -568,7 +568,7 @@ describe('Subscription', () => { }); it('should return the api response', done => { - subscription.delete((err, resp) => { + subscription.delete?.((err, resp) => { assert.ifError(err); assert.strictEqual(resp, apiResponse); done(); @@ -578,9 +578,9 @@ describe('Subscription', () => { it('should close the subscriber if open', done => { const stub = sandbox.stub(subscriber, 'close'); - subscription.open(); + subscription.open?.(); - subscription.delete(err => { + subscription.delete?.(err => { assert.ifError(err); assert.strictEqual(stub.callCount, 1); done(); @@ -598,7 +598,7 @@ describe('Subscription', () => { }); it('should return the error to the callback', done => { - subscription.delete(err => { + subscription.delete?.(err => { assert.strictEqual(err, error); done(); }); @@ -610,7 +610,7 @@ describe('Subscription', () => { done(new Error('Should not be called.')); }; - subscription.delete(() => { + subscription.delete?.(() => { done(); }); }); @@ -620,7 +620,7 @@ describe('Subscription', () => { done(new Error('Should not be called.')); }; - subscription.delete(() => { + subscription.delete?.(() => { done(); }); }); @@ -631,7 +631,7 @@ describe('Subscription', () => { it('should return true if it finds metadata', done => { sandbox.stub(subscription, 'getMetadata').yields(null, {}); - subscription.exists((err, exists) => { + subscription.exists?.((err, exists) => { assert.ifError(err); assert(exists); done(); @@ -642,7 +642,7 @@ describe('Subscription', () => { const error = {code: 5} as ServiceError; sandbox.stub(subscription, 'getMetadata').yields(error); - subscription.exists((err, exists) => { + subscription.exists?.((err, exists) => { assert.ifError(err); assert.strictEqual(exists, false); done(); @@ -653,7 +653,7 @@ describe('Subscription', () => { const error = {code: 4} as ServiceError; sandbox.stub(subscription, 'getMetadata').yields(error); - subscription.exists((err, exists) => { + subscription.exists?.((err, exists) => { assert.strictEqual(err, error); assert.strictEqual(exists, undefined); done(); @@ -674,7 +674,7 @@ describe('Subscription', () => { done(); }); - subscription.get(options, assert.ifError); + subscription.get?.(options, assert.ifError); }); describe('success', () => { @@ -687,7 +687,7 @@ describe('Subscription', () => { callback(null, fakeMetadata); }); - subscription.get((err, sub, resp) => { + subscription.get?.((err, sub, resp) => { assert.ifError(err); assert.strictEqual(sub, subscription); assert.strictEqual(resp, fakeMetadata); @@ -704,7 +704,7 @@ describe('Subscription', () => { callback(null); // the done fn }); - subscription.get(options, done); + subscription.get?.(options, done); }); }); @@ -716,7 +716,7 @@ describe('Subscription', () => { .stub(subscription, 'getMetadata') .callsArgWith(1, error, apiResponse); - subscription.get((err, sub, resp) => { + subscription.get?.((err, sub, resp) => { assert.strictEqual(err, error); assert.strictEqual(sub, null); assert.strictEqual(resp, apiResponse); @@ -731,7 +731,7 @@ describe('Subscription', () => { .stub(subscription, 'getMetadata') .callsArgWith(1, error, apiResponse); - subscription.get((err, sub, resp) => { + subscription.get?.((err, sub, resp) => { assert.strictEqual(err, error); assert.strictEqual(sub, null); assert.strictEqual(resp, apiResponse); @@ -748,7 +748,7 @@ describe('Subscription', () => { delete subscription.create; - subscription.get((err, sub, resp) => { + subscription.get?.((err, sub, resp) => { assert.strictEqual(err, error); assert.strictEqual(sub, null); assert.strictEqual(resp, apiResponse); @@ -773,7 +773,7 @@ describe('Subscription', () => { }); subscription.topic = 'hi-ho-silver'; - subscription.get(fakeOptions, assert.ifError); + subscription.get?.(fakeOptions, assert.ifError); }); }); }); @@ -789,7 +789,7 @@ describe('Subscription', () => { done(); }; - subscription.getMetadata(assert.ifError); + subscription.getMetadata?.(assert.ifError); }); it('should optionally accept gax options', done => { @@ -800,7 +800,7 @@ describe('Subscription', () => { done(); }; - subscription.getMetadata(gaxOpts, assert.ifError); + subscription.getMetadata?.(gaxOpts, assert.ifError); }); it('should pass back any errors that occur', done => { @@ -811,7 +811,7 @@ describe('Subscription', () => { callback(error, apiResponse); }; - subscription.getMetadata((err, metadata) => { + subscription.getMetadata?.((err, metadata) => { assert.strictEqual(err, error); assert.strictEqual(metadata, apiResponse); done(); @@ -825,7 +825,7 @@ describe('Subscription', () => { callback(null, apiResponse); }; - subscription.getMetadata((err, metadata) => { + subscription.getMetadata?.((err, metadata) => { assert.ifError(err); assert.strictEqual(metadata, apiResponse); assert.strictEqual(subscription.metadata, apiResponse); @@ -848,7 +848,7 @@ describe('Subscription', () => { done(); }; - subscription.modifyPushConfig(fakeConfig, assert.ifError); + subscription.modifyPushConfig?.(fakeConfig, assert.ifError); }); it('should optionally accept gaxOpts', done => { @@ -859,7 +859,7 @@ describe('Subscription', () => { done(); }; - subscription.modifyPushConfig(fakeConfig, gaxOpts, assert.ifError); + subscription.modifyPushConfig?.(fakeConfig, gaxOpts, assert.ifError); }); }); @@ -867,7 +867,7 @@ describe('Subscription', () => { it('should open the subscriber', () => { const stub = sandbox.stub(subscriber, 'open'); - subscription.open(); + subscription.open?.(); assert.strictEqual(stub.callCount, 1); }); @@ -875,8 +875,8 @@ describe('Subscription', () => { it('should noop if already open', () => { const spy = sandbox.spy(subscriber, 'open'); - subscription.open(); - subscription.open(); + subscription.open?.(); + subscription.open?.(); assert.strictEqual(spy.callCount, 1); }); @@ -916,7 +916,7 @@ describe('Subscription', () => { done(); }; - subscription.seek(FAKE_SNAPSHOT_NAME, assert.ifError); + subscription.seek?.(FAKE_SNAPSHOT_NAME, assert.ifError); }); it('should optionally accept a Date object', done => { @@ -933,7 +933,7 @@ describe('Subscription', () => { done(); }; - subscription.seek(date, assert.ifError); + subscription.seek?.(date, assert.ifError); }); it('should optionally accept gax options', done => { @@ -944,7 +944,7 @@ describe('Subscription', () => { done(); }; - subscription.seek(FAKE_SNAPSHOT_NAME, gaxOpts, assert.ifError); + subscription.seek?.(FAKE_SNAPSHOT_NAME, gaxOpts, assert.ifError); }); }); @@ -995,7 +995,7 @@ describe('Subscription', () => { done(); }; - subscription.setMetadata(METADATA, done); + subscription.setMetadata?.(METADATA, done); }); it('should optionally accept gax options', done => { @@ -1005,7 +1005,7 @@ describe('Subscription', () => { assert.strictEqual(config.gaxOpts, gaxOpts); done(); }; - subscription.setMetadata(METADATA, gaxOpts, done); + subscription.setMetadata?.(METADATA, gaxOpts, done); }); }); @@ -1013,7 +1013,7 @@ describe('Subscription', () => { it('should pass the options to the subscriber', () => { const options = {}; const stub = sandbox.stub(subscriber, 'setOptions').withArgs(options); - subscription.setOptions(options); + subscription.setOptions?.(options); assert.strictEqual(stub.callCount, 1); }); }); @@ -1029,7 +1029,7 @@ describe('Subscription', () => { done(); }; - subscription.snapshot(SNAPSHOT_NAME); + subscription.snapshot?.(SNAPSHOT_NAME); }); }); }); diff --git a/test/topic.ts b/test/topic.ts index f5733a0d4..bbd0aa2df 100644 --- a/test/topic.ts +++ b/test/topic.ts @@ -488,7 +488,15 @@ describe('Topic', () => { describe('getSubscriptions', () => { it('should make the correct request', done => { - const options = { + interface testOptions { + a: string; + b: string; + gaxOpts?: { + e: string; + }; + autoPaginate?: boolean; + } + const options: testOptions = { a: 'a', b: 'b', gaxOpts: {