diff --git a/common/tools/eslint-plugin-azure-sdk/src/configs/azure-sdk-base.ts b/common/tools/eslint-plugin-azure-sdk/src/configs/azure-sdk-base.ts index 4b67c58a579d..04e0253a360b 100644 --- a/common/tools/eslint-plugin-azure-sdk/src/configs/azure-sdk-base.ts +++ b/common/tools/eslint-plugin-azure-sdk/src/configs/azure-sdk-base.ts @@ -39,9 +39,10 @@ export default { ], "no-console": "off", "no-dupe-class-members": "off", + "no-invalid-this": "off", "no-empty": "error", "no-fallthrough": "error", - "no-invalid-this": "error", + "@typescript-eslint/no-invalid-this": "error", "@typescript-eslint/no-require-imports": "error", "no-restricted-imports": ["error", { paths: ["rhea", "rhea/.*"] }], "no-return-await": "error", diff --git a/sdk/anomalydetector/ai-anomaly-detector/test/anomalydetector.spec.ts b/sdk/anomalydetector/ai-anomaly-detector/test/anomalydetector.spec.ts index cb120e1c215e..4b44f893341e 100644 --- a/sdk/anomalydetector/ai-anomaly-detector/test/anomalydetector.spec.ts +++ b/sdk/anomalydetector/ai-anomaly-detector/test/anomalydetector.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert } from "chai"; +import { Context } from "mocha"; import { Recorder } from "@azure/test-utils-recorder"; import { AnomalyDetectorClient } from "../src/AnomalyDetectorClient"; import { AzureKeyCredential } from "@azure/core-auth"; @@ -19,11 +20,9 @@ describe("AnomalyDetectorClient", () => { let recorder: Recorder; const apiKey = new AzureKeyCredential(testEnv.ANOMALY_DETECTOR_API_KEY); - beforeEach( - /** @this Mocha.Context */ function() { - ({ recorder, client } = createRecordedAnomalyDetectorClient(this, apiKey)); - } - ); + beforeEach(function(this: Context) { + ({ recorder, client } = createRecordedAnomalyDetectorClient(this, apiKey)); + }); afterEach(async function() { if (recorder) { diff --git a/sdk/attestation/attestation/test/public/attestationTests.spec.ts b/sdk/attestation/attestation/test/public/attestationTests.spec.ts index d93d76ed91ed..aa2a79b95421 100644 --- a/sdk/attestation/attestation/test/public/attestationTests.spec.ts +++ b/sdk/attestation/attestation/test/public/attestationTests.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert, use as chaiUse } from "chai"; +import { Context } from "mocha"; import chaiPromises from "chai-as-promised"; chaiUse(chaiPromises); @@ -14,7 +15,7 @@ import { verifyAttestationToken } from "../utils/helpers"; describe("[AAD] Attestation Client", function() { let recorder: Recorder; - beforeEach(/** @this Mocha.Context */ function() { + beforeEach(function(this: Context) { recorder = createRecorder(this); }); diff --git a/sdk/attestation/attestation/test/public/policyGetSetTests.spec.ts b/sdk/attestation/attestation/test/public/policyGetSetTests.spec.ts index c6aae43ce107..981167a8c701 100644 --- a/sdk/attestation/attestation/test/public/policyGetSetTests.spec.ts +++ b/sdk/attestation/attestation/test/public/policyGetSetTests.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert, use as chaiUse } from "chai"; +import { Context } from "mocha"; import chaiPromises from "chai-as-promised"; chaiUse(chaiPromises); @@ -14,7 +15,7 @@ import { verifyAttestationToken } from "../utils/helpers"; describe("PolicyGetSetTests ", function() { let recorder: Recorder; - beforeEach(/** @this Mocha.Context */ function() { + beforeEach(function(this: Context) { recorder = createRecorder(this); }); diff --git a/sdk/attestation/attestation/test/public/policyManagementGetSetTests.spec.ts b/sdk/attestation/attestation/test/public/policyManagementGetSetTests.spec.ts index 9f83fafe11b2..d814287408d8 100644 --- a/sdk/attestation/attestation/test/public/policyManagementGetSetTests.spec.ts +++ b/sdk/attestation/attestation/test/public/policyManagementGetSetTests.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert, use as chaiUse } from "chai"; +import { Context } from "mocha"; import chaiPromises from "chai-as-promised"; chaiUse(chaiPromises); @@ -13,7 +14,7 @@ import { verifyAttestationToken } from "../utils/helpers"; describe("PolicyManagementTests ", function() { let recorder: Recorder; - beforeEach(/** @this Mocha.Context */ function() { + beforeEach(function(this: Context) { recorder = createRecorder(this); }); diff --git a/sdk/attestation/attestation/test/public/tokenCertTests.spec.ts b/sdk/attestation/attestation/test/public/tokenCertTests.spec.ts index da8030379308..321b5f616c49 100644 --- a/sdk/attestation/attestation/test/public/tokenCertTests.spec.ts +++ b/sdk/attestation/attestation/test/public/tokenCertTests.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert, use as chaiUse } from "chai"; +import { Context } from "mocha"; import chaiPromises from "chai-as-promised"; chaiUse(chaiPromises); @@ -13,7 +14,7 @@ import { Buffer } from "../utils/Buffer"; describe("TokenCertTests", function() { let recorder: Recorder; - beforeEach(/** @this Mocha.Context */ function() { + beforeEach(function(this: Context) { recorder = createRecorder(this); }); diff --git a/sdk/containerregistry/container-registry/test/public/containerRegistryClient.spec.ts b/sdk/containerregistry/container-registry/test/public/containerRegistryClient.spec.ts index d09350de7c50..0b7a09ec4113 100644 --- a/sdk/containerregistry/container-registry/test/public/containerRegistryClient.spec.ts +++ b/sdk/containerregistry/container-registry/test/public/containerRegistryClient.spec.ts @@ -50,36 +50,34 @@ describe.skip("ContainerRegistryClient functional tests", function() { // NOTE: use of "function" and not ES6 arrow-style functions with the // beforeEach hook is IMPORTANT due to the use of `this` in the function // body. - beforeEach( - /** @this Mocha.Context */ function(this: Context) { - // The recorder has some convenience methods, and we need to store a - // reference to it so that we can `stop()` the recorder later in the - // `afterEach` hook. - recorder = record(this, { - // == Recorder Environment Setup == Add the replaceable variables from - // above - replaceableVariables, + beforeEach(function(this: Context) { + // The recorder has some convenience methods, and we need to store a + // reference to it so that we can `stop()` the recorder later in the + // `afterEach` hook. + recorder = record(this, { + // == Recorder Environment Setup == Add the replaceable variables from + // above + replaceableVariables, - // We don't use this in the template, but if we had any query parameters - // we wished to discard, we could add them here - queryParametersToSkip: [], + // We don't use this in the template, but if we had any query parameters + // we wished to discard, we could add them here + queryParametersToSkip: [], - // Finally, we need to remove the AAD `access_token` from any requests. - // This is very important, as it cannot be removed using environment - // variable or query parameter replacement. The - // `customizationsOnRecordings` field allows us to make arbitrary - // replacements within recordings. - customizationsOnRecordings: [ - (recording: any): any => - recording.replace(/"access_token":"[^"]*"/g, `"access_token":"access_token"`) - ] - }); + // Finally, we need to remove the AAD `access_token` from any requests. + // This is very important, as it cannot be removed using environment + // variable or query parameter replacement. The + // `customizationsOnRecordings` field allows us to make arbitrary + // replacements within recordings. + customizationsOnRecordings: [ + (recording: any): any => + recording.replace(/"access_token":"[^"]*"/g, `"access_token":"access_token"`) + ] + }); - // We'll be able to refer to the instantiated `client` in tests, since we - // initialize it before each test - client = createTestClient(); - } - ); + // We'll be able to refer to the instantiated `client` in tests, since we + // initialize it before each test + client = createTestClient(); + }); // After each test, we need to stop the recording. afterEach(async function() { diff --git a/sdk/core/core-http/test/defaultHttpClientTests.ts b/sdk/core/core-http/test/defaultHttpClientTests.ts index e548d2e26ff6..0d8bde425ae5 100644 --- a/sdk/core/core-http/test/defaultHttpClientTests.ts +++ b/sdk/core/core-http/test/defaultHttpClientTests.ts @@ -4,6 +4,7 @@ /* eslint-disable no-unused-expressions */ import { assert, AssertionError } from "chai"; +import { Context } from "mocha"; import * as sinon from "sinon"; import { AbortController } from "@azure/abort-controller"; import "chai/register-should"; @@ -236,7 +237,7 @@ describe("defaultHttpClient", function() { } }); - it("should give a graceful error for nonexistent hosts", /** @this Mocha.Context */ async function() { + it("should give a graceful error for nonexistent hosts", async function(this: Context) { // Increase timeout to give the request time to fail this.timeout(10000); const requestUrl = "http://fake.domain"; diff --git a/sdk/core/core-lro/test/utils/testOperation.ts b/sdk/core/core-lro/test/utils/testOperation.ts index 8741abce9efb..427ca4574233 100644 --- a/sdk/core/core-lro/test/utils/testOperation.ts +++ b/sdk/core/core-lro/test/utils/testOperation.ts @@ -21,7 +21,6 @@ export interface TestOperationState extends PollOperationState { export interface TestOperation extends PollOperation {} -/** @this TestOperation */ async function update( this: TestOperation, options: { @@ -70,7 +69,6 @@ async function update( return makeOperation(newState); } -/** @this TestOperation */ async function cancel( this: TestOperation, options: { abortSignal?: AbortSignal } = {} @@ -101,7 +99,6 @@ async function cancel( }); } -/** @this TestOperation */ function toString(this: TestOperation): string { return JSON.stringify({ state: this.state diff --git a/sdk/core/logger/src/debug.ts b/sdk/core/logger/src/debug.ts index 1c29423fe62a..cd4f5f876689 100644 --- a/sdk/core/logger/src/debug.ts +++ b/sdk/core/logger/src/debug.ts @@ -155,7 +155,6 @@ function createDebugger(namespace: string): Debugger { return newDebugger; } -/** @this Debugger */ function destroy(this: Debugger): boolean { const index = debuggers.indexOf(this); if (index >= 0) { @@ -165,7 +164,6 @@ function destroy(this: Debugger): boolean { return false; } -/** @this Debugger */ function extend(this: Debugger, namespace: string): Debugger { const newDebugger = createDebugger(`${this.namespace}:${namespace}`); newDebugger.log = this.log; diff --git a/sdk/cosmosdb/cosmos/src/queryExecutionContext/documentProducer.ts b/sdk/cosmosdb/cosmos/src/queryExecutionContext/documentProducer.ts index 5505c966f9a1..9054b9198b4a 100644 --- a/sdk/cosmosdb/cosmos/src/queryExecutionContext/documentProducer.ts +++ b/sdk/cosmosdb/cosmos/src/queryExecutionContext/documentProducer.ts @@ -86,21 +86,19 @@ export class DocumentProducer { } public fetchFunction = async (options: FeedOptions): Promise> => { - // eslint-disable-next-line no-invalid-this const path = getPathFromLink(this.collectionLink, ResourceType.item); - // eslint-disable-next-line no-invalid-this + const id = getIdFromLink(this.collectionLink); - // eslint-disable-next-line no-invalid-this return this.clientContext.queryFeed({ path, resourceType: ResourceType.item, resourceId: id, resultFn: (result: any) => result.Documents, - // eslint-disable-next-line no-invalid-this + query: this.query, options, - // eslint-disable-next-line no-invalid-this + partitionKeyRangeId: this.targetPartitionKeyRange["id"] }); }; diff --git a/sdk/cosmosdb/cosmos/test/internal/session.spec.ts b/sdk/cosmosdb/cosmos/test/internal/session.spec.ts index 769a78855d72..abe398f276a6 100644 --- a/sdk/cosmosdb/cosmos/test/internal/session.spec.ts +++ b/sdk/cosmosdb/cosmos/test/internal/session.spec.ts @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Context } from "mocha"; +import { Suite } from "mocha"; import * as sinon from "sinon"; import { ClientContext } from "../../src"; import { OperationType, ResourceType, trimSlashes } from "../../src/common"; @@ -28,7 +30,7 @@ function getCollection2TokenMap( return (sessionContainer as any).collectionResourceIdToSessionTokens; } -describe("Session Token", /** @this Mocha.Context */ function() { +describe("Session Token", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 20000); const containerId = "sessionTestColl"; @@ -304,7 +306,7 @@ describe("Session Token", /** @this Mocha.Context */ function() { spy.restore(); }); - it("validate 'lsn not caught up' error for higher lsn and clearing session token", /** @this Mocha.Context */ async function() { + it("validate 'lsn not caught up' error for higher lsn and clearing session token", async function(this: Context) { this.retries(2); const database = await getTestDatabase("session test", client); diff --git a/sdk/cosmosdb/cosmos/test/internal/unit/auth.spec.ts b/sdk/cosmosdb/cosmos/test/internal/unit/auth.spec.ts index cac18417be47..5064b97f44b7 100644 --- a/sdk/cosmosdb/cosmos/test/internal/unit/auth.spec.ts +++ b/sdk/cosmosdb/cosmos/test/internal/unit/auth.spec.ts @@ -2,9 +2,10 @@ // Licensed under the MIT license. import { getAuthorizationTokenUsingResourceTokens } from "../../../src/auth"; +import { Suite } from "mocha"; import assert from "assert"; -describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() { +describe("NodeJS CRUD Tests", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); it("should find exact match", async function() { diff --git a/sdk/cosmosdb/cosmos/test/public/functional/authorization.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/authorization.spec.ts index 3b6d75fa567f..faa0d7a21753 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/authorization.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/authorization.spec.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { CosmosClient, PermissionMode } from "../../../src"; import { PermissionDefinition } from "../../../src/"; import { endpoint, masterKey } from "../common/_testConfig"; @@ -11,7 +12,7 @@ import { removeAllDatabases } from "../common/TestHelpers"; -describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() { +describe("NodeJS CRUD Tests", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); beforeEach(async function() { await removeAllDatabases(); diff --git a/sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts index 8e18e80646b6..c7f8e434f30e 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { Agent } from "http"; import { CosmosClient } from "../../../src"; import { endpoint, masterKey } from "../common/_testConfig"; @@ -13,7 +14,7 @@ import { import AbortController from "node-abort-controller"; import { UsernamePasswordCredential } from "@azure/identity"; -describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() { +describe("NodeJS CRUD Tests", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 20000); describe("Validate client request timeout", function() { diff --git a/sdk/cosmosdb/cosmos/test/public/functional/conflict.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/conflict.spec.ts index 1f8aab90af1c..0d886db7c5a8 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/conflict.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/conflict.spec.ts @@ -1,9 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { removeAllDatabases, getTestContainer } from "../common/TestHelpers"; -describe("Conflicts", /** @this Mocha.Context */ function() { +describe("Conflicts", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); beforeEach(async function() { await removeAllDatabases(); diff --git a/sdk/cosmosdb/cosmos/test/public/functional/container.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/container.spec.ts index 81c4d262fa1f..3aa927ab6c9e 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/container.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/container.spec.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { Constants, ContainerResponse } from "../../../src"; import { ContainerDefinition, Database, Container } from "../../../src"; import { ContainerRequest } from "../../../src"; @@ -14,7 +15,7 @@ import { import { SpatialType } from "../../../src"; import { GeospatialType } from "../../../src"; -describe("Containers", /** @this Mocha.Context */ function() { +describe("Containers", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); beforeEach(async function() { await removeAllDatabases(); diff --git a/sdk/cosmosdb/cosmos/test/public/functional/database.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/database.spec.ts index 123c5fdec13f..c65efb69416e 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/database.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/database.spec.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { CosmosClient, DatabaseDefinition, Database } from "../../../src"; import { endpoint, masterKey } from "../common/_testConfig"; import { @@ -13,7 +14,7 @@ import { DatabaseRequest } from "../../../src"; const client = new CosmosClient({ endpoint, key: masterKey }); -describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() { +describe("NodeJS CRUD Tests", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); beforeEach(async function() { await removeAllDatabases(); diff --git a/sdk/cosmosdb/cosmos/test/public/functional/databaseaccount.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/databaseaccount.spec.ts index 1aa438386527..9e5c8d210430 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/databaseaccount.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/databaseaccount.spec.ts @@ -1,18 +1,18 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Context } from "mocha"; +import { Suite } from "mocha"; import { CosmosClient } from "../../../src"; import { endpoint, masterKey } from "../common/_testConfig"; const client = new CosmosClient({ endpoint, key: masterKey }); -describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() { +describe("NodeJS CRUD Tests", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); - beforeEach( - /** @this Mocha.Context */ async function() { - this.timeout(process.env.MOCHA_TIMEOUT || 10000); - } - ); + beforeEach(async function(this: Context) { + this.timeout(process.env.MOCHA_TIMEOUT || 10000); + }); describe("validate database account functionality", function() { it("nativeApi Should get database account successfully name based", async function() { diff --git a/sdk/cosmosdb/cosmos/test/public/functional/item.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/item.spec.ts index c231f99d5ac2..0b3ceb2fb1e5 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/item.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/item.spec.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { Container } from "../../../src"; import { ItemDefinition } from "../../../src"; import { @@ -26,7 +27,7 @@ interface TestItem { replace?: string; } -describe("Item CRUD", /** @this Mocha.Context */ function() { +describe("Item CRUD", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); beforeEach(async function() { await removeAllDatabases(); diff --git a/sdk/cosmosdb/cosmos/test/public/functional/offer.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/offer.spec.ts index e148d49c35db..6c51bd8dffe4 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/offer.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/offer.spec.ts @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Context } from "mocha"; +import { Suite } from "mocha"; import { Constants, CosmosClient } from "../../../src"; import { endpoint, masterKey } from "../common/_testConfig"; import { getTestContainer, removeAllDatabases } from "../common/TestHelpers"; @@ -15,15 +17,13 @@ const validateOfferResponseBody = function(offer: any): void { assert(offer._self.indexOf(offer.id) !== -1, "Offer id not contained in offer self link."); }; -describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() { +describe("NodeJS CRUD Tests", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); - beforeEach( - /** @this Mocha.Context */ async function() { - this.timeout(process.env.MOCHA_TIMEOUT || 10000); - await removeAllDatabases(); - } - ); + beforeEach(async function(this: Context) { + this.timeout(process.env.MOCHA_TIMEOUT || 10000); + await removeAllDatabases(); + }); describe("Validate Offer CRUD", function() { it("nativeApi Should do offer read and query operations successfully name based single partition collection", async function() { diff --git a/sdk/cosmosdb/cosmos/test/public/functional/permission.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/permission.spec.ts index c947e0a83114..0d30b5f56323 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/permission.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/permission.spec.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { PermissionMode } from "../../../src"; import { PermissionDefinition } from "../../../src"; import { @@ -10,7 +11,7 @@ import { replaceOrUpsertPermission } from "../common/TestHelpers"; -describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() { +describe("NodeJS CRUD Tests", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); beforeEach(async function() { await removeAllDatabases(); diff --git a/sdk/cosmosdb/cosmos/test/public/functional/query.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/query.spec.ts index 2de5e66f30bc..2ef50172b89a 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/query.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/query.spec.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { CosmosClient } from "../../../src"; import { Container } from "../../../src/"; import { endpoint, masterKey } from "../common/_testConfig"; @@ -14,7 +15,7 @@ if (!Symbol || !Symbol.asyncIterator) { (Symbol as any).asyncIterator = Symbol.for("Symbol.asyncIterator"); } -describe("Queries", /** @this Mocha.Context */ function() { +describe("Queries", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); before(async function() { await removeAllDatabases(); @@ -47,7 +48,7 @@ describe("Queries", /** @this Mocha.Context */ function() { }); }); - describe("QueryIterator", /** @this Mocha.Context */ function() { + describe("QueryIterator", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 30000); let resources: { container: Container; doc1: any; doc2: any; doc3: any }; @@ -143,7 +144,7 @@ describe("Queries", /** @this Mocha.Context */ function() { } }); - describe("SUM query iterator", /** @this Mocha.Context */ function() { + describe("SUM query iterator", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 30000); it("returns undefined sum with null value in aggregator", async function() { diff --git a/sdk/cosmosdb/cosmos/test/public/functional/spatial.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/spatial.spec.ts index 857b6ab3b301..8908db0c53bd 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/spatial.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/spatial.spec.ts @@ -1,10 +1,11 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { Database, DataType, IndexKind } from "../../../src"; import { createOrUpsertItem, getTestDatabase, removeAllDatabases } from "../common/TestHelpers"; -describe("Spatial Indexes", /** @this Mocha.Context */ function() { +describe("Spatial Indexes", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); beforeEach(async function() { await removeAllDatabases(); diff --git a/sdk/cosmosdb/cosmos/test/public/functional/sproc.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/sproc.spec.ts index 27baaf0b5532..cd1d6cd9b5de 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/sproc.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/sproc.spec.ts @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Context } from "mocha"; +import { Suite } from "mocha"; import { Constants } from "../../../src"; import { Container, StoredProcedureDefinition } from "../../../src/"; import { @@ -13,18 +15,16 @@ import { // Used for sproc declare let getContext: any; -describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() { +describe("NodeJS CRUD Tests", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); beforeEach(async function() { await removeAllDatabases(); }); describe("Validate sproc CRUD", function() { let container: Container; - beforeEach( - /** @this Mocha.Context */ async function() { - container = await getTestContainer(this.test.fullTitle()); - } - ); + beforeEach(async function(this: Context) { + container = await getTestContainer(this.test.fullTitle()); + }); it("nativeApi Should do sproc CRUD operations successfully with create/replace", async function() { // read sprocs @@ -94,11 +94,9 @@ describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() { describe("Validate stored procedure functionality", function() { let container: Container; - beforeEach( - /** @this Mocha.Context */ async function() { - container = await getTestContainer(this.test.fullTitle()); - } - ); + beforeEach(async function(this: Context) { + container = await getTestContainer(this.test.fullTitle()); + }); it("nativeApi should do stored procedure operations successfully with create/replace", async function() { const sproc1: StoredProcedureDefinition = { diff --git a/sdk/cosmosdb/cosmos/test/public/functional/trigger.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/trigger.spec.ts index cdcc6d5b90e9..21b4e4b788e3 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/trigger.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/trigger.spec.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { TriggerOperation, TriggerType } from "../../../src"; import { TriggerDefinition, Container } from "../../../src"; import { getTestContainer, removeAllDatabases } from "../common/TestHelpers"; @@ -10,7 +11,7 @@ const notFoundErrorCode = 404; // Mock for trigger function bodies declare let getContext: any; -describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() { +describe("NodeJS CRUD Tests", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); let container: Container; diff --git a/sdk/cosmosdb/cosmos/test/public/functional/ttl.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/ttl.spec.ts index 0682de279eae..14f6798f9a55 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/ttl.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/ttl.spec.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { Container, ContainerDefinition, Database } from "../../../src"; import { getTestDatabase, removeAllDatabases } from "../common/TestHelpers"; import { StatusCodes } from "../../../src"; @@ -11,7 +12,7 @@ async function sleep(time: number): Promise { }); } -describe("Container TTL", /** @this Mocha.Context */ function() { +describe("Container TTL", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 600000); beforeEach(async function() { await removeAllDatabases(); diff --git a/sdk/cosmosdb/cosmos/test/public/functional/udf.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/udf.spec.ts index cbfd1dfc5468..ddd28e77a6c0 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/udf.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/udf.spec.ts @@ -1,10 +1,11 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { UserDefinedFunctionDefinition, Container } from "../../../src"; import { removeAllDatabases, getTestContainer } from "../common/TestHelpers"; -describe("User Defined Function", /** @this Mocha.Context */ function() { +describe("User Defined Function", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); let container: Container; diff --git a/sdk/cosmosdb/cosmos/test/public/functional/user.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/user.spec.ts index c06ec026c6a9..523f81af6cdc 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/user.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/user.spec.ts @@ -1,10 +1,11 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { UserDefinition } from "../../../src"; import { createOrUpsertUser, getTestDatabase, removeAllDatabases } from "../common/TestHelpers"; -describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() { +describe("NodeJS CRUD Tests", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); beforeEach(async function() { await removeAllDatabases(); diff --git a/sdk/cosmosdb/cosmos/test/public/integration/aggregateQuery.spec.ts b/sdk/cosmosdb/cosmos/test/public/integration/aggregateQuery.spec.ts index 51dac69cf1fd..ba1cbebf1305 100644 --- a/sdk/cosmosdb/cosmos/test/public/integration/aggregateQuery.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/integration/aggregateQuery.spec.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { Container, ContainerDefinition } from "../../../src"; import { DataType, IndexKind } from "../../../src"; import { QueryIterator } from "../../../src"; @@ -9,7 +10,7 @@ import { FeedOptions } from "../../../src"; import { TestData } from "../common/TestData"; import { bulkInsertItems, getTestContainer, removeAllDatabases } from "../common/TestHelpers"; -describe("Aggregate Query", /** @this Mocha.Context */ function() { +describe("Aggregate Query", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 20000); const partitionKey = "key"; const uniquePartitionKey = "uniquePartitionKey"; diff --git a/sdk/cosmosdb/cosmos/test/public/integration/authorization.spec.ts b/sdk/cosmosdb/cosmos/test/public/integration/authorization.spec.ts index a7d22d30bd6a..09b121089106 100644 --- a/sdk/cosmosdb/cosmos/test/public/integration/authorization.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/integration/authorization.spec.ts @@ -1,12 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { Container, CosmosClient, PermissionMode } from "../../../src"; import { Database } from "../../../src"; import { endpoint } from "../common/_testConfig"; import { getTestContainer, removeAllDatabases } from "../common/TestHelpers"; -describe("Authorization", /** @this Mocha.Context */ function() { +describe("Authorization", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); // TODO: should have types for all these things diff --git a/sdk/cosmosdb/cosmos/test/public/integration/changeFeed.spec.ts b/sdk/cosmosdb/cosmos/test/public/integration/changeFeed.spec.ts index 97625a17e2e4..b56bb721dad3 100644 --- a/sdk/cosmosdb/cosmos/test/public/integration/changeFeed.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/integration/changeFeed.spec.ts @@ -1,11 +1,12 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { RequestOptions } from "../../../src"; import { Container, ContainerDefinition } from "../../../src"; import { getTestContainer, removeAllDatabases } from "../common/TestHelpers"; -describe("Change Feed Iterator", /** @this Mocha.Context */ function() { +describe("Change Feed Iterator", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 20000); // delete all databases and create sample database diff --git a/sdk/cosmosdb/cosmos/test/public/integration/crossPartition.spec.ts b/sdk/cosmosdb/cosmos/test/public/integration/crossPartition.spec.ts index 1bf0a5db5161..48c28a9f2a78 100644 --- a/sdk/cosmosdb/cosmos/test/public/integration/crossPartition.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/integration/crossPartition.spec.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import * as util from "util"; import { Container, ContainerDefinition } from "../../../src"; import { DataType, IndexKind } from "../../../src"; @@ -26,7 +27,7 @@ function compare(key: string) { }; } -describe("Cross Partition", /** @this Mocha.Context */ function() { +describe("Cross Partition", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || "30000"); describe("Validate Query", function() { diff --git a/sdk/cosmosdb/cosmos/test/public/integration/encoding.spec.ts b/sdk/cosmosdb/cosmos/test/public/integration/encoding.spec.ts index 33dc9521adfb..0dff2e7a7572 100644 --- a/sdk/cosmosdb/cosmos/test/public/integration/encoding.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/integration/encoding.spec.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { IndexingMode } from "../../../src"; import { getTestDatabase, removeAllDatabases } from "../common/TestHelpers"; @@ -10,7 +11,7 @@ const testDoc = { "€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€" }; -describe("Create And Read Validation", /** @this Mocha.Context */ function() { +describe("Create And Read Validation", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); const dateTime = new Date(); diff --git a/sdk/cosmosdb/cosmos/test/public/integration/multiregion.spec.ts b/sdk/cosmosdb/cosmos/test/public/integration/multiregion.spec.ts index 81570d28516f..f66aaea60c49 100644 --- a/sdk/cosmosdb/cosmos/test/public/integration/multiregion.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/integration/multiregion.spec.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { CosmosClient } from "../../../src"; import { masterKey } from "../common/_testConfig"; @@ -107,7 +108,7 @@ const collectionResponse = { code: 200 }; -describe("Multi-region tests", /** @this Mocha.Context */ function() { +describe("Multi-region tests", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || "30000"); it("Preferred locations should be honored for readEndpoint", async function() { diff --git a/sdk/cosmosdb/cosmos/test/public/integration/proxy.spec.ts b/sdk/cosmosdb/cosmos/test/public/integration/proxy.spec.ts index 7409c7bacc7f..66409b058b0d 100644 --- a/sdk/cosmosdb/cosmos/test/public/integration/proxy.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/integration/proxy.spec.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import * as http from "http"; +import { Context } from "mocha"; import * as net from "net"; import { URL } from "url"; import ProxyAgent from "proxy-agent"; @@ -52,7 +53,7 @@ if (!isBrowser()) { }); }); - it("nativeApi Client Should execute request in error while the proxy setting is not correct", /** @this Mocha.Context */ async function() { + it("nativeApi Client Should execute request in error while the proxy setting is not correct", async function(this: Context) { this.timeout(process.env.MOCHA_TIMEOUT || 30000); return new Promise((resolve, reject) => { proxy.listen(proxyPort + 1, "127.0.0.1", async () => { diff --git a/sdk/cosmosdb/cosmos/test/public/integration/query.spec.ts b/sdk/cosmosdb/cosmos/test/public/integration/query.spec.ts index f33bb4753ff3..44cb9cc022c1 100644 --- a/sdk/cosmosdb/cosmos/test/public/integration/query.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/integration/query.spec.ts @@ -1,12 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import assert from "assert"; +import { Suite } from "mocha"; import { FeedOptions } from "../../../src"; import { getTestContainer, getTestDatabase, removeAllDatabases } from "../common/TestHelpers"; const doc = { id: "myId", pk: "pk" }; -describe("ResourceLink Trimming of leading and trailing slashes", /** @this Mocha.Context */ function() { +describe("ResourceLink Trimming of leading and trailing slashes", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); const containerId = "testcontainer"; @@ -39,7 +40,7 @@ describe("ResourceLink Trimming of leading and trailing slashes", /** @this Moch }); }); -describe("Test Query Metrics", /** @this Mocha.Context */ function() { +describe("Test Query Metrics", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 20000); const collectionId = "testCollection2"; @@ -84,7 +85,7 @@ describe("Test Query Metrics", /** @this Mocha.Context */ function() { }); }); -describe("Partition key in FeedOptions", /** @this Mocha.Context */ function() { +describe("Partition key in FeedOptions", function(this: Suite) { this.timeout(process.env.MOCHA_TIMEOUT || 10000); beforeEach(async function() { diff --git a/sdk/eventgrid/eventgrid/test/eventGridClient.spec.ts b/sdk/eventgrid/eventgrid/test/eventGridClient.spec.ts index 7b9c98393f4b..15c5d797e0df 100644 --- a/sdk/eventgrid/eventgrid/test/eventGridClient.spec.ts +++ b/sdk/eventgrid/eventgrid/test/eventGridClient.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert } from "chai"; +import { Suite, Context } from "mocha"; import { Recorder } from "@azure/test-utils-recorder"; @@ -18,7 +19,7 @@ import { import { FullOperationResponse } from "@azure/core-client"; import { RestError } from "@azure/core-rest-pipeline"; -describe("EventGridPublisherClient", /** @this Mocha.Context */ function() { +describe("EventGridPublisherClient", function(this: Suite) { let recorder: Recorder; let res: FullOperationResponse | undefined; @@ -31,16 +32,14 @@ describe("EventGridPublisherClient", /** @this Mocha.Context */ function() { describe("#send (EventGrid schema)", function() { let client: EventGridPublisherClient<"EventGrid">; - beforeEach( - /** @this Mocha.Context */ function() { - ({ client, recorder } = createRecordedClient( - this, - testEnv.EVENT_GRID_EVENT_GRID_SCHEMA_ENDPOINT, - "EventGrid", - new AzureKeyCredential(testEnv.EVENT_GRID_EVENT_GRID_SCHEMA_API_KEY) - )); - } - ); + beforeEach(function(this: Context) { + ({ client, recorder } = createRecordedClient( + this, + testEnv.EVENT_GRID_EVENT_GRID_SCHEMA_ENDPOINT, + "EventGrid", + new AzureKeyCredential(testEnv.EVENT_GRID_EVENT_GRID_SCHEMA_API_KEY) + )); + }); afterEach(async function() { await recorder.stop(); @@ -100,16 +99,14 @@ describe("EventGridPublisherClient", /** @this Mocha.Context */ function() { describe("#send error cases (EventGrid schema)", function() { let client: EventGridPublisherClient<"EventGrid">; - beforeEach( - /** @this Mocha.Context */ function() { - ({ client, recorder } = createRecordedClient( - this, - removeApiEventsSuffix(testEnv.EVENT_GRID_CUSTOM_SCHEMA_ENDPOINT), - "EventGrid", - new AzureKeyCredential(testEnv.EVENT_GRID_CUSTOM_SCHEMA_API_KEY) - )); - } - ); + beforeEach(function(this: Context) { + ({ client, recorder } = createRecordedClient( + this, + removeApiEventsSuffix(testEnv.EVENT_GRID_CUSTOM_SCHEMA_ENDPOINT), + "EventGrid", + new AzureKeyCredential(testEnv.EVENT_GRID_CUSTOM_SCHEMA_API_KEY) + )); + }); afterEach(async function() { await recorder.stop(); @@ -145,16 +142,14 @@ describe("EventGridPublisherClient", /** @this Mocha.Context */ function() { describe("#send (CloudEvent schema)", function() { let client: EventGridPublisherClient<"CloudEvent">; - beforeEach( - /** @this Mocha.Context */ function() { - ({ client, recorder } = createRecordedClient( - this, - testEnv.EVENT_GRID_CLOUD_EVENT_SCHEMA_ENDPOINT, - "CloudEvent", - new AzureKeyCredential(testEnv.EVENT_GRID_CLOUD_EVENT_SCHEMA_API_KEY) - )); - } - ); + beforeEach(function(this: Context) { + ({ client, recorder } = createRecordedClient( + this, + testEnv.EVENT_GRID_CLOUD_EVENT_SCHEMA_ENDPOINT, + "CloudEvent", + new AzureKeyCredential(testEnv.EVENT_GRID_CLOUD_EVENT_SCHEMA_API_KEY) + )); + }); afterEach(async function() { await recorder.stop(); @@ -256,16 +251,14 @@ describe("EventGridPublisherClient", /** @this Mocha.Context */ function() { describe("#send error cases (CloudEvent schema)", function() { let client: EventGridPublisherClient<"CloudEvent">; - beforeEach( - /** @this Mocha.Context */ function() { - ({ client, recorder } = createRecordedClient( - this, - removeApiEventsSuffix(testEnv.EVENT_GRID_CLOUD_EVENT_SCHEMA_ENDPOINT), - "CloudEvent", - new AzureKeyCredential(testEnv.EVENT_GRID_CLOUD_EVENT_SCHEMA_API_KEY) - )); - } - ); + beforeEach(function(this: Context) { + ({ client, recorder } = createRecordedClient( + this, + removeApiEventsSuffix(testEnv.EVENT_GRID_CLOUD_EVENT_SCHEMA_ENDPOINT), + "CloudEvent", + new AzureKeyCredential(testEnv.EVENT_GRID_CLOUD_EVENT_SCHEMA_API_KEY) + )); + }); afterEach(async function() { await recorder.stop(); @@ -299,16 +292,14 @@ describe("EventGridPublisherClient", /** @this Mocha.Context */ function() { describe("#send (Custom Event Schema)", function() { let client: EventGridPublisherClient<"Custom">; - beforeEach( - /** @this Mocha.Context */ function() { - ({ client, recorder } = createRecordedClient( - this, - testEnv.EVENT_GRID_CUSTOM_SCHEMA_ENDPOINT, - "Custom", - new AzureKeyCredential(testEnv.EVENT_GRID_CUSTOM_SCHEMA_API_KEY) - )); - } - ); + beforeEach(function(this: Context) { + ({ client, recorder } = createRecordedClient( + this, + testEnv.EVENT_GRID_CUSTOM_SCHEMA_ENDPOINT, + "Custom", + new AzureKeyCredential(testEnv.EVENT_GRID_CUSTOM_SCHEMA_API_KEY) + )); + }); afterEach(async function() { await recorder.stop(); @@ -362,16 +353,14 @@ describe("EventGridPublisherClient", /** @this Mocha.Context */ function() { describe("#send error cases (Custom Event Schema)", function() { let client: EventGridPublisherClient<"Custom">; - beforeEach( - /** @this Mocha.Context */ function() { - ({ client, recorder } = createRecordedClient( - this, - removeApiEventsSuffix(testEnv.EVENT_GRID_CUSTOM_SCHEMA_ENDPOINT), - "Custom", - new AzureKeyCredential(testEnv.EVENT_GRID_CUSTOM_SCHEMA_API_KEY) - )); - } - ); + beforeEach(function(this: Context) { + ({ client, recorder } = createRecordedClient( + this, + removeApiEventsSuffix(testEnv.EVENT_GRID_CUSTOM_SCHEMA_ENDPOINT), + "Custom", + new AzureKeyCredential(testEnv.EVENT_GRID_CUSTOM_SCHEMA_API_KEY) + )); + }); afterEach(async function() { await recorder.stop(); diff --git a/sdk/formrecognizer/ai-form-recognizer/test/public/browser/formrecognizerclient.spec.ts b/sdk/formrecognizer/ai-form-recognizer/test/public/browser/formrecognizerclient.spec.ts index 03515611079a..cfab99f1cef5 100644 --- a/sdk/formrecognizer/ai-form-recognizer/test/public/browser/formrecognizerclient.spec.ts +++ b/sdk/formrecognizer/ai-form-recognizer/test/public/browser/formrecognizerclient.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert } from "chai"; +import { Context } from "mocha"; import { DefaultHttpClient, WebResource } from "@azure/core-http"; import { FormRecognizerClient, AzureKeyCredential } from "../../../src"; import { env, Recorder } from "@azure/test-utils-recorder"; @@ -16,11 +17,9 @@ describe("FormRecognizerClient browser only", () => { let recorder: Recorder; const apiKey = new AzureKeyCredential(testEnv.FORM_RECOGNIZER_API_KEY); - beforeEach( - /** @this Mocha.Context */ function() { - ({ recorder, client } = createRecordedRecognizerClient(this, apiKey)); - } - ); + beforeEach(function(this: Context) { + ({ recorder, client } = createRecordedRecognizerClient(this, apiKey)); + }); afterEach(async function() { if (recorder) { diff --git a/sdk/formrecognizer/ai-form-recognizer/test/public/formtrainingclient.spec.ts b/sdk/formrecognizer/ai-form-recognizer/test/public/formtrainingclient.spec.ts index 582c49f61c1f..d99224def0c1 100644 --- a/sdk/formrecognizer/ai-form-recognizer/test/public/formtrainingclient.spec.ts +++ b/sdk/formrecognizer/ai-form-recognizer/test/public/formtrainingclient.spec.ts @@ -27,11 +27,9 @@ matrix([[true, false]] as const, async (useAad) => { describe(`[${useAad ? "AAD" : "API Key"}] FormTrainingClient`, () => { let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ function(this: Context) { - recorder = createRecorder(this); - } - ); + beforeEach(function(this: Context) { + recorder = createRecorder(this); + }); afterEach(async function() { await recorder.stop(); diff --git a/sdk/formrecognizer/ai-form-recognizer/test/public/node/formrecognizerclient.spec.ts b/sdk/formrecognizer/ai-form-recognizer/test/public/node/formrecognizerclient.spec.ts index 09094bd24aa4..cf26909f3001 100644 --- a/sdk/formrecognizer/ai-form-recognizer/test/public/node/formrecognizerclient.spec.ts +++ b/sdk/formrecognizer/ai-form-recognizer/test/public/node/formrecognizerclient.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert } from "chai"; +import { Context } from "mocha"; import fs from "fs"; import path from "path"; @@ -28,12 +29,10 @@ matrix([[true, false]] as const, async (useAad) => { let client: FormRecognizerClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ function() { - recorder = createRecorder(this); - client = new FormRecognizerClient(endpoint(), makeCredential(useAad)); - } - ); + beforeEach(function(this: Context) { + recorder = createRecorder(this); + client = new FormRecognizerClient(endpoint(), makeCredential(useAad)); + }); afterEach(async function() { if (recorder) { diff --git a/sdk/identity/identity/test/internal/identityClient.spec.ts b/sdk/identity/identity/test/internal/identityClient.spec.ts index be51be197996..0992d508c078 100644 --- a/sdk/identity/identity/test/internal/identityClient.spec.ts +++ b/sdk/identity/identity/test/internal/identityClient.spec.ts @@ -7,6 +7,7 @@ import { IdentityClient } from "../../src/client/identityClient"; import { ClientSecretCredential } from "../../src"; import { setLogLevel, AzureLogger, getLogLevel, AzureLogLevel } from "@azure/logger"; import { isNode } from "@azure/core-http"; +import { Context } from "mocha"; function isExpectedError(expectedErrorName: string): (error: any) => boolean { return (error: any) => { @@ -77,9 +78,8 @@ describe("IdentityClient", function() { ); }); - it("throws an exception when an Env AZURE_AUTHORITY_HOST using 'http' is provided", async function() { + it("throws an exception when an Env AZURE_AUTHORITY_HOST using 'http' is provided", async function(this: Context) { if (!isNode) { - // eslint-disable-next-line no-invalid-this return this.skip(); } process.env.AZURE_AUTHORITY_HOST = "http://totallyinsecure.lol"; diff --git a/sdk/identity/identity/test/internal/node/clientCertificateCredential.spec.ts b/sdk/identity/identity/test/internal/node/clientCertificateCredential.spec.ts index 442204eeb573..be7ff9b0a066 100644 --- a/sdk/identity/identity/test/internal/node/clientCertificateCredential.spec.ts +++ b/sdk/identity/identity/test/internal/node/clientCertificateCredential.spec.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable no-invalid-this */ + /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ import Sinon from "sinon"; @@ -12,13 +12,14 @@ import { ClientCertificateCredential, TokenCachePersistenceOptions } from "../.. import { MsalTestCleanup, msalNodeTestSetup } from "../../msalTestUtils"; import { TokenCachePersistence } from "../../../src/tokenCache/TokenCachePersistence"; import { MsalNode } from "../../../src/msal/nodeFlows/nodeCommon"; +import { Context } from "mocha"; describe("ClientCertificateCredential (internal)", function() { let cleanup: MsalTestCleanup; let getTokenSilentSpy: Sinon.SinonSpy; let doGetTokenSpy: Sinon.SinonSpy; - beforeEach(function() { + beforeEach(function(this: Context) { const setup = msalNodeTestSetup(this); cleanup = setup.cleanup; @@ -47,7 +48,7 @@ describe("ClientCertificateCredential (internal)", function() { }); }); - it("Authenticates silently after the initial request", async function() { + it("Authenticates silently after the initial request", async function(this: Context) { if (isPlaybackMode()) { // MSAL creates a client assertion based on the certificate that I haven't been able to mock. // This assertion could be provided as parameters, but we don't have that in the public API yet, @@ -83,7 +84,7 @@ describe("ClientCertificateCredential (internal)", function() { return; } - it("Accepts tokenCachePersistenceOptions", async function() { + it("Accepts tokenCachePersistenceOptions", async function(this: Context) { if (isPlaybackMode()) { // MSAL creates a client assertion based on the certificate that I haven't been able to mock. // This assertion could be provided as parameters, but we don't have that in the public API yet, @@ -118,7 +119,7 @@ describe("ClientCertificateCredential (internal)", function() { assert.ok(parsedResult.AccessToken); }); - it("Authenticates silently with tokenCachePersistenceOptions", async function() { + it("Authenticates silently with tokenCachePersistenceOptions", async function(this: Context) { if (isPlaybackMode()) { // MSAL creates a client assertion based on the certificate that I haven't been able to mock. // This assertion could be provided as parameters, but we don't have that in the public API yet, diff --git a/sdk/identity/identity/test/internal/node/clientSecretCredential.spec.ts b/sdk/identity/identity/test/internal/node/clientSecretCredential.spec.ts index afcaace292e7..ea26a1c52292 100644 --- a/sdk/identity/identity/test/internal/node/clientSecretCredential.spec.ts +++ b/sdk/identity/identity/test/internal/node/clientSecretCredential.spec.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable no-invalid-this */ + /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ import Sinon from "sinon"; @@ -12,13 +12,14 @@ import { MsalTestCleanup, msalNodeTestSetup } from "../../msalTestUtils"; import { TokenCachePersistence } from "../../../src/tokenCache/TokenCachePersistence"; import { MsalNode } from "../../../src/msal/nodeFlows/nodeCommon"; import { isNode15, isNode8 } from "../../../src/tokenCache/nodeVersion"; +import { Context } from "mocha"; describe("ClientSecretCredential (internal)", function() { let cleanup: MsalTestCleanup; let getTokenSilentSpy: Sinon.SinonSpy; let doGetTokenSpy: Sinon.SinonSpy; - beforeEach(function() { + beforeEach(function(this: Context) { const setup = msalNodeTestSetup(this); cleanup = setup.cleanup; @@ -65,7 +66,7 @@ describe("ClientSecretCredential (internal)", function() { return; } - it("Accepts tokenCachePersistenceOptions", async function() { + it("Accepts tokenCachePersistenceOptions", async function(this: Context) { // msal-node-extensions does not currently support Node 8. if (isNode8 || isNode15) { this.skip(); @@ -98,7 +99,7 @@ describe("ClientSecretCredential (internal)", function() { assert.ok(parsedResult.AccessToken); }); - it("Authenticates silently with tokenCachePersistenceOptions", async function() { + it("Authenticates silently with tokenCachePersistenceOptions", async function(this: Context) { // msal-node-extensions does not currently support Node 8. if (isNode8 || isNode15) { this.skip(); diff --git a/sdk/identity/identity/test/internal/node/deviceCodeCredential.spec.ts b/sdk/identity/identity/test/internal/node/deviceCodeCredential.spec.ts index e23b2889f2d3..33ceabd39f90 100644 --- a/sdk/identity/identity/test/internal/node/deviceCodeCredential.spec.ts +++ b/sdk/identity/identity/test/internal/node/deviceCodeCredential.spec.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable no-invalid-this */ + /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ import Sinon from "sinon"; @@ -12,13 +12,14 @@ import { MsalTestCleanup, msalNodeTestSetup } from "../../msalTestUtils"; import { TokenCachePersistence } from "../../../src/tokenCache/TokenCachePersistence"; import { MsalNode } from "../../../src/msal/nodeFlows/nodeCommon"; import { isNode15, isNode8 } from "../../../src/tokenCache/nodeVersion"; +import { Context } from "mocha"; describe("DeviceCodeCredential (internal)", function() { let cleanup: MsalTestCleanup; let getTokenSilentSpy: Sinon.SinonSpy; let doGetTokenSpy: Sinon.SinonSpy; - beforeEach(function() { + beforeEach(function(this: Context) { const setup = msalNodeTestSetup(this); cleanup = setup.cleanup; @@ -36,7 +37,7 @@ describe("DeviceCodeCredential (internal)", function() { const scope = "https://vault.azure.net/.default"; - it("Authenticates silently after the initial request", async function() { + it("Authenticates silently after the initial request", async function(this: Context) { // These tests should not run live because this credential requires user interaction. if (isLiveMode()) { this.skip(); @@ -64,7 +65,7 @@ describe("DeviceCodeCredential (internal)", function() { return; } - it("Accepts tokenCachePersistenceOptions", async function() { + it("Accepts tokenCachePersistenceOptions", async function(this: Context) { // msal-node-extensions does not currently support Node 8. if (isNode8 || isNode15) { this.skip(); @@ -98,7 +99,7 @@ describe("DeviceCodeCredential (internal)", function() { assert.ok(parsedResult.AccessToken); }); - it("Authenticates silently with tokenCachePersistenceOptions", async function() { + it("Authenticates silently with tokenCachePersistenceOptions", async function(this: Context) { // msal-node-extensions does not currently support Node 8. if (isNode8 || isNode15) { this.skip(); @@ -140,7 +141,7 @@ describe("DeviceCodeCredential (internal)", function() { assert.equal(doGetTokenSpy.callCount, 1); }); - it("allows passing an authenticationRecord to avoid further manual authentications", async function() { + it("allows passing an authenticationRecord to avoid further manual authentications", async function(this: Context) { // msal-node-extensions does not currently support Node 8. if (isNode8 || isNode15) { this.skip(); diff --git a/sdk/identity/identity/test/internal/node/environmentCredential.spec.ts b/sdk/identity/identity/test/internal/node/environmentCredential.spec.ts index 03301dfd026d..80f595f64ea4 100644 --- a/sdk/identity/identity/test/internal/node/environmentCredential.spec.ts +++ b/sdk/identity/identity/test/internal/node/environmentCredential.spec.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable no-invalid-this */ + /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ import Sinon from "sinon"; @@ -9,13 +9,14 @@ import { ConfidentialClientApplication } from "@azure/msal-node"; import { EnvironmentCredential } from "../../../src"; import { MsalTestCleanup, msalNodeTestSetup } from "../../msalTestUtils"; import { MsalNode } from "../../../src/msal/nodeFlows/nodeCommon"; +import { Context } from "mocha"; describe("EnvironmentCredential (internal)", function() { let cleanup: MsalTestCleanup; let getTokenSilentSpy: Sinon.SinonSpy; let doGetTokenSpy: Sinon.SinonSpy; - beforeEach(function() { + beforeEach(function(this: Context) { const setup = msalNodeTestSetup(this); cleanup = setup.cleanup; diff --git a/sdk/identity/identity/test/internal/node/usernamePasswordCredential.spec.ts b/sdk/identity/identity/test/internal/node/usernamePasswordCredential.spec.ts index 072dc28d07cb..71ce29001414 100644 --- a/sdk/identity/identity/test/internal/node/usernamePasswordCredential.spec.ts +++ b/sdk/identity/identity/test/internal/node/usernamePasswordCredential.spec.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable no-invalid-this */ + /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ import Sinon from "sinon"; @@ -21,13 +21,14 @@ import { Node15NotSupportedError, Node8NotSupportedError } from "../../../src/tokenCache/nodeVersion"; +import { Context } from "mocha"; describe("UsernamePasswordCredential (internal)", function() { let cleanup: MsalTestCleanup; let getTokenSilentSpy: Sinon.SinonSpy; let doGetTokenSpy: Sinon.SinonSpy; - beforeEach(function() { + beforeEach(function(this: Context) { const setup = msalNodeTestSetup(this); cleanup = setup.cleanup; @@ -46,7 +47,7 @@ describe("UsernamePasswordCredential (internal)", function() { const scope = "https://vault.azure.net/.default"; - it("Authenticates silently after the initial request", async function() { + it("Authenticates silently after the initial request", async function(this: Context) { // These tests should not run live because this credential requires user interaction. if (isLiveMode()) { this.skip(); @@ -76,7 +77,7 @@ describe("UsernamePasswordCredential (internal)", function() { return; } - it("Persistence throws on Node 8, as expected", async function() { + it("Persistence throws on Node 8, as expected", async function(this: Context) { if (!isNode8) { this.skip(); } @@ -99,7 +100,7 @@ describe("UsernamePasswordCredential (internal)", function() { assert.equal(error?.message, Node8NotSupportedError.message); }); - it("Persistence throws on Node 15, as expected", async function() { + it("Persistence throws on Node 15, as expected", async function(this: Context) { if (!isNode15) { this.skip(); } @@ -122,7 +123,7 @@ describe("UsernamePasswordCredential (internal)", function() { assert.equal(error?.message, Node15NotSupportedError.message); }); - it("Accepts tokenCachePersistenceOptions", async function() { + it("Accepts tokenCachePersistenceOptions", async function(this: Context) { // msal-node-extensions does not currently support Node 8. if (isNode8 || isNode15) { this.skip(); @@ -159,7 +160,7 @@ describe("UsernamePasswordCredential (internal)", function() { assert.ok(parsedResult.AccessToken); }); - it("Authenticates silently with tokenCachePersistenceOptions", async function() { + it("Authenticates silently with tokenCachePersistenceOptions", async function(this: Context) { // msal-node-extensions does not currently support Node 8. if (isNode8 || isNode15) { this.skip(); @@ -205,7 +206,7 @@ describe("UsernamePasswordCredential (internal)", function() { assert.equal(doGetTokenSpy.callCount, 1); }); - it("allows passing an authenticationRecord to avoid further manual authentications", async function() { + it("allows passing an authenticationRecord to avoid further manual authentications", async function(this: Context) { // msal-node-extensions does not currently support Node 8. if (isNode8 || isNode15) { this.skip(); @@ -265,7 +266,7 @@ describe("UsernamePasswordCredential (internal)", function() { assert.equal(doGetTokenSpy.callCount, 1); }); - it("allows working with an authenticationRecord that is serialized", async function() { + it("allows working with an authenticationRecord that is serialized", async function(this: Context) { // msal-node-extensions does not currently support Node 8. if (isNode8 || isNode15) { this.skip(); diff --git a/sdk/identity/identity/test/public/node/clientCertificateCredential.spec.ts b/sdk/identity/identity/test/public/node/clientCertificateCredential.spec.ts index 82ad4337616a..f7b9bed6f8a2 100644 --- a/sdk/identity/identity/test/public/node/clientCertificateCredential.spec.ts +++ b/sdk/identity/identity/test/public/node/clientCertificateCredential.spec.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable no-invalid-this */ + /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ import assert from "assert"; @@ -9,10 +9,11 @@ import { AbortController } from "@azure/abort-controller"; import { env, isPlaybackMode, delay } from "@azure/test-utils-recorder"; import { MsalTestCleanup, msalNodeTestSetup, testTracing } from "../../msalTestUtils"; import { ClientCertificateCredential } from "../../../src"; +import { Context } from "mocha"; describe("ClientCertificateCredential", function() { let cleanup: MsalTestCleanup; - beforeEach(function() { + beforeEach(function(this: Context) { cleanup = msalNodeTestSetup(this).cleanup; }); afterEach(async function() { @@ -22,7 +23,7 @@ describe("ClientCertificateCredential", function() { const certificatePath = path.resolve(__dirname, "../test/assets/cert.pem"); const scope = "https://vault.azure.net/.default"; - it("authenticates", async function() { + it("authenticates", async function(this: Context) { if (isPlaybackMode()) { // MSAL creates a client assertion based on the certificate that I haven't been able to mock. // This assertion could be provided as parameters, but we don't have that in the public API yet, @@ -41,7 +42,7 @@ describe("ClientCertificateCredential", function() { assert.ok(token?.expiresOnTimestamp! > Date.now()); }); - it("authenticates with sendCertificateChain", async function() { + it("authenticates with sendCertificateChain", async function(this: Context) { if (isPlaybackMode()) { // MSAL creates a client assertion based on the certificate that I haven't been able to mock. // This assertion could be provided as parameters, but we don't have that in the public API yet, @@ -86,7 +87,7 @@ describe("ClientCertificateCredential", function() { assert.ok(error?.message.includes("could not resolve endpoints")); }); - it("supports tracing", async function() { + it("supports tracing", async function(this: Context) { if (isPlaybackMode()) { // MSAL creates a client assertion based on the certificate that I haven't been able to mock. // This assertion could be provided as parameters, but we don't have that in the public API yet, diff --git a/sdk/identity/identity/test/public/node/clientSecretCredential.spec.ts b/sdk/identity/identity/test/public/node/clientSecretCredential.spec.ts index d4b1eef9eb28..8d95e07dee11 100644 --- a/sdk/identity/identity/test/public/node/clientSecretCredential.spec.ts +++ b/sdk/identity/identity/test/public/node/clientSecretCredential.spec.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable no-invalid-this */ + /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ import assert from "assert"; @@ -8,10 +8,11 @@ import { env, delay } from "@azure/test-utils-recorder"; import { AbortController } from "@azure/abort-controller"; import { MsalTestCleanup, msalNodeTestSetup, testTracing } from "../../msalTestUtils"; import { ClientSecretCredential } from "../../../src"; +import { Context } from "mocha"; describe("ClientSecretCredential", function() { let cleanup: MsalTestCleanup; - beforeEach(function() { + beforeEach(function(this: Context) { cleanup = msalNodeTestSetup(this).cleanup; }); afterEach(async function() { diff --git a/sdk/identity/identity/test/public/node/deviceCodeCredential.spec.ts b/sdk/identity/identity/test/public/node/deviceCodeCredential.spec.ts index d1aaeaaffdf1..1801c8ffa909 100644 --- a/sdk/identity/identity/test/public/node/deviceCodeCredential.spec.ts +++ b/sdk/identity/identity/test/public/node/deviceCodeCredential.spec.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable no-invalid-this */ + /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ import assert from "assert"; @@ -8,10 +8,11 @@ import { env, isLiveMode, delay } from "@azure/test-utils-recorder"; import { AbortController, AbortError } from "@azure/abort-controller"; import { DeviceCodeCredential, DeviceCodePromptCallback } from "../../../src"; import { msalNodeTestSetup, MsalTestCleanup, testTracing } from "../../msalTestUtils"; +import { Context } from "mocha"; describe("DeviceCodeCredential", function() { let cleanup: MsalTestCleanup; - beforeEach(function() { + beforeEach(function(this: Context) { cleanup = msalNodeTestSetup(this).cleanup; }); afterEach(async function() { @@ -20,7 +21,7 @@ describe("DeviceCodeCredential", function() { const scope = "https://vault.azure.net/.default"; - it("authenticates with default values", async function() { + it("authenticates with default values", async function(this: Context) { // These tests should not run live because this credential requires user interaction. if (isLiveMode()) { this.skip(); @@ -32,7 +33,7 @@ describe("DeviceCodeCredential", function() { assert.ok(token?.expiresOnTimestamp! > Date.now()); }); - it("authenticates with provided values", async function() { + it("authenticates with provided values", async function(this: Context) { // These tests should not run live because this credential requires user interaction. if (isLiveMode()) { this.skip(); @@ -47,7 +48,7 @@ describe("DeviceCodeCredential", function() { assert.ok(token?.expiresOnTimestamp! > Date.now()); }); - it("authenticates and allows the customization of the prompt callback", async function() { + it("authenticates and allows the customization of the prompt callback", async function(this: Context) { // These tests should not run live because this credential requires user interaction. if (isLiveMode()) { this.skip(); @@ -91,7 +92,7 @@ describe("DeviceCodeCredential", function() { assert.equal(error?.message, "Cancellation triggered by the AbortSignal"); }); - it("allows setting disableAutomaticAuthentication", async function() { + it("allows setting disableAutomaticAuthentication", async function(this: Context) { // These tests should not run live because this credential requires user interaction. if (isLiveMode()) { this.skip(); @@ -115,7 +116,7 @@ describe("DeviceCodeCredential", function() { assert.ok(account); }); - it("supports tracing", async function() { + it("supports tracing", async function(this: Context) { // These tests should not run live because this credential requires user interaction. if (isLiveMode()) { this.skip(); diff --git a/sdk/identity/identity/test/public/node/environmentCredential.spec.ts b/sdk/identity/identity/test/public/node/environmentCredential.spec.ts index 0e69e8dc9b2c..6176b9e5cdf9 100644 --- a/sdk/identity/identity/test/public/node/environmentCredential.spec.ts +++ b/sdk/identity/identity/test/public/node/environmentCredential.spec.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable no-invalid-this */ + /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ import sinon from "sinon"; @@ -14,6 +14,7 @@ import { } from "../../../src"; import { MsalTestCleanup, msalNodeTestSetup, testTracing } from "../../msalTestUtils"; import { assertRejects } from "../../authTestUtils"; +import { Context } from "mocha"; describe("EnvironmentCredential", function() { let cleanup: MsalTestCleanup; @@ -27,7 +28,7 @@ describe("EnvironmentCredential", function() { ]; const cachedValues: Record = {}; - beforeEach(function() { + beforeEach(function(this: Context) { const setup = msalNodeTestSetup(this); cleanup = setup.cleanup; environmentVariableNames.forEach((name) => { @@ -58,7 +59,7 @@ describe("EnvironmentCredential", function() { assert.ok(token?.expiresOnTimestamp! > Date.now()); }); - it("authenticates with a client certificate on the environment variables", async function() { + it("authenticates with a client certificate on the environment variables", async function(this: Context) { if (isPlaybackMode()) { // MSAL creates a client assertion based on the certificate that I haven't been able to mock. // This assertion could be provided as parameters, but we don't have that in the public API yet, @@ -136,7 +137,7 @@ describe("EnvironmentCredential", function() { }) ); - it("supports tracing with environment client certificate", async function() { + it("supports tracing with environment client certificate", async function(this: Context) { if (isPlaybackMode()) { // MSAL creates a client assertion based on the certificate that I haven't been able to mock. // This assertion could be provided as parameters, but we don't have that in the public API yet, diff --git a/sdk/identity/identity/test/public/node/usernamePasswordCredential.spec.ts b/sdk/identity/identity/test/public/node/usernamePasswordCredential.spec.ts index 3d75930340bd..975587c2440e 100644 --- a/sdk/identity/identity/test/public/node/usernamePasswordCredential.spec.ts +++ b/sdk/identity/identity/test/public/node/usernamePasswordCredential.spec.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable no-invalid-this */ + /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ import assert from "assert"; @@ -8,10 +8,11 @@ import { env, delay } from "@azure/test-utils-recorder"; import { AbortController } from "@azure/abort-controller"; import { UsernamePasswordCredential } from "../../../src"; import { MsalTestCleanup, msalNodeTestSetup, testTracing } from "../../msalTestUtils"; +import { Context } from "mocha"; describe("UsernamePasswordCredential", function() { let cleanup: MsalTestCleanup; - beforeEach(function() { + beforeEach(function(this: Context) { cleanup = msalNodeTestSetup(this).cleanup; }); afterEach(async function() { diff --git a/sdk/keyvault/keyvault-certificates/test/internal/challengeBasedAuthenticationPolicy.spec.ts b/sdk/keyvault/keyvault-certificates/test/internal/challengeBasedAuthenticationPolicy.spec.ts index 97c489b37405..ac34e8c7a686 100644 --- a/sdk/keyvault/keyvault-certificates/test/internal/challengeBasedAuthenticationPolicy.spec.ts +++ b/sdk/keyvault/keyvault-certificates/test/internal/challengeBasedAuthenticationPolicy.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { createSandbox } from "sinon"; import { env, Recorder } from "@azure/test-utils-recorder"; @@ -32,15 +33,13 @@ describe("Challenge based authentication tests", () => { subject: "cn=MyCert" }; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - certificateSuffix = authentication.suffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + certificateSuffix = authentication.suffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -48,7 +47,7 @@ describe("Challenge based authentication tests", () => { // The tests follow - it("Authentication should work for parallel requests", /** @this Mocha.Context */ async function() { + it("Authentication should work for parallel requests", async function(this: Context) { const certificateName = testClient.formatName( `${certificatePrefix}-${this!.test!.title}-${certificateSuffix}` ); @@ -86,7 +85,7 @@ describe("Challenge based authentication tests", () => { sandbox.restore(); }); - it("Once authenticated, new requests should not authenticate again", /** @this Mocha.Context */ async function() { + it("Once authenticated, new requests should not authenticate again", async function(this: Context) { // Our goal is to intercept how our pipelines are storing the challenge. // The first network call should indeed set the challenge in memory. // Subsequent network calls should not set new challenges. diff --git a/sdk/keyvault/keyvault-certificates/test/internal/userAgent.spec.ts b/sdk/keyvault/keyvault-certificates/test/internal/userAgent.spec.ts index 2949f7e2475b..bebbeca40b40 100644 --- a/sdk/keyvault/keyvault-certificates/test/internal/userAgent.spec.ts +++ b/sdk/keyvault/keyvault-certificates/test/internal/userAgent.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { SDK_VERSION } from "../../src/constants"; import { packageVersion } from "../../src/generated/keyVaultClientContext"; import { isNode } from "@azure/core-http"; @@ -13,7 +14,7 @@ describe("Certificates client's user agent (only in Node, because of fs)", () => assert.equal(SDK_VERSION, packageVersion); }); - it("the version should also match with the one available in the package.json (only in Node, because of fs)", /** @this Mocha.Context */ async function() { + it("the version should also match with the one available in the package.json (only in Node, because of fs)", async function(this: Context) { if (!isNode) { this.skip(); return; diff --git a/sdk/keyvault/keyvault-certificates/test/public/CRUD.spec.ts b/sdk/keyvault/keyvault-certificates/test/public/CRUD.spec.ts index d0431553ed36..a7f5219e4350 100644 --- a/sdk/keyvault/keyvault-certificates/test/public/CRUD.spec.ts +++ b/sdk/keyvault/keyvault-certificates/test/public/CRUD.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import os from "os"; +import { Context } from "mocha"; import fs from "fs"; import childProcess from "child_process"; import * as assert from "assert"; @@ -32,18 +33,16 @@ describe("Certificates client - create, read, update and delete", () => { subject: "cn=MyCert" }; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - suffix = authentication.suffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - keyVaultUrl = authentication.keyVaultUrl; - credential = authentication.credential; - secretClient = new SecretClient(keyVaultUrl, credential); - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + suffix = authentication.suffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + keyVaultUrl = authentication.keyVaultUrl; + credential = authentication.credential; + secretClient = new SecretClient(keyVaultUrl, credential); + }); afterEach(async function() { await recorder.stop(); @@ -51,7 +50,7 @@ describe("Certificates client - create, read, update and delete", () => { // The tests follow - it("can create a certificate", /** @this Mocha.Context */ async function() { + it("can create a certificate", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); const poller = await client.beginCreateCertificate( certificateName, @@ -67,7 +66,7 @@ describe("Certificates client - create, read, update and delete", () => { await testClient.flushCertificate(certificateName); }); - it("can abort creating a certificate", /** @this Mocha.Context */ async function() { + it("can abort creating a certificate", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); const controller = new AbortController(); @@ -82,7 +81,7 @@ describe("Certificates client - create, read, update and delete", () => { }); // On playback mode, the tests happen too fast for the timeout to work - in browsers - it("can create a certificate with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can create a certificate with requestOptions timeout", async function(this: Context) { recorder.skip("browser", "Timeout tests don't work on playback mode."); const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); @@ -116,7 +115,7 @@ describe("Certificates client - create, read, update and delete", () => { ); }); - it("can update the tags of a certificate", /** @this Mocha.Context */ async function() { + it("can update the tags of a certificate", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); await client.beginCreateCertificate( @@ -139,7 +138,7 @@ describe("Certificates client - create, read, update and delete", () => { await testClient.flushCertificate(certificateName); }); - it("can disable a certificate", /** @this Mocha.Context */ async function() { + it("can disable a certificate", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); const poller = await client.beginCreateCertificate( @@ -162,7 +161,7 @@ describe("Certificates client - create, read, update and delete", () => { await testClient.flushCertificate(certificateName); }); - it("can disable a certificate version", /** @this Mocha.Context */ async function() { + it("can disable a certificate version", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); const poller = await client.beginCreateCertificate( @@ -188,7 +187,7 @@ describe("Certificates client - create, read, update and delete", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can update certificate with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can update certificate with requestOptions timeout", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); @@ -209,7 +208,7 @@ describe("Certificates client - create, read, update and delete", () => { }); }); - it("can get a certificate", /** @this Mocha.Context */ async function() { + it("can get a certificate", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); await client.beginCreateCertificate( certificateName, @@ -225,7 +224,7 @@ describe("Certificates client - create, read, update and delete", () => { await testClient.flushCertificate(certificateName); }); - it("can get a certificate's secret in PKCS 12 format", /** @this Mocha.Context */ async function() { + it("can get a certificate's secret in PKCS 12 format", async function(this: Context) { recorder.skip("browser", "This test uses the file system."); // Skipping this test from the live browser test runs, because we use the file system. if (!isNode) { @@ -274,7 +273,7 @@ describe("Certificates client - create, read, update and delete", () => { await testClient.flushCertificate(certificateName); }); - it("can get a certificate's secret in PEM format", /** @this Mocha.Context */ async function() { + it("can get a certificate's secret in PEM format", async function(this: Context) { recorder.skip("browser", "This test uses the file system."); // Skipping this test from the live browser test runs, because we use the file system. if (!isNode) { @@ -310,7 +309,7 @@ describe("Certificates client - create, read, update and delete", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can get a certificate with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can get a certificate with requestOptions timeout", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); await client.beginCreateCertificate( @@ -323,7 +322,7 @@ describe("Certificates client - create, read, update and delete", () => { }); }); - it("can retrieve the latest version of a certificate value", /** @this Mocha.Context */ async function() { + it("can retrieve the latest version of a certificate value", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); await client.beginCreateCertificate( certificateName, @@ -341,7 +340,7 @@ describe("Certificates client - create, read, update and delete", () => { await testClient.flushCertificate(certificateName); }); - it("can get a certificate (Non Existing)", /** @this Mocha.Context */ async function() { + it("can get a certificate (Non Existing)", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); let error; try { @@ -354,7 +353,7 @@ describe("Certificates client - create, read, update and delete", () => { assert.equal(error.statusCode, 404); }); - it("can delete a certificate", /** @this Mocha.Context */ async function() { + it("can delete a certificate", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); await client.beginCreateCertificate( certificateName, @@ -384,7 +383,7 @@ describe("Certificates client - create, read, update and delete", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can delete a certificate with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can delete a certificate with requestOptions timeout", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); await client.beginCreateCertificate( @@ -402,7 +401,7 @@ describe("Certificates client - create, read, update and delete", () => { }); }); - it("can delete a certificate (Non Existing)", /** @this Mocha.Context */ async function() { + it("can delete a certificate (Non Existing)", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); let error; try { @@ -416,7 +415,7 @@ describe("Certificates client - create, read, update and delete", () => { }); describe("can get a deleted certificate", () => { - it("using beginDeleteCertificate's poller", /** @this Mocha.Context */ async function() { + it("using beginDeleteCertificate's poller", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); await client.beginCreateCertificate( certificateName, @@ -438,7 +437,7 @@ describe("Certificates client - create, read, update and delete", () => { await testClient.purgeCertificate(certificateName); }); - it("using getDeletedCertificate", /** @this Mocha.Context */ async function() { + it("using getDeletedCertificate", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); await client.beginCreateCertificate( certificateName, @@ -462,7 +461,7 @@ describe("Certificates client - create, read, update and delete", () => { await testClient.purgeCertificate(certificateName); }); - it("can not get a certificate that never existed", /** @this Mocha.Context */ async function() { + it("can not get a certificate that never existed", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); let error; try { @@ -476,7 +475,7 @@ describe("Certificates client - create, read, update and delete", () => { }); }); - it("can create, read, and delete a certificate issuer", /** @this Mocha.Context */ async function() { + it("can create, read, and delete a certificate issuer", async function(this: Context) { const issuerName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); @@ -542,7 +541,7 @@ describe("Certificates client - create, read, update and delete", () => { await testClient.flushCertificate(certificateName); }); - it("can update a certificate's policy", /** @this Mocha.Context */ async function() { + it("can update a certificate's policy", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); await client.beginCreateCertificate( @@ -564,7 +563,7 @@ describe("Certificates client - create, read, update and delete", () => { await testClient.flushCertificate(certificateName); }); - it("can read, cancel and delete a certificate's operation", /** @this Mocha.Context */ async function() { + it("can read, cancel and delete a certificate's operation", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); await client.beginCreateCertificate( certificateName, diff --git a/sdk/keyvault/keyvault-certificates/test/public/list.spec.ts b/sdk/keyvault/keyvault-certificates/test/public/list.spec.ts index 0509116495b5..b20463dbfdaa 100644 --- a/sdk/keyvault/keyvault-certificates/test/public/list.spec.ts +++ b/sdk/keyvault/keyvault-certificates/test/public/list.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import chai from "chai"; +import { Context } from "mocha"; import * as assert from "assert"; import { env, isPlaybackMode, Recorder, isRecordMode } from "@azure/test-utils-recorder"; import { isNode } from "@azure/core-http"; @@ -26,15 +27,13 @@ describe("Certificates client - list certificates in various ways", () => { subject: "cn=MyCert" }; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - suffix = authentication.suffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + suffix = authentication.suffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -45,7 +44,7 @@ describe("Certificates client - list certificates in various ways", () => { // Use this while recording to make sure the target keyvault is clean. // The next tests will produce a more consistent output. // This test is only useful while developing locally. - it("can purge all certificates", /** @this Mocha.Context */ async function(): Promise { + it("can purge all certificates", async function(this: Context): Promise { // WARNING: When TEST_MODE equals "record", all of the certificates in the indicated KEYVAULT_NAME will be deleted as part of this test. if (!isRecordMode()) { return this.skip(); @@ -68,7 +67,7 @@ describe("Certificates client - list certificates in various ways", () => { } }); - it("can list certificates", /** @this Mocha.Context */ async function() { + it("can list certificates", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); const certificateNames = [`${certificateName}0`, `${certificateName}1`]; for (const name of certificateNames) { @@ -94,7 +93,7 @@ describe("Certificates client - list certificates in various ways", () => { } }); - it("can list deleted certificates", /** @this Mocha.Context */ async function() { + it("can list deleted certificates", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); const certificateNames = [`${certificateName}0`, `${certificateName}1`]; for (const name of certificateNames) { @@ -124,7 +123,7 @@ describe("Certificates client - list certificates in various ways", () => { } }); - it("can list certificates by page", /** @this Mocha.Context */ async function() { + it("can list certificates by page", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); const certificateNames = [`${certificateName}0`, `${certificateName}1`]; for (const name of certificateNames) { @@ -161,7 +160,7 @@ describe("Certificates client - list certificates in various ways", () => { }); } - it("can list deleted certificates by page", /** @this Mocha.Context */ async function() { + it("can list deleted certificates by page", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); const certificateNames = [`${certificateName}0`, `${certificateName}1`]; for (const name of certificateNames) { @@ -200,7 +199,7 @@ describe("Certificates client - list certificates in various ways", () => { }); }); - it("can retrieve all versions of a certificate", /** @this Mocha.Context */ async function() { + it("can retrieve all versions of a certificate", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); const certificateTags = ["tag01", "tag02", "tag03"]; @@ -257,7 +256,7 @@ describe("Certificates client - list certificates in various ways", () => { }); }); - it("can list certificate versions (non existing)", /** @this Mocha.Context */ async function() { + it("can list certificate versions (non existing)", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); let totalVersions = 0; for await (const page of client.listPropertiesOfCertificateVersions(certificateName).byPage()) { diff --git a/sdk/keyvault/keyvault-certificates/test/public/lro.create.spec.ts b/sdk/keyvault/keyvault-certificates/test/public/lro.create.spec.ts index e03d00b8a8e1..c99ecafe756a 100644 --- a/sdk/keyvault/keyvault-certificates/test/public/lro.create.spec.ts +++ b/sdk/keyvault/keyvault-certificates/test/public/lro.create.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { PollerStoppedError } from "@azure/core-lro"; import { env, Recorder } from "@azure/test-utils-recorder"; @@ -17,15 +18,13 @@ describe("Certificates client - LRO - create", () => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - certificateSuffix = authentication.suffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + certificateSuffix = authentication.suffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -33,7 +32,7 @@ describe("Certificates client - LRO - create", () => { // The tests follow - it("can wait until a certificate is created", /** @this Mocha.Context */ async function() { + it("can wait until a certificate is created", async function(this: Context) { const certificateName = testClient.formatName( `${certificatePrefix}-${this!.test!.title}-${certificateSuffix}` ); @@ -57,7 +56,7 @@ describe("Certificates client - LRO - create", () => { await testClient.flushCertificate(certificateName); }); - it("can resume from a stopped poller", /** @this Mocha.Context */ async function() { + it("can resume from a stopped poller", async function(this: Context) { const certificateName = testClient.formatName( `${certificatePrefix}-${this!.test!.title}-${certificateSuffix}` ); diff --git a/sdk/keyvault/keyvault-certificates/test/public/lro.delete.spec.ts b/sdk/keyvault/keyvault-certificates/test/public/lro.delete.spec.ts index 028bb40d82d5..86ee8486ab2d 100644 --- a/sdk/keyvault/keyvault-certificates/test/public/lro.delete.spec.ts +++ b/sdk/keyvault/keyvault-certificates/test/public/lro.delete.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { PollerStoppedError } from "@azure/core-lro"; import { env, Recorder } from "@azure/test-utils-recorder"; @@ -17,15 +18,13 @@ describe("Certificates client - lro - delete", () => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - certificateSuffix = authentication.suffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + certificateSuffix = authentication.suffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -33,7 +32,7 @@ describe("Certificates client - lro - delete", () => { // The tests follow - it("can wait until a certificate is deleted", /** @this Mocha.Context */ async function() { + it("can wait until a certificate is deleted", async function(this: Context) { const certificateName = testClient.formatName( `${certificatePrefix}-${this!.test!.title}-${certificateSuffix}` ); @@ -63,7 +62,7 @@ describe("Certificates client - lro - delete", () => { await testClient.purgeCertificate(certificateName); }); - it("can resume from a stopped poller", /** @this Mocha.Context */ async function() { + it("can resume from a stopped poller", async function(this: Context) { const certificateName = testClient.formatName( `${certificatePrefix}-${this!.test!.title}-${certificateSuffix}` ); diff --git a/sdk/keyvault/keyvault-certificates/test/public/lro.operation.spec.ts b/sdk/keyvault/keyvault-certificates/test/public/lro.operation.spec.ts index afbdfd974767..40e48eb81c32 100644 --- a/sdk/keyvault/keyvault-certificates/test/public/lro.operation.spec.ts +++ b/sdk/keyvault/keyvault-certificates/test/public/lro.operation.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { env, Recorder } from "@azure/test-utils-recorder"; import { @@ -21,15 +22,13 @@ describe("Certificates client - LRO - certificate operation", () => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - certificateSuffix = authentication.suffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + certificateSuffix = authentication.suffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -37,7 +36,7 @@ describe("Certificates client - LRO - certificate operation", () => { // The tests follow - it("can wait until a certificate is created by getting the poller from getCertificateOperation", /** @this Mocha.Context */ async function() { + it("can wait until a certificate is created by getting the poller from getCertificateOperation", async function(this: Context) { const certificateName = testClient.formatName( `${certificatePrefix}-${this!.test!.title}-${certificateSuffix}` ); @@ -66,7 +65,7 @@ describe("Certificates client - LRO - certificate operation", () => { await testClient.flushCertificate(certificateName); }); - it("can resume from a stopped poller", /** @this Mocha.Context */ async function() { + it("can resume from a stopped poller", async function(this: Context) { const certificateName = testClient.formatName( `${certificatePrefix}-${this!.test!.title}-${certificateSuffix}` ); diff --git a/sdk/keyvault/keyvault-certificates/test/public/lro.recover.spec.ts b/sdk/keyvault/keyvault-certificates/test/public/lro.recover.spec.ts index 1dbf31eb4cd3..b2b4318bf124 100644 --- a/sdk/keyvault/keyvault-certificates/test/public/lro.recover.spec.ts +++ b/sdk/keyvault/keyvault-certificates/test/public/lro.recover.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { env, Recorder } from "@azure/test-utils-recorder"; import { PollerStoppedError } from "@azure/core-lro"; @@ -18,15 +19,13 @@ describe("Certificates client - LRO - recoverDelete", () => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - certificateSuffix = authentication.suffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + certificateSuffix = authentication.suffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -34,7 +33,7 @@ describe("Certificates client - LRO - recoverDelete", () => { // The tests follow - it("can wait until a certificate is recovered", /** @this Mocha.Context */ async function() { + it("can wait until a certificate is recovered", async function(this: Context) { const certificateName = testClient.formatName( `${certificatePrefix}-${this!.test!.title}-${certificateSuffix}` ); @@ -67,7 +66,7 @@ describe("Certificates client - LRO - recoverDelete", () => { await testClient.flushCertificate(certificateName); }); - it("can resume from a stopped poller", /** @this Mocha.Context */ async function() { + it("can resume from a stopped poller", async function(this: Context) { const certificateName = testClient.formatName( `${certificatePrefix}-${this!.test!.title}-${certificateSuffix}` ); @@ -114,7 +113,7 @@ describe("Certificates client - LRO - recoverDelete", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can recover a deleted certificate with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can recover a deleted certificate with requestOptions timeout", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const certificateName = testClient.formatName( `${certificatePrefix}-${this!.test!.title}-${certificateSuffix}` diff --git a/sdk/keyvault/keyvault-certificates/test/public/mergeAndImport.spec.ts b/sdk/keyvault/keyvault-certificates/test/public/mergeAndImport.spec.ts index 9a01a66cb025..b5f4a0edfa0a 100644 --- a/sdk/keyvault/keyvault-certificates/test/public/mergeAndImport.spec.ts +++ b/sdk/keyvault/keyvault-certificates/test/public/mergeAndImport.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import fs from "fs"; +import { Context } from "mocha"; import childProcess from "child_process"; import { isNode } from "@azure/core-http"; import { env, Recorder } from "@azure/test-utils-recorder"; @@ -24,18 +25,16 @@ describe("Certificates client - merge and import certificates", () => { let credential: ClientSecretCredential; let secretClient: SecretClient; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - suffix = authentication.suffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - keyVaultUrl = authentication.keyVaultUrl; - credential = authentication.credential; - secretClient = new SecretClient(keyVaultUrl, credential); - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + suffix = authentication.suffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + keyVaultUrl = authentication.keyVaultUrl; + credential = authentication.credential; + secretClient = new SecretClient(keyVaultUrl, credential); + }); afterEach(async function() { await recorder.stop(); @@ -43,7 +42,7 @@ describe("Certificates client - merge and import certificates", () => { // The tests follow - it("can import a certificate from a certificate's non base64 secret value", /** @this Mocha.Context */ async function() { + it("can import a certificate from a certificate's non base64 secret value", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); const certificateNames = [`${certificateName}0`, `${certificateName}1`]; const createPoller = await client.beginCreateCertificate( @@ -67,7 +66,7 @@ describe("Certificates client - merge and import certificates", () => { } }); - it("can import a certificate from a certificate's base64 secret value", /** @this Mocha.Context */ async function() { + it("can import a certificate from a certificate's base64 secret value", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); const certificateNames = [`${certificateName}0`, `${certificateName}1`]; const createPoller = await client.beginCreateCertificate( @@ -97,9 +96,7 @@ describe("Certificates client - merge and import certificates", () => { // The signed certificate will never be the same, so we can't play it back. // This test is only designed to work on NodeJS, since we use child_process to interact with openssl. - it("can merge a self signed certificate", /** @this Mocha.Context */ async function(): Promise< - void - > { + it("can merge a self signed certificate", async function(this: Context): Promise { recorder.skip( undefined, "The signed certificate will never be the same, so we can't play it back." diff --git a/sdk/keyvault/keyvault-certificates/test/public/recoverBackupRestore.spec.ts b/sdk/keyvault/keyvault-certificates/test/public/recoverBackupRestore.spec.ts index 097780726e50..3027f38d7d47 100644 --- a/sdk/keyvault/keyvault-certificates/test/public/recoverBackupRestore.spec.ts +++ b/sdk/keyvault/keyvault-certificates/test/public/recoverBackupRestore.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { env, isPlaybackMode, Recorder, isRecordMode } from "@azure/test-utils-recorder"; import { isNode } from "@azure/core-http"; @@ -23,15 +24,13 @@ describe("Certificates client - restore certificates and recover backups", () => subject: "cn=MyCert" }; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - suffix = authentication.suffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + suffix = authentication.suffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -39,7 +38,7 @@ describe("Certificates client - restore certificates and recover backups", () => // The tests follow - it("can recover a deleted certificate", /** @this Mocha.Context */ async function() { + it("can recover a deleted certificate", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); const createPoller = await client.beginCreateCertificate( certificateName, @@ -67,7 +66,7 @@ describe("Certificates client - restore certificates and recover backups", () => await testClient.flushCertificate(certificateName); }); - it("can recover a deleted certificate (non existing)", /** @this Mocha.Context */ async function() { + it("can recover a deleted certificate (non existing)", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); let error; try { @@ -83,7 +82,7 @@ describe("Certificates client - restore certificates and recover backups", () => if (isRecordMode() || isPlaybackMode()) { // This test can't run live, // since the purge operation currently can't be expected to finish anytime soon. - it("can restore a certificate", /** @this Mocha.Context */ async function() { + it("can restore a certificate", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); const createPoller = await client.beginCreateCertificate( certificateName, @@ -143,7 +142,7 @@ describe("Certificates client - restore certificates and recover backups", () => if (isNode && !isPlaybackMode()) { // On playback mode, the tests happen too fast for the timeout to work - it("can restore a key with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can restore a key with requestOptions timeout", async function(this: Context) { const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); const createPoller = await client.beginCreateCertificate( certificateName, diff --git a/sdk/keyvault/keyvault-certificates/test/utils/lro/restore/operation.ts b/sdk/keyvault/keyvault-certificates/test/utils/lro/restore/operation.ts index e9eabd39902f..fc950e86d3b8 100644 --- a/sdk/keyvault/keyvault-certificates/test/utils/lro/restore/operation.ts +++ b/sdk/keyvault/keyvault-certificates/test/utils/lro/restore/operation.ts @@ -54,7 +54,6 @@ export interface RestoreCertificateBackupPollOperation /** * Reaches to the service and updates the restore certificate's poll operation. * @param options - The optional parameters, which are an abortSignal from \@azure/abort-controller and a function that triggers the poller's onProgress function. - * @this RestoreCertificateBackupPollOperation */ async function update( this: RestoreCertificateBackupPollOperation, @@ -93,7 +92,6 @@ async function cancel(this: RestoreCertificateBackupPollOperation): Promise> 3), // Generate a symmetric key for testing - kty: "oct" - }; + jwk = { + keyOps: ["encrypt", "decrypt", "wrapKey", "unwrapKey"], + k: getKey(keySize >> 3), // Generate a symmetric key for testing + kty: "oct" + }; - cryptoClient = new CryptographyClient(jwk); - } - ); + cryptoClient = new CryptographyClient(jwk); + }); describe(`AES-CBC with PKCS padding (${keySize})`, () => { describe("local-only tests", async function() { - it("encrypts and decrypts locally", /** @this Mocha.Context */ async function() { + it("encrypts and decrypts locally", async function(this: Context) { const text = this.test!.title; const encryptResult = await cryptoClient.encrypt({ algorithm: encryptionAlgorithm, @@ -77,7 +76,7 @@ describe("AesCryptographyProvider internal tests", function() { assert.equal(uint8ArrayToString(decryptResult.result), text); }); - it("validates the key type", /** @this Mocha.Context */ async function() { + it("validates the key type", async function(this: Context) { const text = this.test!.title; jwk.kty = "RSA"; @@ -100,7 +99,7 @@ describe("AesCryptographyProvider internal tests", function() { ); }); - it("validates the key length", /** @this Mocha.Context */ async function() { + it("validates the key length", async function(this: Context) { const text = this.test!.title; jwk.k = getKey((keySize >> 3) - 1); @@ -134,29 +133,27 @@ describe("AesCryptographyProvider internal tests", function() { let keyVaultKey: KeyVaultKey; let remoteProvider: RemoteCryptographyProvider; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - recorder = authentication.recorder; - - if (!authentication.hsmClient) { - // Managed HSM is not deployed for this run due to service resource restrictions so we skip these tests. - // This is only necessary while Managed HSM is in preview. - this.skip(); - } - - client = authentication.hsmClient; - credential = authentication.credential; - testClient = new TestClient(authentication.hsmClient); - keySuffix = authentication.keySuffix; + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + recorder = authentication.recorder; + + if (!authentication.hsmClient) { + // Managed HSM is not deployed for this run due to service resource restrictions so we skip these tests. + // This is only necessary while Managed HSM is in preview. + this.skip(); } - ); + + client = authentication.hsmClient; + credential = authentication.credential; + testClient = new TestClient(authentication.hsmClient); + keySuffix = authentication.keySuffix; + }); afterEach(async function() { await recorder.stop(); }); - it("encrypts locally and decrypts remotely", /** @this Mocha.Context */ async function() { + it("encrypts locally and decrypts remotely", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this.test!.title}-${keySuffix}`); keyVaultKey = await client.importKey(keyName, jwk, {}); remoteProvider = new RemoteCryptographyProvider(keyVaultKey, credential); @@ -178,7 +175,7 @@ describe("AesCryptographyProvider internal tests", function() { await testClient.flushKey(keyName); }); - it("encrypts remotely and decrypts locally", /** @this Mocha.Context */ async function() { + it("encrypts remotely and decrypts locally", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this.test!.title}-${keySuffix}`); keyVaultKey = await client.importKey(keyName, jwk, {}); remoteProvider = new RemoteCryptographyProvider(keyVaultKey, credential); diff --git a/sdk/keyvault/keyvault-keys/test/internal/challengeBasedAuthenticationPolicy.spec.ts b/sdk/keyvault/keyvault-keys/test/internal/challengeBasedAuthenticationPolicy.spec.ts index 6adc6eef74b8..a4e719c656e1 100644 --- a/sdk/keyvault/keyvault-keys/test/internal/challengeBasedAuthenticationPolicy.spec.ts +++ b/sdk/keyvault/keyvault-keys/test/internal/challengeBasedAuthenticationPolicy.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { createSandbox } from "sinon"; import { env, Recorder } from "@azure/test-utils-recorder"; @@ -26,15 +27,13 @@ describe("Challenge based authentication tests", () => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - keySuffix = authentication.keySuffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + keySuffix = authentication.keySuffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -42,7 +41,7 @@ describe("Challenge based authentication tests", () => { // The tests follow - it("Authentication should work for parallel requests", /** @this Mocha.Context */ async function() { + it("Authentication should work for parallel requests", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const keyNames = [`${keyName}-0`, `${keyName}-1`]; @@ -73,7 +72,7 @@ describe("Challenge based authentication tests", () => { sandbox.restore(); }); - it("Once authenticated, new requests should not authenticate again", /** @this Mocha.Context */ async function() { + it("Once authenticated, new requests should not authenticate again", async function(this: Context) { // Our goal is to intercept how our pipelines are storing the challenge. // The first network call should indeed set the challenge in memory. // Subsequent network calls should not set new challenges. diff --git a/sdk/keyvault/keyvault-keys/test/internal/crypto.spec.ts b/sdk/keyvault/keyvault-keys/test/internal/crypto.spec.ts index ed0e5f4dbfbf..171972d86d10 100644 --- a/sdk/keyvault/keyvault-keys/test/internal/crypto.spec.ts +++ b/sdk/keyvault/keyvault-keys/test/internal/crypto.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { isNode, TokenCredential } from "@azure/core-http"; +import { Context } from "mocha"; import chai, { assert } from "chai"; import chaiAsPromised from "chai-as-promised"; chai.use(chaiAsPromised); @@ -135,7 +136,7 @@ describe("internal crypto tests", () => { }); describe("Encrypt parameter mapping", async function() { - it("maps parameters correctly when using the previous API", /** @this Mocha.Context */ async function() { + it("maps parameters correctly when using the previous API", async function(this: Context) { const text = stringToUint8Array(this.test!.title!); await client.encrypt("RSA1_5", text, { requestOptions: { timeout: 5 } }); @@ -146,7 +147,7 @@ describe("internal crypto tests", () => { ); }); - it("maps parameters correctly when using the current API", /** @this Mocha.Context */ async function() { + it("maps parameters correctly when using the current API", async function(this: Context) { const text = stringToUint8Array(this.test!.title!); await client.encrypt( @@ -163,7 +164,7 @@ describe("internal crypto tests", () => { }); describe("Decrypt parameter mapping", async function() { - it("maps parameters correctly when using the previous API", /** @this Mocha.Context */ async function() { + it("maps parameters correctly when using the previous API", async function(this: Context) { const text = stringToUint8Array(this.test!.title!); await client.decrypt("RSA1_5", text, { requestOptions: { timeout: 5 } }); @@ -174,7 +175,7 @@ describe("internal crypto tests", () => { ); }); - it("maps parameters correctly when using the current API", /** @this Mocha.Context */ async function() { + it("maps parameters correctly when using the current API", async function(this: Context) { const text = stringToUint8Array(this.test!.title!); await client.decrypt( @@ -192,7 +193,7 @@ describe("internal crypto tests", () => { }); describe("RSA local cryptography tests", function() { - it("throws a validation error when the key is invalid", /** @this Mocha.Context */ function() { + it("throws a validation error when the key is invalid", function(this: Context) { if (!isNode) { // Local cryptography is not supported in the browser this.skip(); @@ -204,7 +205,7 @@ describe("internal crypto tests", () => { ); }); - it("uses the browser replacement when running in the browser", /** @this Mocha.Context */ function() { + it("uses the browser replacement when running in the browser", function(this: Context) { if (isNode) { this.skip(); } diff --git a/sdk/keyvault/keyvault-keys/test/internal/userAgent.spec.ts b/sdk/keyvault/keyvault-keys/test/internal/userAgent.spec.ts index 13ea672ba6fe..948928d1595e 100644 --- a/sdk/keyvault/keyvault-keys/test/internal/userAgent.spec.ts +++ b/sdk/keyvault/keyvault-keys/test/internal/userAgent.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { SDK_VERSION } from "../../src/constants"; import { packageVersion } from "../../src/generated/keyVaultClientContext"; import { isNode } from "@azure/core-http"; @@ -13,7 +14,7 @@ describe("Keys client's user agent (only in Node, because of fs)", () => { assert.equal(SDK_VERSION, packageVersion); }); - it("the version should also match with the one available in the package.json (only in Node, because of fs)", /** @this Mocha.Context */ async function() { + it("the version should also match with the one available in the package.json (only in Node, because of fs)", async function(this: Context) { if (!isNode) { this.skip(); return; diff --git a/sdk/keyvault/keyvault-keys/test/public/CRUD.hsm.spec.ts b/sdk/keyvault/keyvault-keys/test/public/CRUD.hsm.spec.ts index 5f09ae91ab6f..03db8c9611d9 100644 --- a/sdk/keyvault/keyvault-keys/test/public/CRUD.hsm.spec.ts +++ b/sdk/keyvault/keyvault-keys/test/public/CRUD.hsm.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert } from "chai"; +import { Context } from "mocha"; import { env, Recorder } from "@azure/test-utils-recorder"; import { KeyClient } from "../../src"; @@ -16,28 +17,26 @@ describe("Keys client - create, read, update and delete operations for managed H let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - recorder = authentication.recorder; + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + recorder = authentication.recorder; - if (!authentication.hsmClient) { - // Managed HSM is not deployed for this run due to service resource restrictions so we skip these tests. - // This is only necessary while Managed HSM is in preview. - this.skip(); - } - - hsmClient = authentication.hsmClient; - keySuffix = authentication.keySuffix; - testClient = new TestClient(authentication.hsmClient); + if (!authentication.hsmClient) { + // Managed HSM is not deployed for this run due to service resource restrictions so we skip these tests. + // This is only necessary while Managed HSM is in preview. + this.skip(); } - ); + + hsmClient = authentication.hsmClient; + keySuffix = authentication.keySuffix; + testClient = new TestClient(authentication.hsmClient); + }); afterEach(async function() { await recorder.stop(); }); - it("can create an OCT key with options", /** @this Mocha.Context */ async function() { + it("can create an OCT key with options", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const options: CreateOctKeyOptions = { hsm: true diff --git a/sdk/keyvault/keyvault-keys/test/public/CRUD.spec.ts b/sdk/keyvault/keyvault-keys/test/public/CRUD.spec.ts index 6afa8e5bd20e..7cbc106ade21 100644 --- a/sdk/keyvault/keyvault-keys/test/public/CRUD.spec.ts +++ b/sdk/keyvault/keyvault-keys/test/public/CRUD.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert } from "chai"; +import { Context } from "mocha"; import { RestError } from "@azure/core-http"; import { AbortController } from "@azure/abort-controller"; import { env, Recorder } from "@azure/test-utils-recorder"; @@ -24,15 +25,13 @@ describe("Keys client - create, read, update and delete operations", () => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - keySuffix = authentication.keySuffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + keySuffix = authentication.keySuffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -40,7 +39,7 @@ describe("Keys client - create, read, update and delete operations", () => { // The tests follow - it("can create a key while giving a manual type", /** @this Mocha.Context */ async function() { + it("can create a key while giving a manual type", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const result = await client.createKey(keyName, "RSA"); assert.equal(result.name, keyName, "Unexpected key name in result from createKey()."); @@ -48,7 +47,7 @@ describe("Keys client - create, read, update and delete operations", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can abort creating a key", /** @this Mocha.Context */ async function() { + it("can abort creating a key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const controller = new AbortController(); @@ -62,7 +61,7 @@ describe("Keys client - create, read, update and delete operations", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can create a key with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can create a key with requestOptions timeout", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await assertThrowsAbortError(async () => { @@ -90,14 +89,14 @@ describe("Keys client - create, read, update and delete operations", () => { ); }); - it("can create a RSA key", /** @this Mocha.Context */ async function() { + it("can create a RSA key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const result = await client.createRsaKey(keyName); assert.equal(result.name, keyName, "Unexpected key name in result from createKey()."); await testClient.flushKey(keyName); }); - it("can create a RSA key with size", /** @this Mocha.Context */ async function() { + it("can create a RSA key with size", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const options = { keySize: 2048 @@ -107,7 +106,7 @@ describe("Keys client - create, read, update and delete operations", () => { await testClient.flushKey(keyName); }); - it("can create a RSA key with public exponent", /** @this Mocha.Context */ async function() { + it("can create a RSA key with public exponent", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const options = { publicExponent: 3 @@ -118,7 +117,7 @@ describe("Keys client - create, read, update and delete operations", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can create a RSA key with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can create a RSA key with requestOptions timeout", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); @@ -131,14 +130,14 @@ describe("Keys client - create, read, update and delete operations", () => { }); }); - it("can create an EC key", /** @this Mocha.Context */ async function() { + it("can create an EC key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const result = await client.createEcKey(keyName); assert.equal(result.name, keyName, "Unexpected key name in result from createKey()."); await testClient.flushKey(keyName); }); - it("can create an EC key with curve", /** @this Mocha.Context */ async function() { + it("can create an EC key with curve", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const options: CreateEcKeyOptions = { curve: "P-256" @@ -149,7 +148,7 @@ describe("Keys client - create, read, update and delete operations", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can create an EC key with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can create an EC key with requestOptions timeout", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await assertThrowsAbortError(async () => { @@ -161,7 +160,7 @@ describe("Keys client - create, read, update and delete operations", () => { }); }); - it("can create a disabled key", /** @this Mocha.Context */ async function() { + it("can create a disabled key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const options = { enabled: false @@ -171,7 +170,7 @@ describe("Keys client - create, read, update and delete operations", () => { await testClient.flushKey(keyName); }); - it("can create a key with notBefore", /** @this Mocha.Context */ async function() { + it("can create a key with notBefore", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const date = new Date("2019-01-01"); const notBefore = new Date(date.getTime() + 5000); // 5 seconds later @@ -189,7 +188,7 @@ describe("Keys client - create, read, update and delete operations", () => { await testClient.flushKey(keyName); }); - it("can create a key with expires", /** @this Mocha.Context */ async function() { + it("can create a key with expires", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const date = new Date("2019-01-01"); const expiresOn = new Date(date.getTime() + 5000); // 5 seconds later @@ -207,7 +206,7 @@ describe("Keys client - create, read, update and delete operations", () => { await testClient.flushKey(keyName); }); - it("can update key", /** @this Mocha.Context */ async function() { + it("can update key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const { version } = (await client.createRsaKey(keyName)).properties; const options: UpdateKeyPropertiesOptions = { enabled: false }; @@ -216,7 +215,7 @@ describe("Keys client - create, read, update and delete operations", () => { await testClient.flushKey(keyName); }); - it("can update a disabled key", /** @this Mocha.Context */ async function() { + it("can update a disabled key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const createOptions = { enabled: false @@ -235,7 +234,7 @@ describe("Keys client - create, read, update and delete operations", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can update key with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can update key with requestOptions timeout", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const { version } = (await client.createRsaKey(keyName)).properties; @@ -248,7 +247,7 @@ describe("Keys client - create, read, update and delete operations", () => { }); }); - it("can delete a key", /** @this Mocha.Context */ async function() { + it("can delete a key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); const poller = await client.beginDeleteKey(keyName, testPollerProperties); @@ -269,7 +268,7 @@ describe("Keys client - create, read, update and delete operations", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can delete a key with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can delete a key with requestOptions timeout", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); @@ -283,7 +282,7 @@ describe("Keys client - create, read, update and delete operations", () => { }); }); - it("delete nonexisting key", /** @this Mocha.Context */ async function() { + it("delete nonexisting key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); try { await client.getKey(keyName); @@ -298,7 +297,7 @@ describe("Keys client - create, read, update and delete operations", () => { } }); - it("can get a key", /** @this Mocha.Context */ async function() { + it("can get a key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); const getResult = await client.getKey(keyName); @@ -307,7 +306,7 @@ describe("Keys client - create, read, update and delete operations", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can get a key with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can get a key with requestOptions timeout", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); @@ -316,7 +315,7 @@ describe("Keys client - create, read, update and delete operations", () => { }); }); - it("can get a specific version of a key", /** @this Mocha.Context */ async function() { + it("can get a specific version of a key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const { version } = (await client.createKey(keyName, "RSA")).properties; const options: GetKeyOptions = { version }; @@ -329,7 +328,7 @@ describe("Keys client - create, read, update and delete operations", () => { await testClient.flushKey(keyName); }); - it("can get a deleted key", /** @this Mocha.Context */ async function() { + it("can get a deleted key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); const poller = await client.beginDeleteKey(keyName, testPollerProperties); @@ -350,7 +349,7 @@ describe("Keys client - create, read, update and delete operations", () => { await testClient.purgeKey(keyName); }); - it("can't get a deleted key that doesn't exist", /** @this Mocha.Context */ async function() { + it("can't get a deleted key that doesn't exist", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); let error; try { @@ -364,7 +363,7 @@ describe("Keys client - create, read, update and delete operations", () => { assert.equal(error.statusCode, 404); }); - it("can purge a deleted key", /** @this Mocha.Context */ async function() { + it("can purge a deleted key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); const poller = await client.beginDeleteKey(keyName, testPollerProperties); diff --git a/sdk/keyvault/keyvault-keys/test/public/crypto.hsm.spec.ts b/sdk/keyvault/keyvault-keys/test/public/crypto.hsm.spec.ts index 7dc9798bae9a..6ec8cf94efd1 100644 --- a/sdk/keyvault/keyvault-keys/test/public/crypto.hsm.spec.ts +++ b/sdk/keyvault/keyvault-keys/test/public/crypto.hsm.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert } from "chai"; +import { Context } from "mocha"; import { Recorder } from "@azure/test-utils-recorder"; import { ClientSecretCredential } from "@azure/identity"; @@ -20,24 +21,22 @@ describe("CryptographyClient for managed HSM (skipped if MHSM is not deployed)", let keyVaultKey: KeyVaultKey; let keySuffix: string; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - recorder = authentication.recorder; + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + recorder = authentication.recorder; - if (!authentication.hsmClient) { - // Managed HSM is not deployed for this run due to service resource restrictions so we skip these tests. - // This is only necessary while Managed HSM is in preview. - this.skip(); - } - - hsmClient = authentication.hsmClient; - testClient = new TestClient(authentication.hsmClient); - credential = authentication.credential; - keySuffix = authentication.keySuffix; - keyName = testClient.formatName("cryptography-client-test" + keySuffix); + if (!authentication.hsmClient) { + // Managed HSM is not deployed for this run due to service resource restrictions so we skip these tests. + // This is only necessary while Managed HSM is in preview. + this.skip(); } - ); + + hsmClient = authentication.hsmClient; + testClient = new TestClient(authentication.hsmClient); + credential = authentication.credential; + keySuffix = authentication.keySuffix; + keyName = testClient.formatName("cryptography-client-test" + keySuffix); + }); afterEach(async function() { await testClient?.flushKey(keyName); @@ -45,7 +44,7 @@ describe("CryptographyClient for managed HSM (skipped if MHSM is not deployed)", }); describe("with AES crypto algorithms", async function() { - it("encrypts and decrypts using AES-GCM", /** @this Mocha.Context */ async function() { + it("encrypts and decrypts using AES-GCM", async function(this: Context) { keyVaultKey = await hsmClient.createKey(keyName, "AES", { keySize: 256 }); cryptoClient = new CryptographyClient(keyVaultKey.id!, credential); const text = this.test!.title; @@ -65,7 +64,7 @@ describe("CryptographyClient for managed HSM (skipped if MHSM is not deployed)", assert.equal(text, uint8ArrayToString(decryptResult.result)); }); - it("encrypts and decrypts using AES-CBC", /** @this Mocha.Context */ async function() { + it("encrypts and decrypts using AES-CBC", async function(this: Context) { keyVaultKey = await hsmClient.createKey(keyName, "AES", { keySize: 256 }); cryptoClient = new CryptographyClient(keyVaultKey.id!, credential); const text = this.test!.title; diff --git a/sdk/keyvault/keyvault-keys/test/public/crypto.spec.ts b/sdk/keyvault/keyvault-keys/test/public/crypto.spec.ts index d7938fa66152..b7f440cf7015 100644 --- a/sdk/keyvault/keyvault-keys/test/public/crypto.spec.ts +++ b/sdk/keyvault/keyvault-keys/test/public/crypto.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert } from "chai"; +import { Context } from "mocha"; import { createHash } from "crypto"; import { Recorder, env, isPlaybackMode } from "@azure/test-utils-recorder"; import { ClientSecretCredential } from "@azure/identity"; @@ -29,33 +30,29 @@ describe("CryptographyClient (all decrypts happen remotely)", () => { return; } - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - client = authentication.client; - recorder = authentication.recorder; - testClient = authentication.testClient; - credential = authentication.credential; - keySuffix = authentication.keySuffix; - keyName = testClient.formatName("cryptography-client-test" + keySuffix); - keyVaultKey = await client.createKey(keyName, "RSA"); - cryptoClient = new CryptographyClient(keyVaultKey.id!, credential); - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + client = authentication.client; + recorder = authentication.recorder; + testClient = authentication.testClient; + credential = authentication.credential; + keySuffix = authentication.keySuffix; + keyName = testClient.formatName("cryptography-client-test" + keySuffix); + keyVaultKey = await client.createKey(keyName, "RSA"); + cryptoClient = new CryptographyClient(keyVaultKey.id!, credential); + }); - afterEach( - /** @this Mocha.Context */ async function() { - if (!this.currentTest?.isPending()) { - await testClient.flushKey(keyName); - } - await recorder.stop(); + afterEach(async function(this: Context) { + if (!this.currentTest?.isPending()) { + await testClient.flushKey(keyName); } - ); + await recorder.stop(); + }); // The tests follow if (!isPlaybackMode()) { - it("encrypt & decrypt with RSA1_5", /** @this Mocha.Context */ async function() { + it("encrypt & decrypt with RSA1_5", async function(this: Context) { const text = this.test!.title; const encryptResult = await cryptoClient.encrypt({ algorithm: "RSA1_5", @@ -69,7 +66,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => { assert.equal(text, decryptedText); }); - it("manually encrypt locally and decrypt remotely, both with RSA1_5", /** @this Mocha.Context */ async function() { + it("manually encrypt locally and decrypt remotely, both with RSA1_5", async function(this: Context) { const text = this.test!.title; const localProvider = new RsaCryptographyProvider(keyVaultKey.key!); const encryptResult = await localProvider.encrypt({ @@ -84,7 +81,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => { assert.equal(text, decryptedText); }); - it("encrypt & decrypt with RSA-OAEP", /** @this Mocha.Context */ async function() { + it("encrypt & decrypt with RSA-OAEP", async function(this: Context) { const text = this.test!.title; const encryptResult = await cryptoClient.encrypt( { @@ -101,7 +98,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => { assert.equal(text, decryptedText); }); - it("manually encrypt locally and decrypt remotely, both with RSA-OAEP", /** @this Mocha.Context */ async function() { + it("manually encrypt locally and decrypt remotely, both with RSA-OAEP", async function(this: Context) { const text = this.test!.title; const localProvider = new RsaCryptographyProvider(keyVaultKey.key!); const encryptResult = await localProvider.encrypt({ @@ -116,7 +113,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => { assert.equal(text, decryptedText); }); - it("the CryptographyClient can be created from a full KeyVaultKey object", /** @this Mocha.Context */ async function() { + it("the CryptographyClient can be created from a full KeyVaultKey object", async function(this: Context) { const customKeyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const customKeyVaultKey = await client.createKey(customKeyName, "RSA"); const cryptoClientFromKey = new CryptographyClient(customKeyVaultKey, credential); @@ -166,7 +163,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => { assert.equal("RSA1_5", unwrappedResult.algorithm); }); - it("wrap and unwrap with RSA-OAEP", /** @this Mocha.Context */ async function() { + it("wrap and unwrap with RSA-OAEP", async function(this: Context) { recorder.skip( undefined, "Wrapping and unwrapping don't cause a repeatable pattern, so these tests can only run in playback mode" @@ -180,7 +177,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => { }); if (!isPlaybackMode()) { - it("encrypt & decrypt with an RSA-HSM key and the RSA-OAEP algorithm", /** @this Mocha.Context */ async function() { + it("encrypt & decrypt with an RSA-HSM key and the RSA-OAEP algorithm", async function(this: Context) { const hsmKeyName = keyName + "2"; const hsmKey = await client.createKey(hsmKeyName, "RSA-HSM"); const hsmCryptoClient = new CryptographyClient(hsmKey.id!, credential); @@ -192,7 +189,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => { await testClient.flushKey(hsmKeyName); }); - it("encrypt & decrypt with an RSA-HSM key and the RSA1_5 algorithm", /** @this Mocha.Context */ async function() { + it("encrypt & decrypt with an RSA-HSM key and the RSA1_5 algorithm", async function(this: Context) { const hsmKeyName = keyName + "2"; const hsmKey = await client.createKey(hsmKeyName, "RSA-HSM"); const hsmCryptoClient = new CryptographyClient(hsmKey.id!, credential); @@ -205,7 +202,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => { }); } - it("wrap and unwrap with RSA-OAEP on a RSA-HSM key", /** @this Mocha.Context */ async function() { + it("wrap and unwrap with RSA-OAEP on a RSA-HSM key", async function(this: Context) { recorder.skip( undefined, "Wrapping and unwrapping don't cause a repeatable pattern, so this test can only run live" @@ -221,7 +218,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => { await testClient.flushKey(hsmKeyName); }); - it("wrap and unwrap with RSA1_5 on a RSA-HSM key", /** @this Mocha.Context */ async function() { + it("wrap and unwrap with RSA1_5 on a RSA-HSM key", async function(this: Context) { recorder.skip( undefined, "Wrapping and unwrapping don't cause a repeatable pattern, so this test can only run live" @@ -237,7 +234,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => { await testClient.flushKey(hsmKeyName); }); - it("sign and verify with RS256 through an RSA-HSM key", /** @this Mocha.Context */ async function(): Promise< + it("sign and verify with RS256 through an RSA-HSM key", async function(this: Context): Promise< void > { const hsmKeyName = keyName + "2"; @@ -270,7 +267,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => { await testClient.flushKey(hsmKeyName); }); - it("sign and verify with RS384 through an RSA-HSM key", /** @this Mocha.Context */ async function(): Promise< + it("sign and verify with RS384 through an RSA-HSM key", async function(this: Context): Promise< void > { const hsmKeyName = keyName + "2"; diff --git a/sdk/keyvault/keyvault-keys/test/public/import.spec.ts b/sdk/keyvault/keyvault-keys/test/public/import.spec.ts index 73dc9c9aef3e..defc3834bca5 100644 --- a/sdk/keyvault/keyvault-keys/test/public/import.spec.ts +++ b/sdk/keyvault/keyvault-keys/test/public/import.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { env, Recorder } from "@azure/test-utils-recorder"; import { isNode } from "@azure/core-http"; @@ -16,15 +17,13 @@ describe("Keys client - import keys", () => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - suffix = authentication.keySuffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + suffix = authentication.keySuffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -32,7 +31,7 @@ describe("Keys client - import keys", () => { // The tests follow - it("can import a key", /** @this Mocha.Context */ async function() { + it("can import a key", async function(this: Context) { const keyName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`); function toBytes(hex: string): Uint8Array { if (hex.length % 2) { diff --git a/sdk/keyvault/keyvault-keys/test/public/list.spec.ts b/sdk/keyvault/keyvault-keys/test/public/list.spec.ts index b69f177d6253..bf64e3bd397b 100644 --- a/sdk/keyvault/keyvault-keys/test/public/list.spec.ts +++ b/sdk/keyvault/keyvault-keys/test/public/list.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { env, Recorder, isRecordMode } from "@azure/test-utils-recorder"; import { KeyClient } from "../../src"; @@ -20,15 +21,13 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this, serviceVersion); - keySuffix = authentication.keySuffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this, serviceVersion); + keySuffix = authentication.keySuffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -39,7 +38,7 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => { // Use this while recording to make sure the target keyvault is clean. // The next tests will produce a more consistent output. // This test is only useful while developing locally. - it("can purge all keys", /** @this Mocha.Context */ async function(): Promise { + it("can purge all keys", async function(this: Context): Promise { // WARNING: When TEST_MODE equals "record", all of the keys in the indicated KEYVAULT_URI will be deleted as part of this test. if (!isRecordMode()) { return this.skip(); @@ -60,7 +59,7 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => { } }); - it("can get the versions of a key", /** @this Mocha.Context */ async function() { + it("can get the versions of a key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); let totalVersions = 0; @@ -87,7 +86,7 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => { }); }); - it("can get the versions of a key (paged)", /** @this Mocha.Context */ async function() { + it("can get the versions of a key (paged)", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); let totalVersions = 0; @@ -105,7 +104,7 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => { await testClient.flushKey(keyName); }); - it("list 0 versions of a non-existing key", /** @this Mocha.Context */ async function() { + it("list 0 versions of a non-existing key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); let totalVersions = 0; for await (const version of client.listPropertiesOfKeyVersions(keyName)) { @@ -119,7 +118,7 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => { assert.equal(totalVersions, 0, `Unexpected total versions for key ${keyName}`); }); - it("list 0 versions of a non-existing key (paged)", /** @this Mocha.Context */ async function() { + it("list 0 versions of a non-existing key (paged)", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); let totalVersions = 0; for await (const page of client.listPropertiesOfKeyVersions(keyName).byPage()) { @@ -135,7 +134,7 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => { assert.equal(totalVersions, 0, `Unexpected total versions for key ${keyName}`); }); - it("can get several inserted keys", /** @this Mocha.Context */ async function() { + it("can get several inserted keys", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const keyNames = [`${keyName}-0`, `${keyName}-1`]; for (const name of keyNames) { @@ -166,7 +165,7 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => { }); }); - it("can get several inserted keys (paged)", /** @this Mocha.Context */ async function() { + it("can get several inserted keys (paged)", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const keyNames = [`${keyName}-0`, `${keyName}-1`]; for (const name of keyNames) { @@ -189,7 +188,7 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => { } }); - it("list deleted keys", /** @this Mocha.Context */ async function() { + it("list deleted keys", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const keyNames = [`${keyName}-0`, `${keyName}-1`]; for (const name of keyNames) { @@ -223,7 +222,7 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => { }); }); - it("list deleted keys (paged)", /** @this Mocha.Context */ async function() { + it("list deleted keys (paged)", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const keyNames = [`${keyName}-0`, `${keyName}-1`]; for (const name of keyNames) { diff --git a/sdk/keyvault/keyvault-keys/test/public/localCryptography.spec.ts b/sdk/keyvault/keyvault-keys/test/public/localCryptography.spec.ts index 6b877d10cfaa..22441c3a033d 100644 --- a/sdk/keyvault/keyvault-keys/test/public/localCryptography.spec.ts +++ b/sdk/keyvault/keyvault-keys/test/public/localCryptography.spec.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. +import { Context } from "mocha"; import { LocalSupportedAlgorithmName, KeyClient, @@ -33,16 +34,14 @@ describe("Local cryptography public tests", () => { return; } - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - client = authentication.client; - recorder = authentication.recorder; - testClient = authentication.testClient; - credential = authentication.credential; - keySuffix = authentication.keySuffix; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + client = authentication.client; + recorder = authentication.recorder; + testClient = authentication.testClient; + credential = authentication.credential; + keySuffix = authentication.keySuffix; + }); afterEach(async function() { await recorder.stop(); @@ -53,13 +52,11 @@ describe("Local cryptography public tests", () => { let customKeyVaultKey: KeyVaultKey; let cryptoClientFromKey: CryptographyClient; - beforeEach( - /** @this Mocha.Context */ async function() { - customKeyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); - customKeyVaultKey = await client.createKey(customKeyName, "RSA"); - cryptoClientFromKey = new CryptographyClient(customKeyVaultKey.key!); - } - ); + beforeEach(async function(this: Context) { + customKeyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); + customKeyVaultKey = await client.createKey(customKeyName, "RSA"); + cryptoClientFromKey = new CryptographyClient(customKeyVaultKey.key!); + }); it("the CryptographyClient can be created from a local JsonWebKey object", async function() { assert.isEmpty(cryptoClientFromKey.vaultUrl); @@ -127,7 +124,7 @@ describe("Local cryptography public tests", () => { }); }); - it("encrypt & decrypt RSA1_5", /** @this Mocha.Context */ async function() { + it("encrypt & decrypt RSA1_5", async function(this: Context) { recorder.skip(undefined, "Local encryption can't be tested on playback"); const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const keyVaultKey = await client.createKey(keyName, "RSA"); @@ -141,7 +138,7 @@ describe("Local cryptography public tests", () => { await testClient.flushKey(keyName); }); - it("encrypt & decrypt RSA-OAEP", /** @this Mocha.Context */ async function() { + it("encrypt & decrypt RSA-OAEP", async function(this: Context) { recorder.skip(undefined, "Local encryption can't be tested on playback"); const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const keyVaultKey = await client.createKey(keyName, "RSA"); @@ -155,7 +152,7 @@ describe("Local cryptography public tests", () => { await testClient.flushKey(keyName); }); - it("wrapKey & unwrapKey RSA1_5", /** @this Mocha.Context */ async function() { + it("wrapKey & unwrapKey RSA1_5", async function(this: Context) { recorder.skip(undefined, "Local encryption can't be tested on playback"); const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const keyVaultKey = await client.createKey(keyName, "RSA"); @@ -172,7 +169,7 @@ describe("Local cryptography public tests", () => { await testClient.flushKey(keyName); }); - it("wrapKey & unwrapKey RSA-OAEP", /** @this Mocha.Context */ async function() { + it("wrapKey & unwrapKey RSA-OAEP", async function(this: Context) { recorder.skip(undefined, "Local encryption can't be tested on playback"); const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); const keyVaultKey = await client.createKey(keyName, "RSA"); @@ -194,43 +191,35 @@ describe("Local cryptography public tests", () => { const localSupportedAlgorithmNames = Object.keys(rsaProvider.signatureAlgorithmToHashAlgorithm); for (const localAlgorithmName of localSupportedAlgorithmNames) { - it( - localAlgorithmName, - /** @this Mocha.Context */ async function(): Promise { - recorder.skip( - "browser", - `Local sign of algorithm ${localAlgorithmName} is only supported in NodeJS` - ); - - const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); - const keyVaultKey = await client.createKey(keyName, "RSA"); - const cryptoClient = new CryptographyClient(keyVaultKey.id!, credential); - - // Sign is not implemented yet. - // This boils down to the JWK to PEM conversion, which doesn't support private keys at the moment. - const signatureValue = this.test!.title; - const hash = createHash( - rsaProvider.signatureAlgorithmToHashAlgorithm[localAlgorithmName] - ); - hash.update(signatureValue); - const digest = hash.digest(); - const signature = await cryptoClient.sign( - localAlgorithmName as SignatureAlgorithm, - digest - ); - - // Local Cryptography Client part - const localCryptoClient = new CryptographyClient(keyVaultKey.key!); - const verifyResult = await localCryptoClient.verifyData( - localAlgorithmName as LocalSupportedAlgorithmName, - digest, - signature.result - ); - assert.ok(verifyResult); - - await testClient.flushKey(keyName); - } - ); + it(localAlgorithmName, async function(this: Context): Promise { + recorder.skip( + "browser", + `Local sign of algorithm ${localAlgorithmName} is only supported in NodeJS` + ); + + const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); + const keyVaultKey = await client.createKey(keyName, "RSA"); + const cryptoClient = new CryptographyClient(keyVaultKey.id!, credential); + + // Sign is not implemented yet. + // This boils down to the JWK to PEM conversion, which doesn't support private keys at the moment. + const signatureValue = this.test!.title; + const hash = createHash(rsaProvider.signatureAlgorithmToHashAlgorithm[localAlgorithmName]); + hash.update(signatureValue); + const digest = hash.digest(); + const signature = await cryptoClient.sign(localAlgorithmName as SignatureAlgorithm, digest); + + // Local Cryptography Client part + const localCryptoClient = new CryptographyClient(keyVaultKey.key!); + const verifyResult = await localCryptoClient.verifyData( + localAlgorithmName as LocalSupportedAlgorithmName, + digest, + signature.result + ); + assert.ok(verifyResult); + + await testClient.flushKey(keyName); + }); } }); }); diff --git a/sdk/keyvault/keyvault-keys/test/public/lro.delete.spec.ts b/sdk/keyvault/keyvault-keys/test/public/lro.delete.spec.ts index 7184d8dbaa2f..36d871b3f9f8 100644 --- a/sdk/keyvault/keyvault-keys/test/public/lro.delete.spec.ts +++ b/sdk/keyvault/keyvault-keys/test/public/lro.delete.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { env, Recorder } from "@azure/test-utils-recorder"; import { PollerStoppedError } from "@azure/core-lro"; @@ -17,15 +18,13 @@ describe("Keys client - Long Running Operations - delete", () => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - keySuffix = authentication.keySuffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + keySuffix = authentication.keySuffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -33,7 +32,7 @@ describe("Keys client - Long Running Operations - delete", () => { // The tests follow - it("can wait until a key is deleted", /** @this Mocha.Context */ async function() { + it("can wait until a key is deleted", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); const poller = await client.beginDeleteKey(keyName, testPollerProperties); @@ -52,7 +51,7 @@ describe("Keys client - Long Running Operations - delete", () => { await testClient.purgeKey(keyName); }); - it("can resume from a stopped poller", /** @this Mocha.Context */ async function() { + it("can resume from a stopped poller", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); const poller = await client.beginDeleteKey(keyName, testPollerProperties); diff --git a/sdk/keyvault/keyvault-keys/test/public/lro.recoverDelete.spec.ts b/sdk/keyvault/keyvault-keys/test/public/lro.recoverDelete.spec.ts index ac8769138cfd..0ead1035675d 100644 --- a/sdk/keyvault/keyvault-keys/test/public/lro.recoverDelete.spec.ts +++ b/sdk/keyvault/keyvault-keys/test/public/lro.recoverDelete.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { env, Recorder } from "@azure/test-utils-recorder"; import { PollerStoppedError } from "@azure/core-lro"; @@ -18,15 +19,13 @@ describe("Keys client - Long Running Operations - recoverDelete", () => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - keySuffix = authentication.keySuffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + keySuffix = authentication.keySuffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -34,7 +33,7 @@ describe("Keys client - Long Running Operations - recoverDelete", () => { // The tests follow - it("can wait until a key is recovered", /** @this Mocha.Context */ async function() { + it("can wait until a key is recovered", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); @@ -57,7 +56,7 @@ describe("Keys client - Long Running Operations - recoverDelete", () => { await testClient.flushKey(keyName); }); - it("can resume from a stopped poller", /** @this Mocha.Context */ async function() { + it("can resume from a stopped poller", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); const deletePoller = await client.beginDeleteKey(keyName, testPollerProperties); @@ -94,7 +93,7 @@ describe("Keys client - Long Running Operations - recoverDelete", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can recover a deleted key with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can recover a deleted key with requestOptions timeout", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); diff --git a/sdk/keyvault/keyvault-keys/test/public/recoverBackupRestore.spec.ts b/sdk/keyvault/keyvault-keys/test/public/recoverBackupRestore.spec.ts index 14cfaba62c4f..26335c50221e 100644 --- a/sdk/keyvault/keyvault-keys/test/public/recoverBackupRestore.spec.ts +++ b/sdk/keyvault/keyvault-keys/test/public/recoverBackupRestore.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { isNode } from "@azure/core-http"; import { KeyClient } from "../../src"; import { assertThrowsAbortError } from "../utils/utils.common"; @@ -17,15 +18,13 @@ describe("Keys client - restore keys and recover backups", () => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - keySuffix = authentication.keySuffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + keySuffix = authentication.keySuffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -33,7 +32,7 @@ describe("Keys client - restore keys and recover backups", () => { // The tests follow - it("can recover a deleted key", /** @this Mocha.Context */ async function() { + it("can recover a deleted key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); const deletePoller = await client.beginDeleteKey(keyName, testPollerProperties); @@ -54,7 +53,7 @@ describe("Keys client - restore keys and recover backups", () => { await testClient.flushKey(keyName); }); - it("fails if one tries to recover a non-existing deleted key", /** @this Mocha.Context */ async function() { + it("fails if one tries to recover a non-existing deleted key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); let error; try { @@ -68,7 +67,7 @@ describe("Keys client - restore keys and recover backups", () => { assert.equal(error.statusCode, 404); }); - it("can generate a backup of a key", /** @this Mocha.Context */ async function() { + it("can generate a backup of a key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); const result = await client.backupKey(keyName); @@ -89,7 +88,7 @@ describe("Keys client - restore keys and recover backups", () => { }); }); - it("fails to generate a backup of a non-existing key", /** @this Mocha.Context */ async function() { + it("fails to generate a backup of a non-existing key", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); let error; try { @@ -105,7 +104,7 @@ describe("Keys client - restore keys and recover backups", () => { if (isRecordMode() || isPlaybackMode()) { // This test can't run live, // since the purge operation currently can't be expected to finish anytime soon. - it("can restore a key with a given backup", /** @this Mocha.Context */ async function() { + it("can restore a key with a given backup", async function(this: Context) { const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); const backup = await client.backupKey(keyName); @@ -128,7 +127,7 @@ describe("Keys client - restore keys and recover backups", () => { } // On playback mode, the tests happen too fast for the timeout to work - it("can restore a key with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can restore a key with requestOptions timeout", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); await client.createKey(keyName, "RSA"); diff --git a/sdk/keyvault/keyvault-keys/test/utils/lro/restore/operation.ts b/sdk/keyvault/keyvault-keys/test/utils/lro/restore/operation.ts index 84c4cf59cb2b..1e91f24e96c5 100644 --- a/sdk/keyvault/keyvault-keys/test/utils/lro/restore/operation.ts +++ b/sdk/keyvault/keyvault-keys/test/utils/lro/restore/operation.ts @@ -53,7 +53,6 @@ export interface RestoreKeyBackupPollOperation /** * Reaches to the service and updates the restore key's poll operation. * @param options - The optional parameters, which are an abortSignal from \@azure/abort-controller and a function that triggers the poller's onProgress function. - * @this RestoreKeyBackupPollOperation */ async function update( this: RestoreKeyBackupPollOperation, @@ -92,7 +91,6 @@ async function cancel(this: RestoreKeyBackupPollOperation): Promise { /** * Serializes the create key's poll operation - * @this RestoreKeyBackupPollOperation */ function toString(this: RestoreKeyBackupPollOperation): string { return JSON.stringify({ diff --git a/sdk/keyvault/keyvault-secrets/test/internal/challengeBasedAuthenticationPolicy.spec.ts b/sdk/keyvault/keyvault-secrets/test/internal/challengeBasedAuthenticationPolicy.spec.ts index 5c3c9adddbb2..d3ad551a0c28 100644 --- a/sdk/keyvault/keyvault-secrets/test/internal/challengeBasedAuthenticationPolicy.spec.ts +++ b/sdk/keyvault/keyvault-secrets/test/internal/challengeBasedAuthenticationPolicy.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { env, Recorder } from "@azure/test-utils-recorder"; import { createSandbox } from "sinon"; @@ -26,15 +27,13 @@ describe("Challenge based authentication tests", () => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - secretSuffix = authentication.secretSuffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + secretSuffix = authentication.secretSuffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -42,7 +41,7 @@ describe("Challenge based authentication tests", () => { // The tests follow - it("Authentication should work for parallel requests", /** @this Mocha.Context */ async function() { + it("Authentication should work for parallel requests", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -75,7 +74,7 @@ describe("Challenge based authentication tests", () => { sandbox.restore(); }); - it("Once authenticated, new requests should not authenticate again", /** @this Mocha.Context */ async function() { + it("Once authenticated, new requests should not authenticate again", async function(this: Context) { // Our goal is to intercept how our pipelines are storing the challenge. // The first network call should indeed set the challenge in memory. // Subsequent network calls should not set new challenges. diff --git a/sdk/keyvault/keyvault-secrets/test/internal/userAgent.spec.ts b/sdk/keyvault/keyvault-secrets/test/internal/userAgent.spec.ts index a2f06913dcc9..97b67914b13a 100644 --- a/sdk/keyvault/keyvault-secrets/test/internal/userAgent.spec.ts +++ b/sdk/keyvault/keyvault-secrets/test/internal/userAgent.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { SDK_VERSION } from "../../src/constants"; import { packageVersion } from "../../src/generated/keyVaultClientContext"; import { isNode } from "@azure/core-http"; @@ -13,7 +14,7 @@ describe("Secrets client's user agent (only in Node, because of fs)", () => { assert.equal(SDK_VERSION, packageVersion); }); - it("the version should also match with the one available in the package.json (only in Node, because of fs)", /** @this Mocha.Context */ async function() { + it("the version should also match with the one available in the package.json (only in Node, because of fs)", async function(this: Context) { if (!isNode) { this.skip(); return; diff --git a/sdk/keyvault/keyvault-secrets/test/public/CRUD.spec.ts b/sdk/keyvault/keyvault-secrets/test/public/CRUD.spec.ts index 4192da3fc7c8..5047d5fc17e7 100644 --- a/sdk/keyvault/keyvault-secrets/test/public/CRUD.spec.ts +++ b/sdk/keyvault/keyvault-secrets/test/public/CRUD.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { env, Recorder } from "@azure/test-utils-recorder"; import { AbortController } from "@azure/abort-controller"; @@ -19,15 +20,13 @@ describe("Secret client - create, read, update and delete operations", () => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - secretSuffix = authentication.secretSuffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + secretSuffix = authentication.secretSuffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -35,7 +34,7 @@ describe("Secret client - create, read, update and delete operations", () => { // The tests follow - it("can add a secret", /** @this Mocha.Context */ async function() { + it("can add a secret", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -47,7 +46,7 @@ describe("Secret client - create, read, update and delete operations", () => { // If this test is not skipped in the browser's playback, no other test will be played back. // This is a bug related to the browser features of the recorder. - it("can abort adding a secret", /** @this Mocha.Context */ async function() { + it("can abort adding a secret", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -61,7 +60,7 @@ describe("Secret client - create, read, update and delete operations", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can timeout adding a secret", /** @this Mocha.Context */ async function() { + it("can timeout adding a secret", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` @@ -91,7 +90,7 @@ describe("Secret client - create, read, update and delete operations", () => { ); }); - it("can set a secret with Empty Value", /** @this Mocha.Context */ async function() { + it("can set a secret with Empty Value", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -106,7 +105,7 @@ describe("Secret client - create, read, update and delete operations", () => { await testClient.flushSecret(secretName); }); - it("can set a secret with attributes", /** @this Mocha.Context */ async function() { + it("can set a secret with attributes", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -122,7 +121,7 @@ describe("Secret client - create, read, update and delete operations", () => { await testClient.flushSecret(secretName); }); - it("can update a secret", /** @this Mocha.Context */ async function() { + it("can update a secret", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -144,7 +143,7 @@ describe("Secret client - create, read, update and delete operations", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can timeout updating a secret", /** @this Mocha.Context */ async function() { + it("can timeout updating a secret", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` @@ -163,7 +162,7 @@ describe("Secret client - create, read, update and delete operations", () => { }); }); - it("can update a disabled secret", /** @this Mocha.Context */ async function() { + it("can update a disabled secret", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -184,7 +183,7 @@ describe("Secret client - create, read, update and delete operations", () => { await testClient.flushSecret(secretName); }); - it("can get a secret", /** @this Mocha.Context */ async function() { + it("can get a secret", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -196,7 +195,7 @@ describe("Secret client - create, read, update and delete operations", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can timeout getting a secret", /** @this Mocha.Context */ async function() { + it("can timeout getting a secret", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` @@ -211,7 +210,7 @@ describe("Secret client - create, read, update and delete operations", () => { }); }); - it("can't get a disabled secret", /** @this Mocha.Context */ async function() { + it("can't get a disabled secret", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -236,7 +235,7 @@ describe("Secret client - create, read, update and delete operations", () => { await testClient.flushSecret(secretName); }); - it("can retrieve the latest version of a secret value", /** @this Mocha.Context */ async function() { + it("can retrieve the latest version of a secret value", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -249,7 +248,7 @@ describe("Secret client - create, read, update and delete operations", () => { await testClient.flushSecret(secretName); }); - it("can get a secret (Non Existing)", /** @this Mocha.Context */ async function() { + it("can get a secret (Non Existing)", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -264,7 +263,7 @@ describe("Secret client - create, read, update and delete operations", () => { assert.equal(error.statusCode, 404); }); - it("can delete a secret", /** @this Mocha.Context */ async function() { + it("can delete a secret", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -303,7 +302,7 @@ describe("Secret client - create, read, update and delete operations", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can timeout deleting a secret", /** @this Mocha.Context */ async function() { + it("can timeout deleting a secret", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` @@ -319,7 +318,7 @@ describe("Secret client - create, read, update and delete operations", () => { }); }); - it("can delete a secret (Non Existing)", /** @this Mocha.Context */ async function() { + it("can delete a secret (Non Existing)", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -334,7 +333,7 @@ describe("Secret client - create, read, update and delete operations", () => { assert.equal(error.statusCode, 404); }); - it("can get a deleted secret", /** @this Mocha.Context */ async function() { + it("can get a deleted secret", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -361,7 +360,7 @@ describe("Secret client - create, read, update and delete operations", () => { await testClient.purgeSecret(secretName); }); - it("can get a deleted secret (Non Existing)", /** @this Mocha.Context */ async function() { + it("can get a deleted secret (Non Existing)", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); diff --git a/sdk/keyvault/keyvault-secrets/test/public/list.spec.ts b/sdk/keyvault/keyvault-secrets/test/public/list.spec.ts index a32c8c0bf77c..2cf1c91e6a07 100644 --- a/sdk/keyvault/keyvault-secrets/test/public/list.spec.ts +++ b/sdk/keyvault/keyvault-secrets/test/public/list.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import chai from "chai"; import { env, Recorder, isRecordMode } from "@azure/test-utils-recorder"; @@ -21,15 +22,13 @@ describe("Secret client - list secrets in various ways", () => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - secretSuffix = authentication.secretSuffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + secretSuffix = authentication.secretSuffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -40,7 +39,7 @@ describe("Secret client - list secrets in various ways", () => { // Use this while recording to make sure the target keyvault is clean. // The next tests will produce a more consistent output. // This test is only useful while developing locally. - it("can purge all secrets", /** @this Mocha.Context */ async function(): Promise { + it("can purge all secrets", async function(this: Context): Promise { // WARNING: When TEST_MODE equals "record", all of the secrets in the indicated KEYVAULT_URI will be deleted as part of this test. if (!isRecordMode()) { return this.skip(); @@ -61,7 +60,7 @@ describe("Secret client - list secrets in various ways", () => { } }); - it("can list secret properties", /** @this Mocha.Context */ async function() { + it("can list secret properties", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -85,7 +84,7 @@ describe("Secret client - list secrets in various ways", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can get secret properties with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can get secret properties with requestOptions timeout", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const iter = client.listPropertiesOfSecrets({ requestOptions: { timeout: 1 } @@ -95,7 +94,7 @@ describe("Secret client - list secrets in various ways", () => { }); }); - it("can list deleted secrets", /** @this Mocha.Context */ async function() { + it("can list deleted secrets", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -134,7 +133,7 @@ describe("Secret client - list secrets in various ways", () => { }); }); - it("can retrieve all versions of a secret", /** @this Mocha.Context */ async function() { + it("can retrieve all versions of a secret", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` @@ -177,7 +176,7 @@ describe("Secret client - list secrets in various ways", () => { }); }); - it("can list secret versions (non existing)", /** @this Mocha.Context */ async function() { + it("can list secret versions (non existing)", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -193,7 +192,7 @@ describe("Secret client - list secrets in various ways", () => { assert.equal(totalVersions, 0, `Unexpected total versions for secret ${secretName}`); }); - it("can list secrets by page", /** @this Mocha.Context */ async function() { + it("can list secrets by page", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -215,7 +214,7 @@ describe("Secret client - list secrets in various ways", () => { } }); - it("can list deleted secrets by page", /** @this Mocha.Context */ async function() { + it("can list deleted secrets by page", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -242,7 +241,7 @@ describe("Secret client - list secrets in various ways", () => { } }); - it("can retrieve all versions of a secret by page", /** @this Mocha.Context */ async function() { + it("can retrieve all versions of a secret by page", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -275,7 +274,7 @@ describe("Secret client - list secrets in various ways", () => { await testClient.flushSecret(secretName); }); - it("can list secret versions by page (non existing)", /** @this Mocha.Context */ async function() { + it("can list secret versions by page (non existing)", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); diff --git a/sdk/keyvault/keyvault-secrets/test/public/lro.delete.spec.ts b/sdk/keyvault/keyvault-secrets/test/public/lro.delete.spec.ts index 60e83731f084..359ffa0d3bb0 100644 --- a/sdk/keyvault/keyvault-secrets/test/public/lro.delete.spec.ts +++ b/sdk/keyvault/keyvault-secrets/test/public/lro.delete.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { env, Recorder } from "@azure/test-utils-recorder"; import { PollerStoppedError } from "@azure/core-lro"; @@ -18,15 +19,13 @@ describe("Secrets client - Long Running Operations - delete", () => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - secretSuffix = authentication.secretSuffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + secretSuffix = authentication.secretSuffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -34,7 +33,7 @@ describe("Secrets client - Long Running Operations - delete", () => { // The tests follow - it("can wait until a secret is deleted", /** @this Mocha.Context */ async function() { + it("can wait until a secret is deleted", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -55,7 +54,7 @@ describe("Secrets client - Long Running Operations - delete", () => { await testClient.purgeSecret(secretName); }); - it("can resume from a stopped poller", /** @this Mocha.Context */ async function() { + it("can resume from a stopped poller", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -89,7 +88,7 @@ describe("Secrets client - Long Running Operations - delete", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can attempt to delete a secret with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can attempt to delete a secret with requestOptions timeout", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` diff --git a/sdk/keyvault/keyvault-secrets/test/public/lro.recover.spec.ts b/sdk/keyvault/keyvault-secrets/test/public/lro.recover.spec.ts index f26b4bb5b09f..377fd367dd11 100644 --- a/sdk/keyvault/keyvault-secrets/test/public/lro.recover.spec.ts +++ b/sdk/keyvault/keyvault-secrets/test/public/lro.recover.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { env, Recorder } from "@azure/test-utils-recorder"; import { PollerStoppedError } from "@azure/core-lro"; @@ -18,15 +19,13 @@ describe("Secrets client - Long Running Operations - recoverDelete", () => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - secretSuffix = authentication.secretSuffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + secretSuffix = authentication.secretSuffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -34,7 +33,7 @@ describe("Secrets client - Long Running Operations - recoverDelete", () => { // The tests follow - it("can wait until a secret is recovered", /** @this Mocha.Context */ async function() { + it("can wait until a secret is recovered", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -59,7 +58,7 @@ describe("Secrets client - Long Running Operations - recoverDelete", () => { await testClient.flushSecret(secretName); }); - it("can resume from a stopped poller", /** @this Mocha.Context */ async function() { + it("can resume from a stopped poller", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -98,7 +97,7 @@ describe("Secrets client - Long Running Operations - recoverDelete", () => { }); // On playback mode, the tests happen too fast for the timeout to work - it("can attempt to recover a deleted secret with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can attempt to recover a deleted secret with requestOptions timeout", async function(this: Context) { recorder.skip(undefined, "Timeout tests don't work on playback mode."); const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` diff --git a/sdk/keyvault/keyvault-secrets/test/public/recoverBackupRestore.spec.ts b/sdk/keyvault/keyvault-secrets/test/public/recoverBackupRestore.spec.ts index 84dc3f97a77d..3c644ff91e32 100644 --- a/sdk/keyvault/keyvault-secrets/test/public/recoverBackupRestore.spec.ts +++ b/sdk/keyvault/keyvault-secrets/test/public/recoverBackupRestore.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import * as assert from "assert"; +import { Context } from "mocha"; import { isNode } from "@azure/core-http"; import { env, isPlaybackMode, Recorder, isRecordMode } from "@azure/test-utils-recorder"; @@ -18,15 +19,13 @@ describe("Secret client - restore secrets and recover backups", () => { let testClient: TestClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ async function() { - const authentication = await authenticate(this); - secretSuffix = authentication.secretSuffix; - client = authentication.client; - testClient = authentication.testClient; - recorder = authentication.recorder; - } - ); + beforeEach(async function(this: Context) { + const authentication = await authenticate(this); + secretSuffix = authentication.secretSuffix; + client = authentication.client; + testClient = authentication.testClient; + recorder = authentication.recorder; + }); afterEach(async function() { await recorder.stop(); @@ -34,7 +33,7 @@ describe("Secret client - restore secrets and recover backups", () => { // The tests follow - it("can recover a deleted secret", /** @this Mocha.Context */ async function() { + it("can recover a deleted secret", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -64,7 +63,7 @@ describe("Secret client - restore secrets and recover backups", () => { await testClient.flushSecret(secretName); }); - it("can recover a deleted secret (non existing)", /** @this Mocha.Context */ async function() { + it("can recover a deleted secret (non existing)", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -85,7 +84,7 @@ describe("Secret client - restore secrets and recover backups", () => { if (isNode && !isPlaybackMode()) { // On playback mode, the tests happen too fast for the timeout to work - it("can recover a deleted a secret with requestOptions timeout", /** @this Mocha.Context */ async function() { + it("can recover a deleted a secret with requestOptions timeout", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -103,7 +102,7 @@ describe("Secret client - restore secrets and recover backups", () => { }); } - it("can backup a secret", /** @this Mocha.Context */ async function() { + it("can backup a secret", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -121,7 +120,7 @@ describe("Secret client - restore secrets and recover backups", () => { await testClient.flushSecret(secretName); }); - it("can backup a secret (non existing)", /** @this Mocha.Context */ async function() { + it("can backup a secret (non existing)", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -139,7 +138,7 @@ describe("Secret client - restore secrets and recover backups", () => { if (isRecordMode() || isPlaybackMode()) { // This test can't run live, // since the purge operation currently can't be expected to finish anytime soon. - it("can restore a secret", /** @this Mocha.Context */ async function() { + it("can restore a secret", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); @@ -184,7 +183,7 @@ describe("Secret client - restore secrets and recover backups", () => { if (isNode && !isPlaybackMode()) { // On playback mode, the tests happen too fast for the timeout to work - it("can timeout deleting a secret", /** @this Mocha.Context */ async function() { + it("can timeout deleting a secret", async function(this: Context) { const secretName = testClient.formatName( `${secretPrefix}-${this!.test!.title}-${secretSuffix}` ); diff --git a/sdk/keyvault/keyvault-secrets/test/utils/lro/restore/operation.ts b/sdk/keyvault/keyvault-secrets/test/utils/lro/restore/operation.ts index be58e9a61eee..4d141cbdf33b 100644 --- a/sdk/keyvault/keyvault-secrets/test/utils/lro/restore/operation.ts +++ b/sdk/keyvault/keyvault-secrets/test/utils/lro/restore/operation.ts @@ -54,7 +54,6 @@ export interface RestoreSecretBackupPollOperation /** * Reaches to the service and updates the restore secret's poll operation. * @param options - The optional parameters, which are an abortSignal from \@azure/abort-controller and a function that triggers the poller's onProgress function. - * @this RestoreSecretBackupPollOperation */ async function update( this: RestoreSecretBackupPollOperation, @@ -93,7 +92,6 @@ async function cancel(this: RestoreSecretBackupPollOperation): Promise { /** * Serializes the create secret's poll operation - * @this RestoreSecretBackupPollOperation */ function toString(this: RestoreSecretBackupPollOperation): string { return JSON.stringify({ diff --git a/sdk/metricsadvisor/ai-metrics-advisor/test/public/adminclient.spec.ts b/sdk/metricsadvisor/ai-metrics-advisor/test/public/adminclient.spec.ts index ba12db6b72d3..6f104b8d1180 100644 --- a/sdk/metricsadvisor/ai-metrics-advisor/test/public/adminclient.spec.ts +++ b/sdk/metricsadvisor/ai-metrics-advisor/test/public/adminclient.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert } from "chai"; +import { Context } from "mocha"; import { AnomalyAlertConfiguration, @@ -19,11 +20,9 @@ matrix([[true, false]] as const, async (useAad) => { let client: MetricsAdvisorAdministrationClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ function() { - ({ recorder, client } = createRecordedAdminClient(this, makeCredential(useAad))); - } - ); + beforeEach(function(this: Context) { + ({ recorder, client } = createRecordedAdminClient(this, makeCredential(useAad))); + }); afterEach(async function() { if (recorder) { @@ -79,7 +78,7 @@ matrix([[true, false]] as const, async (useAad) => { assert.ok(result.latestActiveTimestamp, "Expecting valid latest active timestamp"); }); - it("refreshes ingesetion status", /** @this Mocha.Context */ async function() { + it("refreshes ingesetion status", async function(this: Context) { const iterator = client.listDataFeedIngestionStatus( testEnv.METRICS_ADVISOR_AZURE_SQLSERVER_DATAFEED_ID, new Date(Date.UTC(2020, 7, 22)), @@ -368,7 +367,7 @@ matrix([[true, false]] as const, async (useAad) => { } }); - it("deletes an alert configuration", /** @this Mocha.Context */ async function() { + it("deletes an alert configuration", async function(this: Context) { if (!createdAlertConfigId) { this.skip(); } @@ -382,7 +381,7 @@ matrix([[true, false]] as const, async (useAad) => { } }); - it("deletes a detection configuration", /** @this Mocha.Context */ async function() { + it("deletes a detection configuration", async function(this: Context) { if (!createdDetectionConfigId) { this.skip(); } diff --git a/sdk/metricsadvisor/ai-metrics-advisor/test/public/advisorclient.spec.ts b/sdk/metricsadvisor/ai-metrics-advisor/test/public/advisorclient.spec.ts index b434c2325203..e3709294c2a5 100644 --- a/sdk/metricsadvisor/ai-metrics-advisor/test/public/advisorclient.spec.ts +++ b/sdk/metricsadvisor/ai-metrics-advisor/test/public/advisorclient.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert } from "chai"; +import { Context } from "mocha"; import { MetricAnomalyFeedback, @@ -20,11 +21,9 @@ matrix([[true, false]] as const, async (useAad) => { let client: MetricsAdvisorClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ function() { - ({ recorder, client } = createRecordedAdvisorClient(this, makeCredential(useAad))); - } - ); + beforeEach(function(this: Context) { + ({ recorder, client } = createRecordedAdvisorClient(this, makeCredential(useAad))); + }); afterEach(async function() { if (recorder) { diff --git a/sdk/metricsadvisor/ai-metrics-advisor/test/public/datafeed.spec.ts b/sdk/metricsadvisor/ai-metrics-advisor/test/public/datafeed.spec.ts index 7fc3b4a41450..84990484709d 100644 --- a/sdk/metricsadvisor/ai-metrics-advisor/test/public/datafeed.spec.ts +++ b/sdk/metricsadvisor/ai-metrics-advisor/test/public/datafeed.spec.ts @@ -2,7 +2,7 @@ // Licensed under the MIT license. import { assert } from "chai"; - +import { Context } from "mocha"; import { DataFeedGranularity, DataFeedIngestionSettings, @@ -36,8 +36,7 @@ matrix([[true, false]] as const, async (useAad) => { let mySqlFeedName: string; let postgreSqlFeedName: string; - beforeEach(function() { - // eslint-disable-next-line no-invalid-this + beforeEach(function(this: Context) { ({ recorder, client } = createRecordedAdminClient(this, makeCredential(useAad))); if (recorder && !feedName) { feedName = recorder.getUniqueName("js-test-datafeed-"); @@ -233,7 +232,7 @@ matrix([[true, false]] as const, async (useAad) => { } }); - it("retrieves an Azure Blob datafeed", async function() { + it("retrieves an Azure Blob datafeed", async function(this: Context) { // accessing environment variables here so they are already replaced by test env ones const expectedSource: DataFeedSource = { dataSourceType: "AzureBlob", @@ -245,7 +244,6 @@ matrix([[true, false]] as const, async (useAad) => { }; if (!createdAzureBlobDataFeedId) { - // eslint-disable-next-line no-invalid-this this.skip(); } @@ -273,9 +271,8 @@ matrix([[true, false]] as const, async (useAad) => { ); }); - it("updates an Azure Blob datafeed", async function() { + it("updates an Azure Blob datafeed", async function(this: Context) { if (!createdAzureBlobDataFeedId) { - // eslint-disable-next-line no-invalid-this this.skip(); } const expectedSourceParameter = { @@ -816,7 +813,6 @@ export async function verifyDataFeedDeletion( createdDataFeedId: string ): Promise { if (!createdDataFeedId) { - // eslint-disable-next-line no-invalid-this this.skip(); } diff --git a/sdk/metricsadvisor/ai-metrics-advisor/test/public/hookTests.spec.ts b/sdk/metricsadvisor/ai-metrics-advisor/test/public/hookTests.spec.ts index 4c4bb60d3ea2..1381ad72a96f 100644 --- a/sdk/metricsadvisor/ai-metrics-advisor/test/public/hookTests.spec.ts +++ b/sdk/metricsadvisor/ai-metrics-advisor/test/public/hookTests.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert } from "chai"; +import { Context } from "mocha"; import { MetricsAdvisorAdministrationClient, @@ -24,17 +25,15 @@ matrix([[true, false]] as const, async (useAad) => { let emailHookName: string; let webHookName: string; - beforeEach( - /** @this Mocha.Context */ function() { - ({ recorder, client } = createRecordedAdminClient(this, makeCredential(useAad))); - if (recorder && !emailHookName) { - emailHookName = recorder.getUniqueName("js-test-emailHook-"); - } - if (recorder && !webHookName) { - webHookName = recorder.getUniqueName("js-test-webHook-"); - } + beforeEach(function(this: Context) { + ({ recorder, client } = createRecordedAdminClient(this, makeCredential(useAad))); + if (recorder && !emailHookName) { + emailHookName = recorder.getUniqueName("js-test-emailHook-"); } - ); + if (recorder && !webHookName) { + webHookName = recorder.getUniqueName("js-test-webHook-"); + } + }); afterEach(async function() { if (recorder) { diff --git a/sdk/mixedreality/mixedreality-authentication/test/mixedRealityStsClient.spec.ts b/sdk/mixedreality/mixedreality-authentication/test/mixedRealityStsClient.spec.ts index 9652fb026c82..4a54642ba3f6 100644 --- a/sdk/mixedreality/mixedreality-authentication/test/mixedRealityStsClient.spec.ts +++ b/sdk/mixedreality/mixedreality-authentication/test/mixedRealityStsClient.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert } from "chai"; +import { Context } from "mocha"; import { AzureKeyCredential, MixedRealityStsClient } from "../src"; import { createTokenCredentialFromMRKeyCredential } from "./utils/tokenCredentialHelper"; import { Recorder } from "@azure/test-utils-recorder"; @@ -77,12 +78,10 @@ describe("[AccountKey] MixedRealityStsClient functional tests", function() { let client: MixedRealityStsClient; let recorder: Recorder; - beforeEach( - /** @this Mocha.Context */ function() { - recorder = createRecorder(this); - client = createClient(); - } - ); + beforeEach(function(this: Context) { + recorder = createRecorder(this); + client = createClient(); + }); afterEach(async function() { // Stop the recording. diff --git a/sdk/schemaregistry/schema-registry/test/schemaRegistry.spec.ts b/sdk/schemaregistry/schema-registry/test/schemaRegistry.spec.ts index 77718fccaefb..b604818a94ef 100644 --- a/sdk/schemaregistry/schema-registry/test/schemaRegistry.spec.ts +++ b/sdk/schemaregistry/schema-registry/test/schemaRegistry.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { createRecordedClient, testEnv } from "./utils/recordedClient"; +import { Context } from "mocha"; import { Recorder } from "@azure/test-utils-recorder"; import { assert, use as chaiUse } from "chai"; import chaiPromises from "chai-as-promised"; @@ -62,11 +63,9 @@ describe("SchemaRegistryClient", function() { let recorder: Recorder; let client: SchemaRegistryClient; - beforeEach( - /** @this Mocha.Context */ function() { - ({ client, recorder } = createRecordedClient(this)); - } - ); + beforeEach(function(this: Context) { + ({ client, recorder } = createRecordedClient(this)); + }); afterEach(async function() { await recorder.stop(); diff --git a/sdk/search/search-documents/test/public/node/searchClient.spec.ts b/sdk/search/search-documents/test/public/node/searchClient.spec.ts index ba1d47853bb4..bf74936f4aae 100644 --- a/sdk/search/search-documents/test/public/node/searchClient.spec.ts +++ b/sdk/search/search-documents/test/public/node/searchClient.spec.ts @@ -2,6 +2,8 @@ // Licensed under the MIT license. import { assert } from "chai"; +import { Context } from "mocha"; +import { Suite } from "mocha"; import { Recorder, record, isPlaybackMode, isLiveMode } from "@azure/test-utils-recorder"; @@ -18,26 +20,24 @@ import { delay } from "@azure/core-http"; const TEST_INDEX_NAME = isLiveMode() ? createRandomIndexName() : "hotel-live-test1"; -describe("SearchClient", /** @this Mocha.Context */ function() { +describe("SearchClient", function(this: Suite) { let recorder: Recorder; let searchClient: SearchClient; let indexClient: SearchIndexClient; this.timeout(99999); - beforeEach( - /** @this Mocha.Context */ async function() { - ({ searchClient, indexClient } = createClients(TEST_INDEX_NAME)); - if (!isPlaybackMode()) { - await createIndex(indexClient, TEST_INDEX_NAME); - await delay(WAIT_TIME); - await populateIndex(searchClient); - } - recorder = record(this, environmentSetup); - // create the clients again, but hooked up to the recorder - ({ searchClient, indexClient } = createClients(TEST_INDEX_NAME)); + beforeEach(async function(this: Context) { + ({ searchClient, indexClient } = createClients(TEST_INDEX_NAME)); + if (!isPlaybackMode()) { + await createIndex(indexClient, TEST_INDEX_NAME); + await delay(WAIT_TIME); + await populateIndex(searchClient); } - ); + recorder = record(this, environmentSetup); + // create the clients again, but hooked up to the recorder + ({ searchClient, indexClient } = createClients(TEST_INDEX_NAME)); + }); afterEach(async function() { if (recorder) { diff --git a/sdk/search/search-documents/test/public/node/searchIndexClient.spec.ts b/sdk/search/search-documents/test/public/node/searchIndexClient.spec.ts index 6884e9d1fa0d..51469a6db9d7 100644 --- a/sdk/search/search-documents/test/public/node/searchIndexClient.spec.ts +++ b/sdk/search/search-documents/test/public/node/searchIndexClient.spec.ts @@ -2,6 +2,8 @@ // Licensed under the MIT license. import { isPlaybackMode, record, Recorder, isLiveMode } from "@azure/test-utils-recorder"; +import { Context } from "mocha"; +import { Suite } from "mocha"; import { assert } from "chai"; import { SearchIndexClient, SynonymMap, SearchIndex } from "../../../src"; import { Hotel } from "../utils/interfaces"; @@ -17,25 +19,23 @@ import { delay } from "@azure/core-http"; const TEST_INDEX_NAME = isLiveMode() ? createRandomIndexName() : "hotel-live-test3"; -describe("SearchIndexClient", /** @this Mocha.Context */ function() { +describe("SearchIndexClient", function(this: Suite) { let recorder: Recorder; let indexClient: SearchIndexClient; this.timeout(99999); - beforeEach( - /** @this Mocha.Context */ async function() { - ({ indexClient } = createClients(TEST_INDEX_NAME)); - if (!isPlaybackMode()) { - await createSynonymMaps(indexClient); - await createSimpleIndex(indexClient, TEST_INDEX_NAME); - await delay(WAIT_TIME); - } - recorder = record(this, environmentSetup); - // create the clients again, but hooked up to the recorder - ({ indexClient } = createClients(TEST_INDEX_NAME)); + beforeEach(async function(this: Context) { + ({ indexClient } = createClients(TEST_INDEX_NAME)); + if (!isPlaybackMode()) { + await createSynonymMaps(indexClient); + await createSimpleIndex(indexClient, TEST_INDEX_NAME); + await delay(WAIT_TIME); } - ); + recorder = record(this, environmentSetup); + // create the clients again, but hooked up to the recorder + ({ indexClient } = createClients(TEST_INDEX_NAME)); + }); afterEach(async function() { if (recorder) { diff --git a/sdk/search/search-documents/test/public/node/searchIndexerClient.spec.ts b/sdk/search/search-documents/test/public/node/searchIndexerClient.spec.ts index 1a644a5362dd..43ed66a4f67e 100644 --- a/sdk/search/search-documents/test/public/node/searchIndexerClient.spec.ts +++ b/sdk/search/search-documents/test/public/node/searchIndexerClient.spec.ts @@ -2,6 +2,8 @@ // Licensed under the MIT license. import { isPlaybackMode, record, Recorder, isLiveMode } from "@azure/test-utils-recorder"; +import { Context } from "mocha"; +import { Suite } from "mocha"; import { assert } from "chai"; import { SearchIndexClient, @@ -25,27 +27,25 @@ import { delay } from "@azure/core-http"; const TEST_INDEX_NAME = isLiveMode() ? createRandomIndexName() : "hotel-live-test2"; -describe("SearchIndexerClient", /** @this Mocha.Context */ function() { +describe("SearchIndexerClient", function(this: Suite) { let recorder: Recorder; let indexerClient: SearchIndexerClient; let indexClient: SearchIndexClient; this.timeout(99999); - beforeEach( - /** @this Mocha.Context */ async function() { - ({ indexClient, indexerClient } = createClients(TEST_INDEX_NAME)); - if (!isPlaybackMode()) { - await createSkillsets(indexerClient); - await createIndex(indexClient, TEST_INDEX_NAME); - await delay(5000); - await createIndexers(indexerClient, TEST_INDEX_NAME); - } - recorder = record(this, environmentSetup); - // create the clients again, but hooked up to the recorder - ({ indexClient, indexerClient } = createClients(TEST_INDEX_NAME)); + beforeEach(async function(this: Context) { + ({ indexClient, indexerClient } = createClients(TEST_INDEX_NAME)); + if (!isPlaybackMode()) { + await createSkillsets(indexerClient); + await createIndex(indexClient, TEST_INDEX_NAME); + await delay(5000); + await createIndexers(indexerClient, TEST_INDEX_NAME); } - ); + recorder = record(this, environmentSetup); + // create the clients again, but hooked up to the recorder + ({ indexClient, indexerClient } = createClients(TEST_INDEX_NAME)); + }); afterEach(async function() { if (recorder) { diff --git a/sdk/tables/data-tables/test/integration/batch.spec.ts b/sdk/tables/data-tables/test/integration/batch.spec.ts index 0d6375845baf..8434478c4797 100644 --- a/sdk/tables/data-tables/test/integration/batch.spec.ts +++ b/sdk/tables/data-tables/test/integration/batch.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { TableClient, odata } from "../../src"; +import { Context } from "mocha"; import { assert } from "chai"; import { record, Recorder, isPlaybackMode, isLiveMode } from "@azure/test-utils-recorder"; import { recordedEnvironmentSetup, createTableClient } from "./utils/recordedClient"; @@ -26,21 +27,19 @@ describe("batch operations", () => { // which wouldn't match the recorded one. Fallingback to SAS for recorded tests. const authMode = !isNode || !isLiveMode() ? "SASConnectionString" : "AccountConnectionString"; - beforeEach( - /** @this Mocha.Context */ async function() { - sinon.stub(Uuid, "generateUuid").returns("fakeId"); - recorder = record(this, recordedEnvironmentSetup); - client = createTableClient(tableName, authMode); - - try { - if (!isPlaybackMode()) { - await client.create(); - } - } catch { - console.warn("Table already exists"); + beforeEach(async function(this: Context) { + sinon.stub(Uuid, "generateUuid").returns("fakeId"); + recorder = record(this, recordedEnvironmentSetup); + client = createTableClient(tableName, authMode); + + try { + if (!isPlaybackMode()) { + await client.create(); } + } catch { + console.warn("Table already exists"); } - ); + }); afterEach(async function() { sinon.restore(); diff --git a/sdk/tables/data-tables/test/integration/tableclient.spec.ts b/sdk/tables/data-tables/test/integration/tableclient.spec.ts index 2505d6f5645e..3c70989b34e1 100644 --- a/sdk/tables/data-tables/test/integration/tableclient.spec.ts +++ b/sdk/tables/data-tables/test/integration/tableclient.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { TableClient, TableEntity, Edm, odata } from "../../src"; +import { Context } from "mocha"; import { assert } from "chai"; import { record, Recorder, isPlaybackMode, isLiveMode } from "@azure/test-utils-recorder"; import { recordedEnvironmentSetup, createTableClient } from "./utils/recordedClient"; @@ -18,13 +19,11 @@ describe("TableClient", () => { // which wouldn't match the recorded one. Fallingback to SAS for recorded tests. const authMode = !isNode || !isLiveMode() ? "SASConnectionString" : "AccountConnectionString"; - beforeEach( - /** @this Mocha.Context */ function() { - recorder = record(this, recordedEnvironmentSetup); + beforeEach(function(this: Context) { + recorder = record(this, recordedEnvironmentSetup); - client = createTableClient(tableName, authMode); - } - ); + client = createTableClient(tableName, authMode); + }); before(async () => { if (!isPlaybackMode()) { @@ -45,26 +44,24 @@ describe("TableClient", () => { describe("listEntities", () => { // Create required entities for testing list operations - before( - /** @this Mocha.Context */ async function() { - if (!isPlaybackMode()) { - this.timeout(10000); + before(async function(this: Context) { + if (!isPlaybackMode()) { + this.timeout(10000); + await client.createEntity({ + partitionKey: listPartitionKey, + rowKey: "binary1", + foo: new Uint8Array([66, 97, 114]) + }); + + for (let i = 0; i < 20; i++) { await client.createEntity({ partitionKey: listPartitionKey, - rowKey: "binary1", - foo: new Uint8Array([66, 97, 114]) + rowKey: `${i}`, + foo: "testEntity" }); - - for (let i = 0; i < 20; i++) { - await client.createEntity({ - partitionKey: listPartitionKey, - rowKey: `${i}`, - foo: "testEntity" - }); - } } } - ); + }); type StringEntity = { foo: string }; type NumberEntity = { foo: number }; type DateEntity = { foo: Date }; diff --git a/sdk/tables/data-tables/test/integration/tableserviceclient.spec.ts b/sdk/tables/data-tables/test/integration/tableserviceclient.spec.ts index ba3c836446b0..9fb0a62bf955 100644 --- a/sdk/tables/data-tables/test/integration/tableserviceclient.spec.ts +++ b/sdk/tables/data-tables/test/integration/tableserviceclient.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { TableResponseProperties, TableServiceClient } from "../../src"; +import { Context } from "mocha"; import { record, Recorder, isPlaybackMode, isLiveMode } from "@azure/test-utils-recorder"; import { recordedEnvironmentSetup, createTableServiceClient } from "./utils/recordedClient"; import { isNode } from "../testUtils"; @@ -14,12 +15,10 @@ describe("TableServiceClient", () => { const suffix = isNode ? "node" : "browser"; const authMode = !isNode || !isLiveMode() ? "SASConnectionString" : "AccountConnectionString"; - beforeEach( - /** @this Mocha.Context */ function() { - recorder = record(this, recordedEnvironmentSetup); - client = createTableServiceClient(authMode); - } - ); + beforeEach(function(this: Context) { + recorder = record(this, recordedEnvironmentSetup); + client = createTableServiceClient(authMode); + }); afterEach(async function() { await recorder.stop(); @@ -51,35 +50,31 @@ describe("TableServiceClient", () => { describe("listTables", () => { const tableNames: string[] = []; const expectedTotalItems = 20; - before( - /** @this Mocha.Context */ async function() { - // Create tables to be listed - if (!isPlaybackMode()) { - this.timeout(10000); - for (let i = 0; i < 20; i++) { - const tableName = `ListTableTest${suffix}${i}`; - await client.createTable(tableName); - tableNames.push(tableName); - } + before(async function(this: Context) { + // Create tables to be listed + if (!isPlaybackMode()) { + this.timeout(10000); + for (let i = 0; i < 20; i++) { + const tableName = `ListTableTest${suffix}${i}`; + await client.createTable(tableName); + tableNames.push(tableName); } } - ); + }); - after( - /** @this Mocha.Context */ async function() { - // Cleanup tables - if (!isPlaybackMode()) { - this.timeout(10000); - try { - for (const table of tableNames) { - await client.deleteTable(table); - } - } catch (error) { - console.warn(`Failed to delete a table during cleanup`); + after(async function(this: Context) { + // Cleanup tables + if (!isPlaybackMode()) { + this.timeout(10000); + try { + for (const table of tableNames) { + await client.deleteTable(table); } + } catch (error) { + console.warn(`Failed to delete a table during cleanup`); } } - ); + }); it("should list all", async () => { const tables = client.listTables(); diff --git a/sdk/tables/data-tables/test/unit/sharedKeyCredential.spec.ts b/sdk/tables/data-tables/test/unit/sharedKeyCredential.spec.ts index b71521260069..c8674274c1a9 100644 --- a/sdk/tables/data-tables/test/unit/sharedKeyCredential.spec.ts +++ b/sdk/tables/data-tables/test/unit/sharedKeyCredential.spec.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. +import { Context } from "mocha"; import { SendRequest, PipelineRequest, @@ -25,7 +26,7 @@ describe("TablesSharedKeyCredential", () => { Date.prototype.toUTCString = originalToUTCString; }); - it("It should sign", /** @this Mocha.Context */ async function() { + it("It should sign", async function(this: Context) { if (!isNode) { // TablesSharedKeyCredential auth is not supported in Browser this.skip(); diff --git a/sdk/tables/data-tables/test/unit/utils.spec.ts b/sdk/tables/data-tables/test/unit/utils.spec.ts index 3559606b22a0..332269838472 100644 --- a/sdk/tables/data-tables/test/unit/utils.spec.ts +++ b/sdk/tables/data-tables/test/unit/utils.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { extractConnectionStringParts } from "../../src/utils/connectionString"; +import { Context } from "mocha"; import { base64Encode, base64Decode } from "../../src/utils/bufferSerializer"; import { isNode } from "../testUtils"; import { assert } from "chai"; @@ -10,14 +11,12 @@ import { ConnectionString } from "../../src/utils/internalModels"; describe("Utility Helpers", () => { describe("extractConnectionStringParts", () => { describe("Account Connection String", () => { - beforeEach( - /** @this Mocha.Context */ function() { - if (!isNode) { - // Account connection string is not supported for Browsers - this.skip(); - } + beforeEach(function(this: Context) { + if (!isNode) { + // Account connection string is not supported for Browsers + this.skip(); } - ); + }); it("should handle connection string without TableEndpoint", () => { const validConnectionString = "DefaultEndpointsProtocol=https;AccountName=testaccount;AccountKey=REDACTED;EndpointSuffix=core.windows.net"; diff --git a/sdk/template/template/test/public/configurationClient.spec.ts b/sdk/template/template/test/public/configurationClient.spec.ts index 36706d5e28f2..c6a4212de7f4 100644 --- a/sdk/template/template/test/public/configurationClient.spec.ts +++ b/sdk/template/template/test/public/configurationClient.spec.ts @@ -52,36 +52,34 @@ describe("[AAD] ConfigurationClient functional tests", function() { // NOTE: use of "function" and not ES6 arrow-style functions with the // beforeEach hook is IMPORTANT due to the use of `this` in the function // body. - beforeEach( - /** @this Mocha.Context */ function(this: Context) { - // The recorder has some convenience methods, and we need to store a - // reference to it so that we can `stop()` the recorder later in the - // `afterEach` hook. - recorder = record(this, { - // == Recorder Environment Setup == Add the replaceable variables from - // above - replaceableVariables, - - // We don't use this in the template, but if we had any query parameters - // we wished to discard, we could add them here - queryParametersToSkip: [], - - // Finally, we need to remove the AAD `access_token` from any requests. - // This is very important, as it cannot be removed using environment - // variable or query parameter replacement. The - // `customizationsOnRecordings` field allows us to make arbitrary - // replacements within recordings. - customizationsOnRecordings: [ - (recording: any): any => - recording.replace(/"access_token":"[^"]*"/g, `"access_token":"access_token"`) - ] - }); - - // We'll be able to refer to the instantiated `client` in tests, since we - // initialize it before each test - client = createConfigurationClient(); - } - ); + beforeEach(function(this: Context) { + // The recorder has some convenience methods, and we need to store a + // reference to it so that we can `stop()` the recorder later in the + // `afterEach` hook. + recorder = record(this, { + // == Recorder Environment Setup == Add the replaceable variables from + // above + replaceableVariables, + + // We don't use this in the template, but if we had any query parameters + // we wished to discard, we could add them here + queryParametersToSkip: [], + + // Finally, we need to remove the AAD `access_token` from any requests. + // This is very important, as it cannot be removed using environment + // variable or query parameter replacement. The + // `customizationsOnRecordings` field allows us to make arbitrary + // replacements within recordings. + customizationsOnRecordings: [ + (recording: any): any => + recording.replace(/"access_token":"[^"]*"/g, `"access_token":"access_token"`) + ] + }); + + // We'll be able to refer to the instantiated `client` in tests, since we + // initialize it before each test + client = createConfigurationClient(); + }); // After each test, we need to stop the recording. afterEach(async function() { diff --git a/sdk/textanalytics/ai-text-analytics/test/public/apiKey.spec.ts b/sdk/textanalytics/ai-text-analytics/test/public/apiKey.spec.ts index 08d82c723afe..52359e0c83b2 100644 --- a/sdk/textanalytics/ai-text-analytics/test/public/apiKey.spec.ts +++ b/sdk/textanalytics/ai-text-analytics/test/public/apiKey.spec.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { assert, use as chaiUse } from "chai"; +import { Suite, Context } from "mocha"; import chaiPromises from "chai-as-promised"; chaiUse(chaiPromises); @@ -19,29 +20,25 @@ const testDataEn = [ "I didn't like the last book I read at all." ]; -describe("[API Key] TextAnalyticsClient", /** @this Mocha.Context */ function() { +describe("[API Key] TextAnalyticsClient", function(this: Suite) { let recorder: Recorder; let client: TextAnalyticsClient; const CLITimeout = this.timeout(); const fastTimeout = 10000; - beforeEach( - /** @this Mocha.Context */ function() { - recorder = createRecorder(this); - client = createClient("APIKey"); - } - ); + beforeEach(function(this: Context) { + recorder = createRecorder(this); + client = createClient("APIKey"); + }); afterEach(async function() { await recorder.stop(); }); describe("fast tests", function() { - before( - /** @this Mocha.Context */ function() { - this.timeout(fastTimeout); - } - ); + before(function(this: Context) { + this.timeout(fastTimeout); + }); it("#analyzeSentiment", async function() { const results = await client.analyzeSentiment(testDataEn); @@ -89,11 +86,9 @@ describe("[API Key] TextAnalyticsClient", /** @this Mocha.Context */ function() describe("LROs", function() { const pollingInterval = isPlaybackMode() ? 0 : 2000; - before( - /** @this Mocha.Context */ function() { - this.timeout(isPlaybackMode() ? fastTimeout : CLITimeout); - } - ); + before(function(this: Context) { + this.timeout(isPlaybackMode() ? fastTimeout : CLITimeout); + }); describe("#health", function() { it("input strings", async function() { diff --git a/sdk/textanalytics/ai-text-analytics/test/public/textAnalyticsClient.spec.ts b/sdk/textanalytics/ai-text-analytics/test/public/textAnalyticsClient.spec.ts index 042db8123bc1..5634f2df460c 100644 --- a/sdk/textanalytics/ai-text-analytics/test/public/textAnalyticsClient.spec.ts +++ b/sdk/textanalytics/ai-text-analytics/test/public/textAnalyticsClient.spec.ts @@ -4,6 +4,7 @@ /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ import { assert } from "chai"; +import { Suite, Context } from "mocha"; import { isPlaybackMode, Recorder } from "@azure/test-utils-recorder"; @@ -35,7 +36,7 @@ const testDataEs = [ "Los caminos que llevan hasta Monte Rainier son espectaculares y hermosos.", "La carretera estaba atascada. Había mucho tráfico el día de ayer." ]; -describe("[AAD] TextAnalyticsClient", /** @this Mocha.Context */ function() { +describe("[AAD] TextAnalyticsClient", function(this: Suite) { let recorder: Recorder; let client: TextAnalyticsClient; const CLITimeout = this.timeout(); @@ -43,28 +44,24 @@ describe("[AAD] TextAnalyticsClient", /** @this Mocha.Context */ function() { let getId: () => string; - beforeEach( - /** @this Mocha.Context */ function() { - recorder = createRecorder(this); - client = createClient("AAD"); - let nextId = 0; - getId = function() { - nextId += 1; - return nextId.toString(); - }; - } - ); + beforeEach(function(this: Context) { + recorder = createRecorder(this); + client = createClient("AAD"); + let nextId = 0; + getId = function() { + nextId += 1; + return nextId.toString(); + }; + }); afterEach(async function() { await recorder.stop(); }); describe("fast tests", function() { - before( - /** @this Mocha.Context */ function() { - this.timeout(fastTimeout); - } - ); + before(function(this: Context) { + this.timeout(fastTimeout); + }); describe("#analyzeSentiment", function() { it("client throws on empty list", async function() { @@ -930,11 +927,9 @@ describe("[AAD] TextAnalyticsClient", /** @this Mocha.Context */ function() { describe("LROs", function() { const pollingInterval = isPlaybackMode() ? 0 : 2000; - before( - /** @this Mocha.Context */ function() { - this.timeout(isPlaybackMode() ? fastTimeout : CLITimeout); - } - ); + before(function(this: Context) { + this.timeout(isPlaybackMode() ? fastTimeout : CLITimeout); + }); describe("#analyze", function() { it("single entity recognition action", async function() { diff --git a/tsdoc.json b/tsdoc.json index 9c1bbccb2518..6e1223d4e138 100644 --- a/tsdoc.json +++ b/tsdoc.json @@ -4,10 +4,6 @@ { "tagName": "@hidden", "syntaxKind": "modifier" - }, - { - "tagName": "@this", - "syntaxKind": "modifier" } ] }