From f3520b933cc06a6e9245a51c634a8989f6a1b3d9 Mon Sep 17 00:00:00 2001 From: chradek <51000525+chradek@users.noreply.github.com> Date: Fri, 2 Apr 2021 10:22:46 -0700 Subject: [PATCH] [eventhubs-checkpointstore-blob] fixes eslint errors (#14677) Resolves #10777 by addressing the last outstanding item. With this change, `@azure/eventhubs-checkpointstore-blob` now no longer has eslint errors. --- .../package.json | 2 +- .../eventhubs-checkpointstore-blob/src/log.ts | 8 +- .../src/util/error.ts | 2 +- .../test/blob-checkpointstore.spec.ts | 120 +++++++++++++----- .../test/utils/testUtils.ts | 5 +- 5 files changed, 98 insertions(+), 39 deletions(-) diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/package.json b/sdk/eventhub/eventhubs-checkpointstore-blob/package.json index 385533d2daaf..41708d4fd303 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/package.json +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/package.json @@ -48,7 +48,7 @@ "integration-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"dist-esm/test/*.spec.js\"", "integration-test": "npm run integration-test:node && npm run integration-test:browser", "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix", - "lint": "eslint package.json api-extractor.json src test --ext .ts -f html -o checkpointstore-lintReport.html || exit 0", + "lint": "eslint package.json api-extractor.json src test --ext .ts", "pack": "npm pack 2>&1", "prebuild": "npm run clean", "test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser", diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/src/log.ts b/sdk/eventhub/eventhubs-checkpointstore-blob/src/log.ts index e5463105c4c6..be5903409e9d 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/src/log.ts +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/src/log.ts @@ -12,10 +12,10 @@ export const logger = createClientLogger("eventhubs-checkpointstore-blob"); /** * Logs the error's stack trace to "verbose" if a stack trace is available. * @param error - Error containing a stack trace. - * @hidden + * @internal */ -export function logErrorStackTrace(error: any): void { - if (error && error.stack) { - logger.verbose(error.stack); +export function logErrorStackTrace(error: unknown): void { + if (error && typeof error === "object" && "stack" in error) { + logger.verbose((error as any).stack); } } diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/src/util/error.ts b/sdk/eventhub/eventhubs-checkpointstore-blob/src/util/error.ts index d72b2b8f49ef..741a86602900 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/src/util/error.ts +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/src/util/error.ts @@ -13,7 +13,7 @@ import { logger, logErrorStackTrace } from "../log"; export function throwTypeErrorIfParameterMissing( methodName: string, parameterName: string, - parameterValue: any + parameterValue: unknown ): void { if (parameterValue === undefined || parameterValue === null) { const error = new TypeError( diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/test/blob-checkpointstore.spec.ts b/sdk/eventhub/eventhubs-checkpointstore-blob/test/blob-checkpointstore.spec.ts index cbaaeffb68b4..8edc35d19874 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/test/blob-checkpointstore.spec.ts +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/test/blob-checkpointstore.spec.ts @@ -223,7 +223,7 @@ describe("Blob Checkpoint Store", function(): void { ]); fail("Should have thrown an error - this isn't a normal claim collision issue"); } catch (err) { - (err instanceof RestError).should.be.ok; + should.equal(err instanceof RestError, true, "Error is unexpected type."); // 404 because the container is missing (since we deleted it up above) (err as RestError).statusCode!.should.equal(404); } @@ -257,14 +257,30 @@ describe("Blob Checkpoint Store", function(): void { "testConsumerGroup" ); - ownershipList.length.should.equal(1); - ownershipList[0].ownerId.should.equal("Id1"); - ownershipList[0].partitionId.should.equal("0"); - ownershipList[0].consumerGroup.should.equal("testConsumerGroup"); - ownershipList[0].fullyQualifiedNamespace.should.equal("testNamespace.servicebus.windows.net"); - ownershipList[0].eventHubName.should.equal("testEventHub"); - ownershipList[0].lastModifiedTimeInMs!.should.not.undefined; - ownershipList[0].etag!.should.not.undefined; + should.equal(ownershipList.length, 1, "Unexpected number of ownerships in list."); + should.equal(ownershipList[0].ownerId, "Id1", "The 1st ownership item has the wrong ownerId."); + should.equal( + ownershipList[0].consumerGroup, + "testConsumerGroup", + "The 1st ownership item has the wrong consumerGroup." + ); + should.equal( + ownershipList[0].fullyQualifiedNamespace, + "testNamespace.servicebus.windows.net", + "The 1st fullyQualifiedNamespace item has the wrong fullyQualifiedNamespace." + ); + should.equal( + ownershipList[0].eventHubName, + "testEventHub", + "The 1st ownership item has the wrong eventHubName." + ); + should.equal( + ownershipList[0].partitionId, + "0", + "The 1st ownership item has the wrong partitionId." + ); + should.exist(ownershipList[0].lastModifiedTimeInMs, "lastModifiedTimeInMs should exist."); + should.exist(ownershipList[0].etag, "etag should exist."); debug( `LastModifiedTime: ${ownershipList[0].lastModifiedTimeInMs!}, ETag: ${ownershipList[0].etag}` @@ -299,14 +315,31 @@ describe("Blob Checkpoint Store", function(): void { "testEventHub", "testConsumerGroup" ); - ownershipList.length.should.equal(1); - ownershipList[0].ownerId.should.equal("Id1"); - ownershipList[0].partitionId.should.equal("0"); - ownershipList[0].fullyQualifiedNamespace.should.equal("testNamespace.servicebus.windows.net"); - ownershipList[0].consumerGroup.should.equal("testConsumerGroup"); - ownershipList[0].eventHubName.should.equal("testEventHub"); - ownershipList[0].lastModifiedTimeInMs!.should.not.undefined; - ownershipList[0].etag!.should.not.undefined; + + should.equal(ownershipList.length, 1, "Unexpected number of ownerships in list."); + should.equal(ownershipList[0].ownerId, "Id1", "The 1st ownership item has the wrong ownerId."); + should.equal( + ownershipList[0].consumerGroup, + "testConsumerGroup", + "The 1st ownership item has the wrong consumerGroup." + ); + should.equal( + ownershipList[0].fullyQualifiedNamespace, + "testNamespace.servicebus.windows.net", + "The 1st fullyQualifiedNamespace item has the wrong fullyQualifiedNamespace." + ); + should.equal( + ownershipList[0].eventHubName, + "testEventHub", + "The 1st ownership item has the wrong eventHubName." + ); + should.equal( + ownershipList[0].partitionId, + "0", + "The 1st ownership item has the wrong partitionId." + ); + should.exist(ownershipList[0].lastModifiedTimeInMs, "lastModifiedTimeInMs should exist."); + should.exist(ownershipList[0].etag, "etag should exist."); debug( `LastModifiedTime: ${ownershipList[0].lastModifiedTimeInMs!}, ETag: ${ownershipList[0].etag}` ); @@ -345,23 +378,48 @@ describe("Blob Checkpoint Store", function(): void { "testEventHub", "testConsumerGroup" ); - ownershipList.length.should.equal(3); - ownershipList[0].partitionId.should.equal("0"); - ownershipList[0].ownerId.should.equal("Id1"); - ownershipList[0].consumerGroup.should.equal("testConsumerGroup"); - ownershipList[0].fullyQualifiedNamespace.should.equal("testNamespace.servicebus.windows.net"); - ownershipList[0].eventHubName.should.equal("testEventHub"); - ownershipList[0].lastModifiedTimeInMs!.should.not.undefined; - ownershipList[0].etag!.should.not.undefined; + should.equal(ownershipList.length, 3, "Unexpected number of ownerships in list."); + + should.equal(ownershipList[0].ownerId, "Id1", "The 1st ownership item has the wrong ownerId."); + should.equal( + ownershipList[0].consumerGroup, + "testConsumerGroup", + "The 1st ownership item has the wrong consumerGroup." + ); + should.equal( + ownershipList[0].fullyQualifiedNamespace, + "testNamespace.servicebus.windows.net", + "The 1st fullyQualifiedNamespace item has the wrong fullyQualifiedNamespace." + ); + should.equal( + ownershipList[0].eventHubName, + "testEventHub", + "The 1st ownership item has the wrong eventHubName." + ); + should.equal( + ownershipList[0].partitionId, + "0", + "The 1st ownership item has the wrong partitionId." + ); + should.exist(ownershipList[0].lastModifiedTimeInMs, "lastModifiedTimeInMs should exist."); + should.exist(ownershipList[0].etag, "etag should exist."); - ownershipList[1].partitionId.should.equal("1"); - ownershipList[1].lastModifiedTimeInMs!.should.not.undefined; - ownershipList[1].etag!.should.not.undefined; + should.equal( + ownershipList[1].partitionId, + "1", + "The 2nd ownership item has the wrong partitionId." + ); + should.exist(ownershipList[1].lastModifiedTimeInMs, "lastModifiedTimeInMs should exist."); + should.exist(ownershipList[1].etag, "etag should exist."); - ownershipList[2].partitionId.should.equal("2"); - ownershipList[2].lastModifiedTimeInMs!.should.not.undefined; - ownershipList[2].etag!.should.not.undefined; + should.equal( + ownershipList[2].partitionId, + "2", + "The 3rd ownership item has the wrong partitionId." + ); + should.exist(ownershipList[2].lastModifiedTimeInMs, "lastModifiedTimeInMs should exist."); + should.exist(ownershipList[2].etag, "etag should exist."); }); describe("listCheckpoints", function() { diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/test/utils/testUtils.ts b/sdk/eventhub/eventhubs-checkpointstore-blob/test/utils/testUtils.ts index 1ce3adc3dd29..82c58389846c 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/test/utils/testUtils.ts +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/test/utils/testUtils.ts @@ -4,6 +4,8 @@ import * as dotenv from "dotenv"; dotenv.config(); +declare const self: any; + export const isNode = !!process && !!process.version && !!process.versions && !!process.versions.node; @@ -15,8 +17,7 @@ function getEnvVarValue(name: string): string | undefined { if (isNode) { return process.env[name]; } else { - // @ts-ignore - return window.__env__[name]; + return self.__env__[name]; } }