Use @this to satisfy ESLint's no-invalid-this (#14406)

# Problem

`no-invalid-this` makes sure uses of `this` are valid (see [docs](https://eslint.org/docs/rules/no-invalid-this) and [implementation](8984c91372/lib/rules/utils/ast-utils.js (L900))). However, uses of `this` are rampant in our test suites because this is how mocha unit tests are structured, the Mocha context can be accessed only through `this`. 

# Fix

So instead of disabling `no-invalid-this` in our test suites, this PR tags functions that reference `this` with `@this` and that satisfies the rule requirements (see [docs](https://eslint.org/docs/rules/no-invalid-this)).

# Discussion

It could be argued that this work just replaces one comment annotation with another so we did not really solve the underlying problem. However, the inherent problem lies in how mocha itself works and there is nothing we can do other than probably migrating to another framework that is more sane/type-safe. One minor improvement we get is we now have slightly less syntactic overhead because we need to tag just the function instead of individual lines in its body that violate the rule.

# Trade-offs

Pros:
- function tags are less than line tags

Cons:
- whitelisting one more tag with the tsdoc linter that our devs need to learn about
- still having rampant tags everywhere

Fixes https://github.com/Azure/azure-sdk-for-js/issues/11404
This commit is contained in:
Deyaaeldeen Almahallawi 2021-03-22 20:51:54 -04:00 коммит произвёл GitHub
Родитель 589e8cd553
Коммит 18b3f30602
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
101 изменённых файлов: 930 добавлений и 797 удалений

Просмотреть файл

@ -19,10 +19,11 @@ describe("AnomalyDetectorClient", () => {
let recorder: Recorder;
const apiKey = new AzureKeyCredential(testEnv.ANOMALY_DETECTOR_API_KEY);
beforeEach(function() {
// eslint-disable-next-line no-invalid-this
({ recorder, client } = createRecordedAnomalyDetectorClient(this, apiKey));
});
beforeEach(
/** @this Mocha.Context */ function() {
({ recorder, client } = createRecordedAnomalyDetectorClient(this, apiKey));
}
);
afterEach(async function() {
if (recorder) {

Просмотреть файл

@ -14,8 +14,7 @@ import { verifyAttestationToken } from "../utils/helpers";
describe("[AAD] Attestation Client", function() {
let recorder: Recorder;
beforeEach(function() {
// eslint-disable-next-line no-invalid-this
beforeEach(/** @this Mocha.Context */ function() {
recorder = createRecorder(this);
});

Просмотреть файл

@ -14,8 +14,7 @@ import { verifyAttestationToken } from "../utils/helpers";
describe("PolicyGetSetTests ", function() {
let recorder: Recorder;
beforeEach(function() {
// eslint-disable-next-line no-invalid-this
beforeEach(/** @this Mocha.Context */ function() {
recorder = createRecorder(this);
});

Просмотреть файл

@ -13,8 +13,7 @@ import { verifyAttestationToken } from "../utils/helpers";
describe("PolicyManagementTests ", function() {
let recorder: Recorder;
beforeEach(function() {
// eslint-disable-next-line no-invalid-this
beforeEach(/** @this Mocha.Context */ function() {
recorder = createRecorder(this);
});

Просмотреть файл

@ -13,8 +13,7 @@ import { Buffer } from "../utils/Buffer";
describe("TokenCertTests", function() {
let recorder: Recorder;
beforeEach(function() {
// eslint-disable-next-line no-invalid-this
beforeEach(/** @this Mocha.Context */ function() {
recorder = createRecorder(this);
});

Просмотреть файл

@ -50,35 +50,36 @@ 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(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.
// eslint-disable-next-line no-invalid-this
recorder = record(this, {
// == Recorder Environment Setup == Add the replaceable variables from
// above
replaceableVariables,
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: [],
// 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() {

Просмотреть файл

@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
"extends": ["../../../tsdoc.json"]
}

Просмотреть файл

@ -236,9 +236,8 @@ describe("defaultHttpClient", function() {
}
});
it("should give a graceful error for nonexistent hosts", async function() {
it("should give a graceful error for nonexistent hosts", /** @this Mocha.Context */ async function() {
// Increase timeout to give the request time to fail
// eslint-disable-next-line no-invalid-this
this.timeout(10000);
const requestUrl = "http://fake.domain";
const request = new WebResource(requestUrl, "GET");

Просмотреть файл

@ -1,6 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/* eslint-disable no-invalid-this */
import { HttpOperationResponse, RequestOptionsBase } from "@azure/core-http";
import { AbortSignalLike } from "@azure/abort-controller";
@ -22,6 +21,7 @@ export interface TestOperationState extends PollOperationState<string> {
export interface TestOperation extends PollOperation<TestOperationState, string> {}
/** @this TestOperation */
async function update(
this: TestOperation,
options: {
@ -70,6 +70,7 @@ async function update(
return makeOperation(newState);
}
/** @this TestOperation */
async function cancel(
this: TestOperation,
options: { abortSignal?: AbortSignal } = {}
@ -100,6 +101,7 @@ async function cancel(
});
}
/** @this TestOperation */
function toString(this: TestOperation): string {
return JSON.stringify({
state: this.state

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/* eslint-disable no-invalid-this */
import { log } from "./log";
/**
@ -157,6 +155,7 @@ function createDebugger(namespace: string): Debugger {
return newDebugger;
}
/** @this Debugger */
function destroy(this: Debugger): boolean {
const index = debuggers.indexOf(this);
if (index >= 0) {
@ -166,6 +165,7 @@ 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;

Просмотреть файл

@ -2,7 +2,6 @@
"extends": ["../.eslintrc.json"],
"rules": {
"no-console": "off",
"no-invalid-this": "off",
"space-before-function-paren": "off"
}
}

Просмотреть файл

@ -28,7 +28,7 @@ function getCollection2TokenMap(
return (sessionContainer as any).collectionResourceIdToSessionTokens;
}
describe("Session Token", function() {
describe("Session Token", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 20000);
const containerId = "sessionTestColl";
@ -304,7 +304,7 @@ describe("Session Token", function() {
spy.restore();
});
it("validate 'lsn not caught up' error for higher lsn and clearing session token", async function() {
it("validate 'lsn not caught up' error for higher lsn and clearing session token", /** @this Mocha.Context */ async function() {
this.retries(2);
const database = await getTestDatabase("session test", client);

Просмотреть файл

@ -4,7 +4,7 @@
import { getAuthorizationTokenUsingResourceTokens } from "../../../src/auth";
import assert from "assert";
describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
it("should find exact match", async function() {

Просмотреть файл

@ -11,7 +11,7 @@ import {
removeAllDatabases
} from "../common/TestHelpers";
describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();

Просмотреть файл

@ -13,7 +13,7 @@ import {
import AbortController from "node-abort-controller";
import { UsernamePasswordCredential } from "@azure/identity";
describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 20000);
describe("Validate client request timeout", function() {

Просмотреть файл

@ -3,7 +3,7 @@
import assert from "assert";
import { removeAllDatabases, getTestContainer } from "../common/TestHelpers";
describe("Conflicts", function() {
describe("Conflicts", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();

Просмотреть файл

@ -14,7 +14,7 @@ import {
import { SpatialType } from "../../../src";
import { GeospatialType } from "../../../src";
describe("Containers", function() {
describe("Containers", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();

Просмотреть файл

@ -13,7 +13,7 @@ import { DatabaseRequest } from "../../../src";
const client = new CosmosClient({ endpoint, key: masterKey });
describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();

Просмотреть файл

@ -6,11 +6,13 @@ import { endpoint, masterKey } from "../common/_testConfig";
const client = new CosmosClient({ endpoint, key: masterKey });
describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
});
beforeEach(
/** @this Mocha.Context */ async function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
}
);
describe("validate database account functionality", function() {
it("nativeApi Should get database account successfully name based", async function() {

Просмотреть файл

@ -26,7 +26,7 @@ interface TestItem {
replace?: string;
}
describe("Item CRUD", function() {
describe("Item CRUD", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();

Просмотреть файл

@ -15,13 +15,15 @@ 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", function() {
describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
await removeAllDatabases();
});
beforeEach(
/** @this Mocha.Context */ async function() {
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() {

Просмотреть файл

@ -10,7 +10,7 @@ import {
replaceOrUpsertPermission
} from "../common/TestHelpers";
describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();

Просмотреть файл

@ -14,7 +14,7 @@ if (!Symbol || !Symbol.asyncIterator) {
(Symbol as any).asyncIterator = Symbol.for("Symbol.asyncIterator");
}
describe("Queries", function() {
describe("Queries", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
before(async function() {
await removeAllDatabases();
@ -47,7 +47,7 @@ describe("Queries", function() {
});
});
describe("QueryIterator", function() {
describe("QueryIterator", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 30000);
let resources: { container: Container; doc1: any; doc2: any; doc3: any };
@ -143,7 +143,7 @@ describe("Queries", function() {
}
});
describe("SUM query iterator", function() {
describe("SUM query iterator", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 30000);
it("returns undefined sum with null value in aggregator", async function() {

Просмотреть файл

@ -4,7 +4,7 @@ import assert from "assert";
import { Database, DataType, IndexKind } from "../../../src";
import { createOrUpsertItem, getTestDatabase, removeAllDatabases } from "../common/TestHelpers";
describe("Spatial Indexes", function() {
describe("Spatial Indexes", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();

Просмотреть файл

@ -13,16 +13,18 @@ import {
// Used for sproc
declare let getContext: any;
describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();
});
describe("Validate sproc CRUD", function() {
let container: Container;
beforeEach(async function() {
container = await getTestContainer(this.test.fullTitle());
});
beforeEach(
/** @this Mocha.Context */ async function() {
container = await getTestContainer(this.test.fullTitle());
}
);
it("nativeApi Should do sproc CRUD operations successfully with create/replace", async function() {
// read sprocs
@ -92,9 +94,11 @@ describe("NodeJS CRUD Tests", function() {
describe("Validate stored procedure functionality", function() {
let container: Container;
beforeEach(async function() {
container = await getTestContainer(this.test.fullTitle());
});
beforeEach(
/** @this Mocha.Context */ async function() {
container = await getTestContainer(this.test.fullTitle());
}
);
it("nativeApi should do stored procedure operations successfully with create/replace", async function() {
const sproc1: StoredProcedureDefinition = {

Просмотреть файл

@ -10,7 +10,7 @@ const notFoundErrorCode = 404;
// Mock for trigger function bodies
declare let getContext: any;
describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
let container: Container;

Просмотреть файл

@ -11,7 +11,7 @@ async function sleep(time: number): Promise<unknown> {
});
}
describe("Container TTL", function() {
describe("Container TTL", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 600000);
beforeEach(async function() {
await removeAllDatabases();

Просмотреть файл

@ -4,7 +4,7 @@ import assert from "assert";
import { UserDefinedFunctionDefinition, Container } from "../../../src";
import { removeAllDatabases, getTestContainer } from "../common/TestHelpers";
describe("User Defined Function", function() {
describe("User Defined Function", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
let container: Container;

Просмотреть файл

@ -4,7 +4,7 @@ import assert from "assert";
import { UserDefinition } from "../../../src";
import { createOrUpsertUser, getTestDatabase, removeAllDatabases } from "../common/TestHelpers";
describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();

Просмотреть файл

@ -9,7 +9,7 @@ import { FeedOptions } from "../../../src";
import { TestData } from "../common/TestData";
import { bulkInsertItems, getTestContainer, removeAllDatabases } from "../common/TestHelpers";
describe("Aggregate Query", function() {
describe("Aggregate Query", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 20000);
const partitionKey = "key";
const uniquePartitionKey = "uniquePartitionKey";

Просмотреть файл

@ -6,7 +6,7 @@ import { Database } from "../../../src";
import { endpoint } from "../common/_testConfig";
import { getTestContainer, removeAllDatabases } from "../common/TestHelpers";
describe("Authorization", function() {
describe("Authorization", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
// TODO: should have types for all these things

Просмотреть файл

@ -5,7 +5,7 @@ import { RequestOptions } from "../../../src";
import { Container, ContainerDefinition } from "../../../src";
import { getTestContainer, removeAllDatabases } from "../common/TestHelpers";
describe("Change Feed Iterator", function() {
describe("Change Feed Iterator", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 20000);
// delete all databases and create sample database

Просмотреть файл

@ -26,7 +26,7 @@ function compare(key: string) {
};
}
describe("Cross Partition", function() {
describe("Cross Partition", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || "30000");
describe("Validate Query", function() {

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -107,7 +107,7 @@ const collectionResponse = {
code: 200
};
describe("Multi-region tests", function() {
describe("Multi-region tests", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || "30000");
it("Preferred locations should be honored for readEndpoint", async function() {

Просмотреть файл

@ -52,7 +52,7 @@ if (!isBrowser()) {
});
});
it("nativeApi Client Should execute request in error while the proxy setting is not correct", async function() {
it("nativeApi Client Should execute request in error while the proxy setting is not correct", /** @this Mocha.Context */ async function() {
this.timeout(process.env.MOCHA_TIMEOUT || 30000);
return new Promise((resolve, reject) => {
proxy.listen(proxyPort + 1, "127.0.0.1", async () => {

Просмотреть файл

@ -6,7 +6,7 @@ import { getTestContainer, getTestDatabase, removeAllDatabases } from "../common
const doc = { id: "myId", pk: "pk" };
describe("ResourceLink Trimming of leading and trailing slashes", function() {
describe("ResourceLink Trimming of leading and trailing slashes", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
const containerId = "testcontainer";
@ -39,7 +39,7 @@ describe("ResourceLink Trimming of leading and trailing slashes", function() {
});
});
describe("Test Query Metrics", function() {
describe("Test Query Metrics", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 20000);
const collectionId = "testCollection2";
@ -84,7 +84,7 @@ describe("Test Query Metrics", function() {
});
});
describe("Partition key in FeedOptions", function() {
describe("Partition key in FeedOptions", /** @this Mocha.Context */ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {

Просмотреть файл

@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
"extends": ["../../../../tsdoc.json"]
}

Просмотреть файл

@ -1,6 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/* eslint-disable no-invalid-this */
import { assert } from "chai";
@ -19,7 +18,7 @@ import {
import { FullOperationResponse } from "@azure/core-client";
import { RestError } from "@azure/core-rest-pipeline";
describe("EventGridPublisherClient", function() {
describe("EventGridPublisherClient", /** @this Mocha.Context */ function() {
let recorder: Recorder;
let res: FullOperationResponse | undefined;
@ -32,14 +31,16 @@ describe("EventGridPublisherClient", function() {
describe("#send (EventGrid schema)", function() {
let client: EventGridPublisherClient<"EventGrid">;
beforeEach(function() {
({ client, recorder } = createRecordedClient(
this,
testEnv.EVENT_GRID_EVENT_GRID_SCHEMA_ENDPOINT,
"EventGrid",
new AzureKeyCredential(testEnv.EVENT_GRID_EVENT_GRID_SCHEMA_API_KEY)
));
});
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)
));
}
);
afterEach(async function() {
await recorder.stop();
@ -99,14 +100,16 @@ describe("EventGridPublisherClient", function() {
describe("#send error cases (EventGrid schema)", function() {
let client: EventGridPublisherClient<"EventGrid">;
beforeEach(function() {
({ client, recorder } = createRecordedClient(
this,
removeApiEventsSuffix(testEnv.EVENT_GRID_CUSTOM_SCHEMA_ENDPOINT),
"EventGrid",
new AzureKeyCredential(testEnv.EVENT_GRID_CUSTOM_SCHEMA_API_KEY)
));
});
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)
));
}
);
afterEach(async function() {
await recorder.stop();
@ -142,14 +145,16 @@ describe("EventGridPublisherClient", function() {
describe("#send (CloudEvent schema)", function() {
let client: EventGridPublisherClient<"CloudEvent">;
beforeEach(function() {
({ client, recorder } = createRecordedClient(
this,
testEnv.EVENT_GRID_CLOUD_EVENT_SCHEMA_ENDPOINT,
"CloudEvent",
new AzureKeyCredential(testEnv.EVENT_GRID_CLOUD_EVENT_SCHEMA_API_KEY)
));
});
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)
));
}
);
afterEach(async function() {
await recorder.stop();
@ -251,14 +256,16 @@ describe("EventGridPublisherClient", function() {
describe("#send error cases (CloudEvent schema)", function() {
let client: EventGridPublisherClient<"CloudEvent">;
beforeEach(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(
/** @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)
));
}
);
afterEach(async function() {
await recorder.stop();
@ -292,14 +299,16 @@ describe("EventGridPublisherClient", function() {
describe("#send (Custom Event Schema)", function() {
let client: EventGridPublisherClient<"Custom">;
beforeEach(function() {
({ client, recorder } = createRecordedClient(
this,
testEnv.EVENT_GRID_CUSTOM_SCHEMA_ENDPOINT,
"Custom",
new AzureKeyCredential(testEnv.EVENT_GRID_CUSTOM_SCHEMA_API_KEY)
));
});
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)
));
}
);
afterEach(async function() {
await recorder.stop();
@ -353,14 +362,16 @@ describe("EventGridPublisherClient", function() {
describe("#send error cases (Custom Event Schema)", function() {
let client: EventGridPublisherClient<"Custom">;
beforeEach(function() {
({ client, recorder } = createRecordedClient(
this,
removeApiEventsSuffix(testEnv.EVENT_GRID_CUSTOM_SCHEMA_ENDPOINT),
"Custom",
new AzureKeyCredential(testEnv.EVENT_GRID_CUSTOM_SCHEMA_API_KEY)
));
});
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)
));
}
);
afterEach(async function() {
await recorder.stop();

Просмотреть файл

@ -16,10 +16,11 @@ describe("FormRecognizerClient browser only", () => {
let recorder: Recorder;
const apiKey = new AzureKeyCredential(testEnv.FORM_RECOGNIZER_API_KEY);
beforeEach(function() {
// eslint-disable-next-line no-invalid-this
({ recorder, client } = createRecordedRecognizerClient(this, apiKey));
});
beforeEach(
/** @this Mocha.Context */ function() {
({ recorder, client } = createRecordedRecognizerClient(this, apiKey));
}
);
afterEach(async function() {
if (recorder) {

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/* eslint-disable no-invalid-this */
import { assert } from "chai";
import { Context } from "mocha";
@ -29,9 +27,11 @@ matrix([[true, false]] as const, async (useAad) => {
describe(`[${useAad ? "AAD" : "API Key"}] FormTrainingClient`, () => {
let recorder: Recorder;
beforeEach(function(this: Context) {
recorder = createRecorder(this);
});
beforeEach(
/** @this Mocha.Context */ function(this: Context) {
recorder = createRecorder(this);
}
);
afterEach(async function() {
await recorder.stop();

Просмотреть файл

@ -28,11 +28,12 @@ matrix([[true, false]] as const, async (useAad) => {
let client: FormRecognizerClient;
let recorder: Recorder;
beforeEach(function() {
// eslint-disable-next-line no-invalid-this
recorder = createRecorder(this);
client = new FormRecognizerClient(endpoint(), makeCredential(useAad));
});
beforeEach(
/** @this Mocha.Context */ function() {
recorder = createRecorder(this);
client = new FormRecognizerClient(endpoint(), makeCredential(useAad));
}
);
afterEach(async function() {
if (recorder) {

Просмотреть файл

@ -77,9 +77,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", /** @this Mocha.Context */ async function() {
if (!isNode) {
// eslint-disable-next-line no-invalid-this
return this.skip();
}
process.env.AZURE_AUTHORITY_HOST = "http://totallyinsecure.lol";

Просмотреть файл

@ -4,7 +4,6 @@
"ignorePatterns": ["src/generated"],
"rules": {
"@typescript-eslint/no-this-alias": "off",
"no-invalid-this": "off",
"@azure/azure-sdk/ts-package-json-module": "warn",
"no-use-before-define": "warn"
}

Просмотреть файл

@ -4,7 +4,6 @@
"ignorePatterns": ["src/core"],
"rules": {
"@typescript-eslint/no-this-alias": "off",
"no-invalid-this": "off",
"@azure/azure-sdk/ts-package-json-module": "warn",
"no-use-before-define": "warn"
}

Просмотреть файл

@ -32,13 +32,15 @@ describe("Challenge based authentication tests", () => {
subject: "cn=MyCert"
};
beforeEach(async function() {
const authentication = await authenticate(this);
certificateSuffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
certificateSuffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -46,7 +48,7 @@ describe("Challenge based authentication tests", () => {
// The tests follow
it("Authentication should work for parallel requests", async function() {
it("Authentication should work for parallel requests", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(
`${certificatePrefix}-${this!.test!.title}-${certificateSuffix}`
);
@ -84,7 +86,7 @@ describe("Challenge based authentication tests", () => {
sandbox.restore();
});
it("Once authenticated, new requests should not authenticate again", async function() {
it("Once authenticated, new requests should not authenticate again", /** @this Mocha.Context */ async function() {
// 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.

Просмотреть файл

@ -13,7 +13,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)", async function() {
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() {
if (!isNode) {
this.skip();
return;

Просмотреть файл

@ -32,16 +32,18 @@ describe("Certificates client - create, read, update and delete", () => {
subject: "cn=MyCert"
};
beforeEach(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(
/** @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);
}
);
afterEach(async function() {
await recorder.stop();
@ -49,7 +51,7 @@ describe("Certificates client - create, read, update and delete", () => {
// The tests follow
it("can create a certificate", async function() {
it("can create a certificate", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const poller = await client.beginCreateCertificate(
certificateName,
@ -65,7 +67,7 @@ describe("Certificates client - create, read, update and delete", () => {
await testClient.flushCertificate(certificateName);
});
it("can abort creating a certificate", async function() {
it("can abort creating a certificate", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const controller = new AbortController();
@ -80,7 +82,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", async function() {
it("can create a certificate with requestOptions timeout", /** @this Mocha.Context */ async function() {
recorder.skip("browser", "Timeout tests don't work on playback mode.");
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
@ -114,7 +116,7 @@ describe("Certificates client - create, read, update and delete", () => {
);
});
it("can update the tags of a certificate", async function() {
it("can update the tags of a certificate", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
await client.beginCreateCertificate(
@ -137,7 +139,7 @@ describe("Certificates client - create, read, update and delete", () => {
await testClient.flushCertificate(certificateName);
});
it("can disable a certificate", async function() {
it("can disable a certificate", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const poller = await client.beginCreateCertificate(
@ -160,7 +162,7 @@ describe("Certificates client - create, read, update and delete", () => {
await testClient.flushCertificate(certificateName);
});
it("can disable a certificate version", async function() {
it("can disable a certificate version", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const poller = await client.beginCreateCertificate(
@ -186,7 +188,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", async function() {
it("can update certificate with requestOptions timeout", /** @this Mocha.Context */ async function() {
recorder.skip(undefined, "Timeout tests don't work on playback mode.");
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
@ -207,7 +209,7 @@ describe("Certificates client - create, read, update and delete", () => {
});
});
it("can get a certificate", async function() {
it("can get a certificate", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
await client.beginCreateCertificate(
certificateName,
@ -223,7 +225,7 @@ describe("Certificates client - create, read, update and delete", () => {
await testClient.flushCertificate(certificateName);
});
it("can get a certificate's secret in PKCS 12 format", async function() {
it("can get a certificate's secret in PKCS 12 format", /** @this Mocha.Context */ async function() {
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) {
@ -272,7 +274,7 @@ describe("Certificates client - create, read, update and delete", () => {
await testClient.flushCertificate(certificateName);
});
it("can get a certificate's secret in PEM format", async function() {
it("can get a certificate's secret in PEM format", /** @this Mocha.Context */ async function() {
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) {
@ -308,7 +310,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", async function() {
it("can get a certificate with requestOptions timeout", /** @this Mocha.Context */ async function() {
recorder.skip(undefined, "Timeout tests don't work on playback mode.");
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
await client.beginCreateCertificate(
@ -321,7 +323,7 @@ describe("Certificates client - create, read, update and delete", () => {
});
});
it("can retrieve the latest version of a certificate value", async function() {
it("can retrieve the latest version of a certificate value", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
await client.beginCreateCertificate(
certificateName,
@ -339,7 +341,7 @@ describe("Certificates client - create, read, update and delete", () => {
await testClient.flushCertificate(certificateName);
});
it("can get a certificate (Non Existing)", async function() {
it("can get a certificate (Non Existing)", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
let error;
try {
@ -352,7 +354,7 @@ describe("Certificates client - create, read, update and delete", () => {
assert.equal(error.statusCode, 404);
});
it("can delete a certificate", async function() {
it("can delete a certificate", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
await client.beginCreateCertificate(
certificateName,
@ -382,7 +384,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", async function() {
it("can delete a certificate with requestOptions timeout", /** @this Mocha.Context */ async function() {
recorder.skip(undefined, "Timeout tests don't work on playback mode.");
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
await client.beginCreateCertificate(
@ -400,7 +402,7 @@ describe("Certificates client - create, read, update and delete", () => {
});
});
it("can delete a certificate (Non Existing)", async function() {
it("can delete a certificate (Non Existing)", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
let error;
try {
@ -414,7 +416,7 @@ describe("Certificates client - create, read, update and delete", () => {
});
describe("can get a deleted certificate", () => {
it("using beginDeleteCertificate's poller", async function() {
it("using beginDeleteCertificate's poller", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
await client.beginCreateCertificate(
certificateName,
@ -436,7 +438,7 @@ describe("Certificates client - create, read, update and delete", () => {
await testClient.purgeCertificate(certificateName);
});
it("using getDeletedCertificate", async function() {
it("using getDeletedCertificate", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
await client.beginCreateCertificate(
certificateName,
@ -460,7 +462,7 @@ describe("Certificates client - create, read, update and delete", () => {
await testClient.purgeCertificate(certificateName);
});
it("can not get a certificate that never existed", async function() {
it("can not get a certificate that never existed", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
let error;
try {
@ -474,7 +476,7 @@ describe("Certificates client - create, read, update and delete", () => {
});
});
it("can create, read, and delete a certificate issuer", async function() {
it("can create, read, and delete a certificate issuer", /** @this Mocha.Context */ async function() {
const issuerName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
@ -540,7 +542,7 @@ describe("Certificates client - create, read, update and delete", () => {
await testClient.flushCertificate(certificateName);
});
it("can update a certificate's policy", async function() {
it("can update a certificate's policy", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
await client.beginCreateCertificate(
@ -562,7 +564,7 @@ describe("Certificates client - create, read, update and delete", () => {
await testClient.flushCertificate(certificateName);
});
it("can read, cancel and delete a certificate's operation", async function() {
it("can read, cancel and delete a certificate's operation", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
await client.beginCreateCertificate(
certificateName,

Просмотреть файл

@ -26,13 +26,15 @@ describe("Certificates client - list certificates in various ways", () => {
subject: "cn=MyCert"
};
beforeEach(async function() {
const authentication = await authenticate(this);
suffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
suffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -43,7 +45,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", async function(): Promise<void> {
it("can purge all certificates", /** @this Mocha.Context */ async function(): Promise<void> {
// 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();
@ -66,7 +68,7 @@ describe("Certificates client - list certificates in various ways", () => {
}
});
it("can list certificates", async function() {
it("can list certificates", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const certificateNames = [`${certificateName}0`, `${certificateName}1`];
for (const name of certificateNames) {
@ -92,7 +94,7 @@ describe("Certificates client - list certificates in various ways", () => {
}
});
it("can list deleted certificates", async function() {
it("can list deleted certificates", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const certificateNames = [`${certificateName}0`, `${certificateName}1`];
for (const name of certificateNames) {
@ -122,7 +124,7 @@ describe("Certificates client - list certificates in various ways", () => {
}
});
it("can list certificates by page", async function() {
it("can list certificates by page", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const certificateNames = [`${certificateName}0`, `${certificateName}1`];
for (const name of certificateNames) {
@ -159,7 +161,7 @@ describe("Certificates client - list certificates in various ways", () => {
});
}
it("can list deleted certificates by page", async function() {
it("can list deleted certificates by page", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const certificateNames = [`${certificateName}0`, `${certificateName}1`];
for (const name of certificateNames) {
@ -198,7 +200,7 @@ describe("Certificates client - list certificates in various ways", () => {
});
});
it("can retrieve all versions of a certificate", async function() {
it("can retrieve all versions of a certificate", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const certificateTags = ["tag01", "tag02", "tag03"];
@ -255,7 +257,7 @@ describe("Certificates client - list certificates in various ways", () => {
});
});
it("can list certificate versions (non existing)", async function() {
it("can list certificate versions (non existing)", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
let totalVersions = 0;
for await (const page of client.listPropertiesOfCertificateVersions(certificateName).byPage()) {

Просмотреть файл

@ -17,13 +17,15 @@ describe("Certificates client - LRO - create", () => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
certificateSuffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
certificateSuffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -31,7 +33,7 @@ describe("Certificates client - LRO - create", () => {
// The tests follow
it("can wait until a certificate is created", async function() {
it("can wait until a certificate is created", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(
`${certificatePrefix}-${this!.test!.title}-${certificateSuffix}`
);
@ -55,7 +57,7 @@ describe("Certificates client - LRO - create", () => {
await testClient.flushCertificate(certificateName);
});
it("can resume from a stopped poller", async function() {
it("can resume from a stopped poller", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(
`${certificatePrefix}-${this!.test!.title}-${certificateSuffix}`
);

Просмотреть файл

@ -17,13 +17,15 @@ describe("Certificates client - lro - delete", () => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
certificateSuffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
certificateSuffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -31,7 +33,7 @@ describe("Certificates client - lro - delete", () => {
// The tests follow
it("can wait until a certificate is deleted", async function() {
it("can wait until a certificate is deleted", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(
`${certificatePrefix}-${this!.test!.title}-${certificateSuffix}`
);
@ -61,7 +63,7 @@ describe("Certificates client - lro - delete", () => {
await testClient.purgeCertificate(certificateName);
});
it("can resume from a stopped poller", async function() {
it("can resume from a stopped poller", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(
`${certificatePrefix}-${this!.test!.title}-${certificateSuffix}`
);

Просмотреть файл

@ -21,13 +21,15 @@ describe("Certificates client - LRO - certificate operation", () => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
certificateSuffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
certificateSuffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -35,7 +37,7 @@ describe("Certificates client - LRO - certificate operation", () => {
// The tests follow
it("can wait until a certificate is created by getting the poller from getCertificateOperation", async function() {
it("can wait until a certificate is created by getting the poller from getCertificateOperation", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(
`${certificatePrefix}-${this!.test!.title}-${certificateSuffix}`
);
@ -64,7 +66,7 @@ describe("Certificates client - LRO - certificate operation", () => {
await testClient.flushCertificate(certificateName);
});
it("can resume from a stopped poller", async function() {
it("can resume from a stopped poller", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(
`${certificatePrefix}-${this!.test!.title}-${certificateSuffix}`
);

Просмотреть файл

@ -18,13 +18,15 @@ describe("Certificates client - LRO - recoverDelete", () => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
certificateSuffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
certificateSuffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -32,7 +34,7 @@ describe("Certificates client - LRO - recoverDelete", () => {
// The tests follow
it("can wait until a certificate is recovered", async function() {
it("can wait until a certificate is recovered", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(
`${certificatePrefix}-${this!.test!.title}-${certificateSuffix}`
);
@ -65,7 +67,7 @@ describe("Certificates client - LRO - recoverDelete", () => {
await testClient.flushCertificate(certificateName);
});
it("can resume from a stopped poller", async function() {
it("can resume from a stopped poller", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(
`${certificatePrefix}-${this!.test!.title}-${certificateSuffix}`
);
@ -112,7 +114,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", async function() {
it("can recover a deleted certificate with requestOptions timeout", /** @this Mocha.Context */ async function() {
recorder.skip(undefined, "Timeout tests don't work on playback mode.");
const certificateName = testClient.formatName(
`${certificatePrefix}-${this!.test!.title}-${certificateSuffix}`

Просмотреть файл

@ -24,16 +24,18 @@ describe("Certificates client - merge and import certificates", () => {
let credential: ClientSecretCredential;
let secretClient: SecretClient;
beforeEach(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(
/** @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);
}
);
afterEach(async function() {
await recorder.stop();
@ -41,7 +43,7 @@ describe("Certificates client - merge and import certificates", () => {
// The tests follow
it("can import a certificate from a certificate's non base64 secret value", async function() {
it("can import a certificate from a certificate's non base64 secret value", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const certificateNames = [`${certificateName}0`, `${certificateName}1`];
const createPoller = await client.beginCreateCertificate(
@ -65,7 +67,7 @@ describe("Certificates client - merge and import certificates", () => {
}
});
it("can import a certificate from a certificate's base64 secret value", async function() {
it("can import a certificate from a certificate's base64 secret value", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const certificateNames = [`${certificateName}0`, `${certificateName}1`];
const createPoller = await client.beginCreateCertificate(
@ -95,7 +97,9 @@ 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", async function(): Promise<void> {
it("can merge a self signed certificate", /** @this Mocha.Context */ async function(): Promise<
void
> {
recorder.skip(
undefined,
"The signed certificate will never be the same, so we can't play it back."

Просмотреть файл

@ -23,13 +23,15 @@ describe("Certificates client - restore certificates and recover backups", () =>
subject: "cn=MyCert"
};
beforeEach(async function() {
const authentication = await authenticate(this);
suffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
suffix = authentication.suffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -37,7 +39,7 @@ describe("Certificates client - restore certificates and recover backups", () =>
// The tests follow
it("can recover a deleted certificate", async function() {
it("can recover a deleted certificate", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const createPoller = await client.beginCreateCertificate(
certificateName,
@ -65,7 +67,7 @@ describe("Certificates client - restore certificates and recover backups", () =>
await testClient.flushCertificate(certificateName);
});
it("can recover a deleted certificate (non existing)", async function() {
it("can recover a deleted certificate (non existing)", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
let error;
try {
@ -81,7 +83,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", async function() {
it("can restore a certificate", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const createPoller = await client.beginCreateCertificate(
certificateName,
@ -141,7 +143,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", async function() {
it("can restore a key with requestOptions timeout", /** @this Mocha.Context */ async function() {
const certificateName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
const createPoller = await client.beginCreateCertificate(
certificateName,

Просмотреть файл

@ -54,6 +54,7 @@ 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,
@ -92,6 +93,7 @@ async function cancel(this: RestoreCertificateBackupPollOperation): Promise<neve
/**
* Serializes the create certificate's poll operation
* @this RestoreCertificateBackupPollOperation
*/
function toString(this: RestoreCertificateBackupPollOperation): string {
return JSON.stringify({

Просмотреть файл

@ -4,7 +4,6 @@
"ignorePatterns": ["src/core"],
"rules": {
"@typescript-eslint/no-this-alias": "off",
"no-invalid-this": "off",
"@azure/azure-sdk/ts-package-json-module": "warn",
"no-use-before-define": "warn"
}

Просмотреть файл

@ -19,7 +19,7 @@ import { RemoteCryptographyProvider } from "../../src/cryptography/remoteCryptog
import { ClientSecretCredential } from "@azure/identity";
describe("AesCryptographyProvider browser tests", function() {
it("uses the browser replacement when running in the browser", async function() {
it("uses the browser replacement when running in the browser", /** @this Mocha.Context */ async function() {
if (isNode) {
this.skip();
}
@ -43,23 +43,25 @@ describe("AesCryptographyProvider internal tests", function() {
const encryptionAlgorithm = `A${keySize}CBCPAD` as AesCbcEncryptionAlgorithm;
let jwk: JsonWebKey;
beforeEach(function() {
if (!isNode) {
this.skip();
beforeEach(
/** @this Mocha.Context */ function() {
if (!isNode) {
this.skip();
}
jwk = {
keyOps: ["encrypt", "decrypt", "wrapKey", "unwrapKey"],
k: getKey(keySize >> 3), // Generate a symmetric key for testing
kty: "oct"
};
cryptoClient = new CryptographyClient(jwk);
}
jwk = {
keyOps: ["encrypt", "decrypt", "wrapKey", "unwrapKey"],
k: getKey(keySize >> 3), // Generate a symmetric key for testing
kty: "oct"
};
cryptoClient = new CryptographyClient(jwk);
});
);
describe(`AES-CBC with PKCS padding (${keySize})`, () => {
describe("local-only tests", async function() {
it("encrypts and decrypts locally", async function() {
it("encrypts and decrypts locally", /** @this Mocha.Context */ async function() {
const text = this.test!.title;
const encryptResult = await cryptoClient.encrypt({
algorithm: encryptionAlgorithm,
@ -75,7 +77,7 @@ describe("AesCryptographyProvider internal tests", function() {
assert.equal(uint8ArrayToString(decryptResult.result), text);
});
it("validates the key type", async function() {
it("validates the key type", /** @this Mocha.Context */ async function() {
const text = this.test!.title;
jwk.kty = "RSA";
@ -98,7 +100,7 @@ describe("AesCryptographyProvider internal tests", function() {
);
});
it("validates the key length", async function() {
it("validates the key length", /** @this Mocha.Context */ async function() {
const text = this.test!.title;
jwk.k = getKey((keySize >> 3) - 1);
@ -132,27 +134,29 @@ describe("AesCryptographyProvider internal tests", function() {
let keyVaultKey: KeyVaultKey;
let remoteProvider: RemoteCryptographyProvider;
beforeEach(async function() {
const authentication = await authenticate(this);
recorder = authentication.recorder;
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();
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;
}
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", async function() {
it("encrypts locally and decrypts remotely", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this.test!.title}-${keySuffix}`);
keyVaultKey = await client.importKey(keyName, jwk, {});
remoteProvider = new RemoteCryptographyProvider(keyVaultKey, credential);
@ -174,7 +178,7 @@ describe("AesCryptographyProvider internal tests", function() {
await testClient.flushKey(keyName);
});
it("encrypts remotely and decrypts locally", async function() {
it("encrypts remotely and decrypts locally", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this.test!.title}-${keySuffix}`);
keyVaultKey = await client.importKey(keyName, jwk, {});
remoteProvider = new RemoteCryptographyProvider(keyVaultKey, credential);

Просмотреть файл

@ -26,13 +26,15 @@ describe("Challenge based authentication tests", () => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
keySuffix = authentication.keySuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
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 +42,7 @@ describe("Challenge based authentication tests", () => {
// The tests follow
it("Authentication should work for parallel requests", async function() {
it("Authentication should work for parallel requests", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
const keyNames = [`${keyName}-0`, `${keyName}-1`];
@ -71,7 +73,7 @@ describe("Challenge based authentication tests", () => {
sandbox.restore();
});
it("Once authenticated, new requests should not authenticate again", async function() {
it("Once authenticated, new requests should not authenticate again", /** @this Mocha.Context */ async function() {
// 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.

Просмотреть файл

@ -135,7 +135,7 @@ describe("internal crypto tests", () => {
});
describe("Encrypt parameter mapping", async function() {
it("maps parameters correctly when using the previous API", async function() {
it("maps parameters correctly when using the previous API", /** @this Mocha.Context */ async function() {
const text = stringToUint8Array(this.test!.title!);
await client.encrypt("RSA1_5", text, { requestOptions: { timeout: 5 } });
@ -146,7 +146,7 @@ describe("internal crypto tests", () => {
);
});
it("maps parameters correctly when using the current API", async function() {
it("maps parameters correctly when using the current API", /** @this Mocha.Context */ async function() {
const text = stringToUint8Array(this.test!.title!);
await client.encrypt(
@ -163,7 +163,7 @@ describe("internal crypto tests", () => {
});
describe("Decrypt parameter mapping", async function() {
it("maps parameters correctly when using the previous API", async function() {
it("maps parameters correctly when using the previous API", /** @this Mocha.Context */ async function() {
const text = stringToUint8Array(this.test!.title!);
await client.decrypt("RSA1_5", text, { requestOptions: { timeout: 5 } });
@ -174,7 +174,7 @@ describe("internal crypto tests", () => {
);
});
it("maps parameters correctly when using the current API", async function() {
it("maps parameters correctly when using the current API", /** @this Mocha.Context */ async function() {
const text = stringToUint8Array(this.test!.title!);
await client.decrypt(
@ -192,7 +192,7 @@ describe("internal crypto tests", () => {
});
describe("RSA local cryptography tests", function() {
it("throws a validation error when the key is invalid", function() {
it("throws a validation error when the key is invalid", /** @this Mocha.Context */ function() {
if (!isNode) {
// Local cryptography is not supported in the browser
this.skip();
@ -204,7 +204,7 @@ describe("internal crypto tests", () => {
);
});
it("uses the browser replacement when running in the browser", function() {
it("uses the browser replacement when running in the browser", /** @this Mocha.Context */ function() {
if (isNode) {
this.skip();
}

Просмотреть файл

@ -13,7 +13,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)", async function() {
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() {
if (!isNode) {
this.skip();
return;

Просмотреть файл

@ -16,26 +16,28 @@ describe("Keys client - create, read, update and delete operations for managed H
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
recorder = authentication.recorder;
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();
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);
}
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", async function() {
it("can create an OCT key with options", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
const options: CreateOctKeyOptions = {
hsm: true

Просмотреть файл

@ -24,13 +24,15 @@ describe("Keys client - create, read, update and delete operations", () => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
keySuffix = authentication.keySuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
keySuffix = authentication.keySuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -38,7 +40,7 @@ describe("Keys client - create, read, update and delete operations", () => {
// The tests follow
it("can create a key while giving a manual type", async function() {
it("can create a key while giving a manual type", /** @this Mocha.Context */ async function() {
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().");
@ -46,7 +48,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", async function() {
it("can abort creating a key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
const controller = new AbortController();
@ -60,7 +62,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", async function() {
it("can create a key with requestOptions timeout", /** @this Mocha.Context */ async function() {
recorder.skip(undefined, "Timeout tests don't work on playback mode.");
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
await assertThrowsAbortError(async () => {
@ -88,14 +90,14 @@ describe("Keys client - create, read, update and delete operations", () => {
);
});
it("can create a RSA key", async function() {
it("can create a RSA key", /** @this Mocha.Context */ async function() {
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", async function() {
it("can create a RSA key with size", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
const options = {
keySize: 2048
@ -105,7 +107,7 @@ describe("Keys client - create, read, update and delete operations", () => {
await testClient.flushKey(keyName);
});
it("can create a RSA key with public exponent", async function() {
it("can create a RSA key with public exponent", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
const options = {
publicExponent: 3
@ -116,7 +118,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", async function() {
it("can create a RSA key with requestOptions timeout", /** @this Mocha.Context */ async function() {
recorder.skip(undefined, "Timeout tests don't work on playback mode.");
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
@ -129,14 +131,14 @@ describe("Keys client - create, read, update and delete operations", () => {
});
});
it("can create an EC key", async function() {
it("can create an EC key", /** @this Mocha.Context */ async function() {
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", async function() {
it("can create an EC key with curve", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
const options: CreateEcKeyOptions = {
curve: "P-256"
@ -147,7 +149,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", async function() {
it("can create an EC key with requestOptions timeout", /** @this Mocha.Context */ async function() {
recorder.skip(undefined, "Timeout tests don't work on playback mode.");
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
await assertThrowsAbortError(async () => {
@ -159,7 +161,7 @@ describe("Keys client - create, read, update and delete operations", () => {
});
});
it("can create a disabled key", async function() {
it("can create a disabled key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
const options = {
enabled: false
@ -169,7 +171,7 @@ describe("Keys client - create, read, update and delete operations", () => {
await testClient.flushKey(keyName);
});
it("can create a key with notBefore", async function() {
it("can create a key with notBefore", /** @this Mocha.Context */ async function() {
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
@ -187,7 +189,7 @@ describe("Keys client - create, read, update and delete operations", () => {
await testClient.flushKey(keyName);
});
it("can create a key with expires", async function() {
it("can create a key with expires", /** @this Mocha.Context */ async function() {
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
@ -205,7 +207,7 @@ describe("Keys client - create, read, update and delete operations", () => {
await testClient.flushKey(keyName);
});
it("can update key", async function() {
it("can update key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
const { version } = (await client.createRsaKey(keyName)).properties;
const options: UpdateKeyPropertiesOptions = { enabled: false };
@ -214,7 +216,7 @@ describe("Keys client - create, read, update and delete operations", () => {
await testClient.flushKey(keyName);
});
it("can update a disabled key", async function() {
it("can update a disabled key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
const createOptions = {
enabled: false
@ -233,7 +235,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", async function() {
it("can update key with requestOptions timeout", /** @this Mocha.Context */ async function() {
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;
@ -246,7 +248,7 @@ describe("Keys client - create, read, update and delete operations", () => {
});
});
it("can delete a key", async function() {
it("can delete a key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
await client.createKey(keyName, "RSA");
const poller = await client.beginDeleteKey(keyName, testPollerProperties);
@ -267,7 +269,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", async function() {
it("can delete a key with requestOptions timeout", /** @this Mocha.Context */ async function() {
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");
@ -281,7 +283,7 @@ describe("Keys client - create, read, update and delete operations", () => {
});
});
it("delete nonexisting key", async function() {
it("delete nonexisting key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
try {
await client.getKey(keyName);
@ -296,7 +298,7 @@ describe("Keys client - create, read, update and delete operations", () => {
}
});
it("can get a key", async function() {
it("can get a key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
await client.createKey(keyName, "RSA");
const getResult = await client.getKey(keyName);
@ -305,7 +307,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", async function() {
it("can get a key with requestOptions timeout", /** @this Mocha.Context */ async function() {
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");
@ -314,7 +316,7 @@ describe("Keys client - create, read, update and delete operations", () => {
});
});
it("can get a specific version of a key", async function() {
it("can get a specific version of a key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
const { version } = (await client.createKey(keyName, "RSA")).properties;
const options: GetKeyOptions = { version };
@ -327,7 +329,7 @@ describe("Keys client - create, read, update and delete operations", () => {
await testClient.flushKey(keyName);
});
it("can get a deleted key", async function() {
it("can get a deleted key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
await client.createKey(keyName, "RSA");
const poller = await client.beginDeleteKey(keyName, testPollerProperties);
@ -348,7 +350,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", async function() {
it("can't get a deleted key that doesn't exist", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
let error;
try {
@ -362,7 +364,7 @@ describe("Keys client - create, read, update and delete operations", () => {
assert.equal(error.statusCode, 404);
});
it("can purge a deleted key", async function() {
it("can purge a deleted key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
await client.createKey(keyName, "RSA");
const poller = await client.beginDeleteKey(keyName, testPollerProperties);

Просмотреть файл

@ -20,22 +20,24 @@ describe("CryptographyClient for managed HSM (skipped if MHSM is not deployed)",
let keyVaultKey: KeyVaultKey;
let keySuffix: string;
beforeEach(async function() {
const authentication = await authenticate(this);
recorder = authentication.recorder;
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();
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);
}
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);
@ -43,7 +45,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", async function() {
it("encrypts and decrypts using AES-GCM", /** @this Mocha.Context */ async function() {
keyVaultKey = await hsmClient.createKey(keyName, "AES", { keySize: 256 });
cryptoClient = new CryptographyClient(keyVaultKey.id!, credential);
const text = this.test!.title;
@ -63,7 +65,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", async function() {
it("encrypts and decrypts using AES-CBC", /** @this Mocha.Context */ async function() {
keyVaultKey = await hsmClient.createKey(keyName, "AES", { keySize: 256 });
cryptoClient = new CryptographyClient(keyVaultKey.id!, credential);
const text = this.test!.title;

Просмотреть файл

@ -29,29 +29,33 @@ describe("CryptographyClient (all decrypts happen remotely)", () => {
return;
}
beforeEach(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);
});
afterEach(async function() {
if (!this.currentTest?.isPending()) {
await testClient.flushKey(keyName);
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);
}
await recorder.stop();
});
);
afterEach(
/** @this Mocha.Context */ async function() {
if (!this.currentTest?.isPending()) {
await testClient.flushKey(keyName);
}
await recorder.stop();
}
);
// The tests follow
if (!isPlaybackMode()) {
it("encrypt & decrypt with RSA1_5", async function() {
it("encrypt & decrypt with RSA1_5", /** @this Mocha.Context */ async function() {
const text = this.test!.title;
const encryptResult = await cryptoClient.encrypt({
algorithm: "RSA1_5",
@ -65,7 +69,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => {
assert.equal(text, decryptedText);
});
it("manually encrypt locally and decrypt remotely, both with RSA1_5", async function() {
it("manually encrypt locally and decrypt remotely, both with RSA1_5", /** @this Mocha.Context */ async function() {
const text = this.test!.title;
const localProvider = new RsaCryptographyProvider(keyVaultKey.key!);
const encryptResult = await localProvider.encrypt({
@ -80,7 +84,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => {
assert.equal(text, decryptedText);
});
it("encrypt & decrypt with RSA-OAEP", async function() {
it("encrypt & decrypt with RSA-OAEP", /** @this Mocha.Context */ async function() {
const text = this.test!.title;
const encryptResult = await cryptoClient.encrypt(
{
@ -97,7 +101,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => {
assert.equal(text, decryptedText);
});
it("manually encrypt locally and decrypt remotely, both with RSA-OAEP", async function() {
it("manually encrypt locally and decrypt remotely, both with RSA-OAEP", /** @this Mocha.Context */ async function() {
const text = this.test!.title;
const localProvider = new RsaCryptographyProvider(keyVaultKey.key!);
const encryptResult = await localProvider.encrypt({
@ -112,7 +116,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => {
assert.equal(text, decryptedText);
});
it("the CryptographyClient can be created from a full KeyVaultKey object", async function() {
it("the CryptographyClient can be created from a full KeyVaultKey object", /** @this Mocha.Context */ async function() {
const customKeyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
const customKeyVaultKey = await client.createKey(customKeyName, "RSA");
const cryptoClientFromKey = new CryptographyClient(customKeyVaultKey, credential);
@ -162,7 +166,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => {
assert.equal("RSA1_5", unwrappedResult.algorithm);
});
it("wrap and unwrap with RSA-OAEP", async function() {
it("wrap and unwrap with RSA-OAEP", /** @this Mocha.Context */ async function() {
recorder.skip(
undefined,
"Wrapping and unwrapping don't cause a repeatable pattern, so these tests can only run in playback mode"
@ -176,7 +180,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => {
});
if (!isPlaybackMode()) {
it("encrypt & decrypt with an RSA-HSM key and the RSA-OAEP algorithm", async function() {
it("encrypt & decrypt with an RSA-HSM key and the RSA-OAEP algorithm", /** @this Mocha.Context */ async function() {
const hsmKeyName = keyName + "2";
const hsmKey = await client.createKey(hsmKeyName, "RSA-HSM");
const hsmCryptoClient = new CryptographyClient(hsmKey.id!, credential);
@ -188,7 +192,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => {
await testClient.flushKey(hsmKeyName);
});
it("encrypt & decrypt with an RSA-HSM key and the RSA1_5 algorithm", async function() {
it("encrypt & decrypt with an RSA-HSM key and the RSA1_5 algorithm", /** @this Mocha.Context */ async function() {
const hsmKeyName = keyName + "2";
const hsmKey = await client.createKey(hsmKeyName, "RSA-HSM");
const hsmCryptoClient = new CryptographyClient(hsmKey.id!, credential);
@ -201,7 +205,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => {
});
}
it("wrap and unwrap with RSA-OAEP on a RSA-HSM key", async function() {
it("wrap and unwrap with RSA-OAEP on a RSA-HSM key", /** @this Mocha.Context */ async function() {
recorder.skip(
undefined,
"Wrapping and unwrapping don't cause a repeatable pattern, so this test can only run live"
@ -217,7 +221,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => {
await testClient.flushKey(hsmKeyName);
});
it("wrap and unwrap with RSA1_5 on a RSA-HSM key", async function() {
it("wrap and unwrap with RSA1_5 on a RSA-HSM key", /** @this Mocha.Context */ async function() {
recorder.skip(
undefined,
"Wrapping and unwrapping don't cause a repeatable pattern, so this test can only run live"
@ -233,7 +237,9 @@ describe("CryptographyClient (all decrypts happen remotely)", () => {
await testClient.flushKey(hsmKeyName);
});
it("sign and verify with RS256 through an RSA-HSM key", async function(): Promise<void> {
it("sign and verify with RS256 through an RSA-HSM key", /** @this Mocha.Context */ async function(): Promise<
void
> {
const hsmKeyName = keyName + "2";
const hsmKey = await client.createKey(hsmKeyName, "RSA-HSM");
const hsmCryptoClient = new CryptographyClient(hsmKey.id!, credential);
@ -264,7 +270,9 @@ describe("CryptographyClient (all decrypts happen remotely)", () => {
await testClient.flushKey(hsmKeyName);
});
it("sign and verify with RS384 through an RSA-HSM key", async function(): Promise<void> {
it("sign and verify with RS384 through an RSA-HSM key", /** @this Mocha.Context */ async function(): Promise<
void
> {
const hsmKeyName = keyName + "2";
const hsmKey = await client.createKey(hsmKeyName, "RSA-HSM");
const hsmCryptoClient = new CryptographyClient(hsmKey.id!, credential);

Просмотреть файл

@ -16,13 +16,15 @@ describe("Keys client - import keys", () => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
suffix = authentication.keySuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
suffix = authentication.keySuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -30,7 +32,7 @@ describe("Keys client - import keys", () => {
// The tests follow
it("can import a key", async function() {
it("can import a key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${prefix}-${this!.test!.title}-${suffix}`);
function toBytes(hex: string): Uint8Array {
if (hex.length % 2) {

Просмотреть файл

@ -20,13 +20,15 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this, serviceVersion);
keySuffix = authentication.keySuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.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;
}
);
afterEach(async function() {
await recorder.stop();
@ -37,7 +39,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", async function(): Promise<void> {
it("can purge all keys", /** @this Mocha.Context */ async function(): Promise<void> {
// 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();
@ -58,7 +60,7 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => {
}
});
it("can get the versions of a key", async function() {
it("can get the versions of a key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
await client.createKey(keyName, "RSA");
let totalVersions = 0;
@ -85,7 +87,7 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => {
});
});
it("can get the versions of a key (paged)", async function() {
it("can get the versions of a key (paged)", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
await client.createKey(keyName, "RSA");
let totalVersions = 0;
@ -103,7 +105,7 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => {
await testClient.flushKey(keyName);
});
it("list 0 versions of a non-existing key", async function() {
it("list 0 versions of a non-existing key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
let totalVersions = 0;
for await (const version of client.listPropertiesOfKeyVersions(keyName)) {
@ -117,7 +119,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)", async function() {
it("list 0 versions of a non-existing key (paged)", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
let totalVersions = 0;
for await (const page of client.listPropertiesOfKeyVersions(keyName).byPage()) {
@ -133,7 +135,7 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => {
assert.equal(totalVersions, 0, `Unexpected total versions for key ${keyName}`);
});
it("can get several inserted keys", async function() {
it("can get several inserted keys", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
const keyNames = [`${keyName}-0`, `${keyName}-1`];
for (const name of keyNames) {
@ -164,7 +166,7 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => {
});
});
it("can get several inserted keys (paged)", async function() {
it("can get several inserted keys (paged)", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
const keyNames = [`${keyName}-0`, `${keyName}-1`];
for (const name of keyNames) {
@ -187,7 +189,7 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => {
}
});
it("list deleted keys", async function() {
it("list deleted keys", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
const keyNames = [`${keyName}-0`, `${keyName}-1`];
for (const name of keyNames) {
@ -221,7 +223,7 @@ versionsToTest(serviceApiVersions, {}, (serviceVersion, onVersions) => {
});
});
it("list deleted keys (paged)", async function() {
it("list deleted keys (paged)", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
const keyNames = [`${keyName}-0`, `${keyName}-1`];
for (const name of keyNames) {

Просмотреть файл

@ -33,14 +33,16 @@ describe("Local cryptography public tests", () => {
return;
}
beforeEach(async function() {
const authentication = await authenticate(this);
client = authentication.client;
recorder = authentication.recorder;
testClient = authentication.testClient;
credential = authentication.credential;
keySuffix = authentication.keySuffix;
});
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;
}
);
afterEach(async function() {
await recorder.stop();
@ -51,11 +53,13 @@ describe("Local cryptography public tests", () => {
let customKeyVaultKey: KeyVaultKey;
let cryptoClientFromKey: CryptographyClient;
beforeEach(async function() {
customKeyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
customKeyVaultKey = await client.createKey(customKeyName, "RSA");
cryptoClientFromKey = new CryptographyClient(customKeyVaultKey.key!);
});
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!);
}
);
it("the CryptographyClient can be created from a local JsonWebKey object", async function() {
assert.isEmpty(cryptoClientFromKey.vaultUrl);
@ -123,7 +127,7 @@ describe("Local cryptography public tests", () => {
});
});
it("encrypt & decrypt RSA1_5", async function() {
it("encrypt & decrypt RSA1_5", /** @this Mocha.Context */ async function() {
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");
@ -137,7 +141,7 @@ describe("Local cryptography public tests", () => {
await testClient.flushKey(keyName);
});
it("encrypt & decrypt RSA-OAEP", async function() {
it("encrypt & decrypt RSA-OAEP", /** @this Mocha.Context */ async function() {
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");
@ -151,7 +155,7 @@ describe("Local cryptography public tests", () => {
await testClient.flushKey(keyName);
});
it("wrapKey & unwrapKey RSA1_5", async function() {
it("wrapKey & unwrapKey RSA1_5", /** @this Mocha.Context */ async function() {
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");
@ -168,7 +172,7 @@ describe("Local cryptography public tests", () => {
await testClient.flushKey(keyName);
});
it("wrapKey & unwrapKey RSA-OAEP", async function() {
it("wrapKey & unwrapKey RSA-OAEP", /** @this Mocha.Context */ async function() {
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");
@ -190,35 +194,43 @@ describe("Local cryptography public tests", () => {
const localSupportedAlgorithmNames = Object.keys(rsaProvider.signatureAlgorithmToHashAlgorithm);
for (const localAlgorithmName of localSupportedAlgorithmNames) {
it(localAlgorithmName, async function(): Promise<void> {
recorder.skip(
"browser",
`Local sign of algorithm ${localAlgorithmName} is only supported in NodeJS`
);
it(
localAlgorithmName,
/** @this Mocha.Context */ async function(): Promise<void> {
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);
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);
// 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);
// 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);
});
await testClient.flushKey(keyName);
}
);
}
});
});

Просмотреть файл

@ -17,13 +17,15 @@ describe("Keys client - Long Running Operations - delete", () => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
keySuffix = authentication.keySuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
keySuffix = authentication.keySuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -31,7 +33,7 @@ describe("Keys client - Long Running Operations - delete", () => {
// The tests follow
it("can wait until a key is deleted", async function() {
it("can wait until a key is deleted", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
await client.createKey(keyName, "RSA");
const poller = await client.beginDeleteKey(keyName, testPollerProperties);
@ -50,7 +52,7 @@ describe("Keys client - Long Running Operations - delete", () => {
await testClient.purgeKey(keyName);
});
it("can resume from a stopped poller", async function() {
it("can resume from a stopped poller", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
await client.createKey(keyName, "RSA");
const poller = await client.beginDeleteKey(keyName, testPollerProperties);

Просмотреть файл

@ -18,13 +18,15 @@ describe("Keys client - Long Running Operations - recoverDelete", () => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
keySuffix = authentication.keySuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
keySuffix = authentication.keySuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -32,7 +34,7 @@ describe("Keys client - Long Running Operations - recoverDelete", () => {
// The tests follow
it("can wait until a key is recovered", async function() {
it("can wait until a key is recovered", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
await client.createKey(keyName, "RSA");
@ -55,7 +57,7 @@ describe("Keys client - Long Running Operations - recoverDelete", () => {
await testClient.flushKey(keyName);
});
it("can resume from a stopped poller", async function() {
it("can resume from a stopped poller", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
await client.createKey(keyName, "RSA");
const deletePoller = await client.beginDeleteKey(keyName, testPollerProperties);
@ -92,7 +94,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", async function() {
it("can recover a deleted key with requestOptions timeout", /** @this Mocha.Context */ async function() {
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");

Просмотреть файл

@ -17,13 +17,15 @@ describe("Keys client - restore keys and recover backups", () => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
keySuffix = authentication.keySuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
keySuffix = authentication.keySuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -31,7 +33,7 @@ describe("Keys client - restore keys and recover backups", () => {
// The tests follow
it("can recover a deleted key", async function() {
it("can recover a deleted key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
await client.createKey(keyName, "RSA");
const deletePoller = await client.beginDeleteKey(keyName, testPollerProperties);
@ -52,7 +54,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", async function() {
it("fails if one tries to recover a non-existing deleted key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
let error;
try {
@ -66,7 +68,7 @@ describe("Keys client - restore keys and recover backups", () => {
assert.equal(error.statusCode, 404);
});
it("can generate a backup of a key", async function() {
it("can generate a backup of a key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
await client.createKey(keyName, "RSA");
const result = await client.backupKey(keyName);
@ -87,7 +89,7 @@ describe("Keys client - restore keys and recover backups", () => {
});
});
it("fails to generate a backup of a non-existing key", async function() {
it("fails to generate a backup of a non-existing key", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
let error;
try {
@ -103,7 +105,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", async function() {
it("can restore a key with a given backup", /** @this Mocha.Context */ async function() {
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
await client.createKey(keyName, "RSA");
const backup = await client.backupKey(keyName);
@ -126,7 +128,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", async function() {
it("can restore a key with requestOptions timeout", /** @this Mocha.Context */ async function() {
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");

Просмотреть файл

@ -53,6 +53,7 @@ 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,
@ -91,6 +92,7 @@ async function cancel(this: RestoreKeyBackupPollOperation): Promise<never> {
/**
* Serializes the create key's poll operation
* @this RestoreKeyBackupPollOperation
*/
function toString(this: RestoreKeyBackupPollOperation): string {
return JSON.stringify({

Просмотреть файл

@ -4,7 +4,6 @@
"ignorePatterns": ["src/core"],
"rules": {
"@typescript-eslint/no-this-alias": "off",
"no-invalid-this": "off",
"@azure/azure-sdk/ts-package-json-module": "warn",
"no-use-before-define": "warn"
}

Просмотреть файл

@ -26,13 +26,15 @@ describe("Challenge based authentication tests", () => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
secretSuffix = authentication.secretSuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
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 +42,7 @@ describe("Challenge based authentication tests", () => {
// The tests follow
it("Authentication should work for parallel requests", async function() {
it("Authentication should work for parallel requests", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -73,7 +75,7 @@ describe("Challenge based authentication tests", () => {
sandbox.restore();
});
it("Once authenticated, new requests should not authenticate again", async function() {
it("Once authenticated, new requests should not authenticate again", /** @this Mocha.Context */ async function() {
// 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.

Просмотреть файл

@ -13,7 +13,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)", async function() {
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() {
if (!isNode) {
this.skip();
return;

Просмотреть файл

@ -19,13 +19,15 @@ describe("Secret client - create, read, update and delete operations", () => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
secretSuffix = authentication.secretSuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
secretSuffix = authentication.secretSuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -33,7 +35,7 @@ describe("Secret client - create, read, update and delete operations", () => {
// The tests follow
it("can add a secret", async function() {
it("can add a secret", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -45,7 +47,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", async function() {
it("can abort adding a secret", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -59,7 +61,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", async function() {
it("can timeout adding a secret", /** @this Mocha.Context */ async function() {
recorder.skip(undefined, "Timeout tests don't work on playback mode.");
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
@ -89,7 +91,7 @@ describe("Secret client - create, read, update and delete operations", () => {
);
});
it("can set a secret with Empty Value", async function() {
it("can set a secret with Empty Value", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -104,7 +106,7 @@ describe("Secret client - create, read, update and delete operations", () => {
await testClient.flushSecret(secretName);
});
it("can set a secret with attributes", async function() {
it("can set a secret with attributes", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -120,7 +122,7 @@ describe("Secret client - create, read, update and delete operations", () => {
await testClient.flushSecret(secretName);
});
it("can update a secret", async function() {
it("can update a secret", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -142,7 +144,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", async function() {
it("can timeout updating a secret", /** @this Mocha.Context */ async function() {
recorder.skip(undefined, "Timeout tests don't work on playback mode.");
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
@ -161,7 +163,7 @@ describe("Secret client - create, read, update and delete operations", () => {
});
});
it("can update a disabled secret", async function() {
it("can update a disabled secret", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -182,7 +184,7 @@ describe("Secret client - create, read, update and delete operations", () => {
await testClient.flushSecret(secretName);
});
it("can get a secret", async function() {
it("can get a secret", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -194,7 +196,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", async function() {
it("can timeout getting a secret", /** @this Mocha.Context */ async function() {
recorder.skip(undefined, "Timeout tests don't work on playback mode.");
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
@ -209,7 +211,7 @@ describe("Secret client - create, read, update and delete operations", () => {
});
});
it("can't get a disabled secret", async function() {
it("can't get a disabled secret", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -234,7 +236,7 @@ describe("Secret client - create, read, update and delete operations", () => {
await testClient.flushSecret(secretName);
});
it("can retrieve the latest version of a secret value", async function() {
it("can retrieve the latest version of a secret value", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -247,7 +249,7 @@ describe("Secret client - create, read, update and delete operations", () => {
await testClient.flushSecret(secretName);
});
it("can get a secret (Non Existing)", async function() {
it("can get a secret (Non Existing)", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -262,7 +264,7 @@ describe("Secret client - create, read, update and delete operations", () => {
assert.equal(error.statusCode, 404);
});
it("can delete a secret", async function() {
it("can delete a secret", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -293,7 +295,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", async function() {
it("can timeout deleting a secret", /** @this Mocha.Context */ async function() {
recorder.skip(undefined, "Timeout tests don't work on playback mode.");
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
@ -309,7 +311,7 @@ describe("Secret client - create, read, update and delete operations", () => {
});
});
it("can delete a secret (Non Existing)", async function() {
it("can delete a secret (Non Existing)", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -324,7 +326,7 @@ describe("Secret client - create, read, update and delete operations", () => {
assert.equal(error.statusCode, 404);
});
it("can get a deleted secret", async function() {
it("can get a deleted secret", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -351,7 +353,7 @@ describe("Secret client - create, read, update and delete operations", () => {
await testClient.purgeSecret(secretName);
});
it("can get a deleted secret (Non Existing)", async function() {
it("can get a deleted secret (Non Existing)", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);

Просмотреть файл

@ -21,13 +21,15 @@ describe("Secret client - list secrets in various ways", () => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
secretSuffix = authentication.secretSuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
secretSuffix = authentication.secretSuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -38,7 +40,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", async function(): Promise<void> {
it("can purge all secrets", /** @this Mocha.Context */ async function(): Promise<void> {
// 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();
@ -59,7 +61,7 @@ describe("Secret client - list secrets in various ways", () => {
}
});
it("can list secret properties", async function() {
it("can list secret properties", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -83,7 +85,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", async function() {
it("can get secret properties with requestOptions timeout", /** @this Mocha.Context */ async function() {
recorder.skip(undefined, "Timeout tests don't work on playback mode.");
const iter = client.listPropertiesOfSecrets({
requestOptions: { timeout: 1 }
@ -93,7 +95,7 @@ describe("Secret client - list secrets in various ways", () => {
});
});
it("can list deleted secrets", async function() {
it("can list deleted secrets", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -132,7 +134,7 @@ describe("Secret client - list secrets in various ways", () => {
});
});
it("can retrieve all versions of a secret", async function() {
it("can retrieve all versions of a secret", /** @this Mocha.Context */ async function() {
recorder.skip(undefined, "Timeout tests don't work on playback mode.");
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
@ -175,7 +177,7 @@ describe("Secret client - list secrets in various ways", () => {
});
});
it("can list secret versions (non existing)", async function() {
it("can list secret versions (non existing)", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -191,7 +193,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", async function() {
it("can list secrets by page", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -213,7 +215,7 @@ describe("Secret client - list secrets in various ways", () => {
}
});
it("can list deleted secrets by page", async function() {
it("can list deleted secrets by page", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -240,7 +242,7 @@ describe("Secret client - list secrets in various ways", () => {
}
});
it("can retrieve all versions of a secret by page", async function() {
it("can retrieve all versions of a secret by page", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -273,7 +275,7 @@ describe("Secret client - list secrets in various ways", () => {
await testClient.flushSecret(secretName);
});
it("can list secret versions by page (non existing)", async function() {
it("can list secret versions by page (non existing)", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);

Просмотреть файл

@ -18,13 +18,15 @@ describe("Secrets client - Long Running Operations - delete", () => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
secretSuffix = authentication.secretSuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
secretSuffix = authentication.secretSuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -32,7 +34,7 @@ describe("Secrets client - Long Running Operations - delete", () => {
// The tests follow
it("can wait until a secret is deleted", async function() {
it("can wait until a secret is deleted", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -53,7 +55,7 @@ describe("Secrets client - Long Running Operations - delete", () => {
await testClient.purgeSecret(secretName);
});
it("can resume from a stopped poller", async function() {
it("can resume from a stopped poller", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -87,7 +89,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", async function() {
it("can attempt to delete a secret with requestOptions timeout", /** @this Mocha.Context */ async function() {
recorder.skip(undefined, "Timeout tests don't work on playback mode.");
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`

Просмотреть файл

@ -18,13 +18,15 @@ describe("Secrets client - Long Running Operations - recoverDelete", () => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
secretSuffix = authentication.secretSuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
secretSuffix = authentication.secretSuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -32,7 +34,7 @@ describe("Secrets client - Long Running Operations - recoverDelete", () => {
// The tests follow
it("can wait until a secret is recovered", async function() {
it("can wait until a secret is recovered", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -57,7 +59,7 @@ describe("Secrets client - Long Running Operations - recoverDelete", () => {
await testClient.flushSecret(secretName);
});
it("can resume from a stopped poller", async function() {
it("can resume from a stopped poller", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -96,7 +98,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", async function() {
it("can attempt to recover a deleted secret with requestOptions timeout", /** @this Mocha.Context */ async function() {
recorder.skip(undefined, "Timeout tests don't work on playback mode.");
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`

Просмотреть файл

@ -18,13 +18,15 @@ describe("Secret client - restore secrets and recover backups", () => {
let testClient: TestClient;
let recorder: Recorder;
beforeEach(async function() {
const authentication = await authenticate(this);
secretSuffix = authentication.secretSuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});
beforeEach(
/** @this Mocha.Context */ async function() {
const authentication = await authenticate(this);
secretSuffix = authentication.secretSuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
}
);
afterEach(async function() {
await recorder.stop();
@ -32,7 +34,7 @@ describe("Secret client - restore secrets and recover backups", () => {
// The tests follow
it("can recover a deleted secret", async function() {
it("can recover a deleted secret", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -62,7 +64,7 @@ describe("Secret client - restore secrets and recover backups", () => {
await testClient.flushSecret(secretName);
});
it("can recover a deleted secret (non existing)", async function() {
it("can recover a deleted secret (non existing)", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -83,7 +85,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", async function() {
it("can recover a deleted a secret with requestOptions timeout", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -101,7 +103,7 @@ describe("Secret client - restore secrets and recover backups", () => {
});
}
it("can backup a secret", async function() {
it("can backup a secret", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -119,7 +121,7 @@ describe("Secret client - restore secrets and recover backups", () => {
await testClient.flushSecret(secretName);
});
it("can backup a secret (non existing)", async function() {
it("can backup a secret (non existing)", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -137,7 +139,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", async function() {
it("can restore a secret", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
@ -182,7 +184,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", async function() {
it("can timeout deleting a secret", /** @this Mocha.Context */ async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);

Просмотреть файл

@ -54,6 +54,7 @@ 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,
@ -92,6 +93,7 @@ async function cancel(this: RestoreSecretBackupPollOperation): Promise<never> {
/**
* Serializes the create secret's poll operation
* @this RestoreSecretBackupPollOperation
*/
function toString(this: RestoreSecretBackupPollOperation): string {
return JSON.stringify({

Просмотреть файл

@ -19,10 +19,11 @@ matrix([[true, false]] as const, async (useAad) => {
let client: MetricsAdvisorAdministrationClient;
let recorder: Recorder;
beforeEach(function() {
// eslint-disable-next-line no-invalid-this
({ recorder, client } = createRecordedAdminClient(this, makeCredential(useAad)));
});
beforeEach(
/** @this Mocha.Context */ function() {
({ recorder, client } = createRecordedAdminClient(this, makeCredential(useAad)));
}
);
afterEach(async function() {
if (recorder) {
@ -78,7 +79,7 @@ matrix([[true, false]] as const, async (useAad) => {
assert.ok(result.latestActiveTimestamp, "Expecting valid latest active timestamp");
});
it("refreshes ingesetion status", async function() {
it("refreshes ingesetion status", /** @this Mocha.Context */ async function() {
const iterator = client.listDataFeedIngestionStatus(
testEnv.METRICS_ADVISOR_AZURE_SQLSERVER_DATAFEED_ID,
new Date(Date.UTC(2020, 7, 22)),
@ -101,7 +102,6 @@ matrix([[true, false]] as const, async (useAad) => {
const result2 = await iterator2.next();
assert.notEqual(result2.value.status, "Succeeded");
} else {
// eslint-disable-next-line no-invalid-this
this.skip();
}
});
@ -368,9 +368,8 @@ matrix([[true, false]] as const, async (useAad) => {
}
});
it("deletes an alert configuration", async function() {
it("deletes an alert configuration", /** @this Mocha.Context */ async function() {
if (!createdAlertConfigId) {
// eslint-disable-next-line no-invalid-this
this.skip();
}
@ -383,9 +382,8 @@ matrix([[true, false]] as const, async (useAad) => {
}
});
it("deletes a detection configuration", async function() {
it("deletes a detection configuration", /** @this Mocha.Context */ async function() {
if (!createdDetectionConfigId) {
// eslint-disable-next-line no-invalid-this
this.skip();
}

Просмотреть файл

@ -20,10 +20,11 @@ matrix([[true, false]] as const, async (useAad) => {
let client: MetricsAdvisorClient;
let recorder: Recorder;
beforeEach(function() {
// eslint-disable-next-line no-invalid-this
({ recorder, client } = createRecordedAdvisorClient(this, makeCredential(useAad)));
});
beforeEach(
/** @this Mocha.Context */ function() {
({ recorder, client } = createRecordedAdvisorClient(this, makeCredential(useAad)));
}
);
afterEach(async function() {
if (recorder) {

Просмотреть файл

@ -24,16 +24,17 @@ matrix([[true, false]] as const, async (useAad) => {
let emailHookName: string;
let webHookName: string;
beforeEach(function() {
// eslint-disable-next-line no-invalid-this
({ recorder, client } = createRecordedAdminClient(this, makeCredential(useAad)));
if (recorder && !emailHookName) {
emailHookName = recorder.getUniqueName("js-test-emailHook-");
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-");
}
}
if (recorder && !webHookName) {
webHookName = recorder.getUniqueName("js-test-webHook-");
}
});
);
afterEach(async function() {
if (recorder) {

Просмотреть файл

@ -77,11 +77,12 @@ describe("[AccountKey] MixedRealityStsClient functional tests", function() {
let client: MixedRealityStsClient;
let recorder: Recorder;
beforeEach(function() {
// eslint-disable-next-line no-invalid-this
recorder = createRecorder(this);
client = createClient();
});
beforeEach(
/** @this Mocha.Context */ function() {
recorder = createRecorder(this);
client = createClient();
}
);
afterEach(async function() {
// Stop the recording.

Просмотреть файл

@ -62,10 +62,11 @@ describe("SchemaRegistryClient", function() {
let recorder: Recorder;
let client: SchemaRegistryClient;
beforeEach(function() {
// eslint-disable-next-line no-invalid-this
({ client, recorder } = createRecordedClient(this));
});
beforeEach(
/** @this Mocha.Context */ function() {
({ client, recorder } = createRecordedClient(this));
}
);
afterEach(async function() {
await recorder.stop();

Просмотреть файл

@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
"extends": ["../../../tsdoc.json"]
}

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/* eslint-disable no-invalid-this */
import { assert } from "chai";
import { Recorder, record, isPlaybackMode, isLiveMode } from "@azure/test-utils-recorder";
@ -20,24 +18,26 @@ import { delay } from "@azure/core-http";
const TEST_INDEX_NAME = isLiveMode() ? createRandomIndexName() : "hotel-live-test1";
describe("SearchClient", function() {
describe("SearchClient", /** @this Mocha.Context */ function() {
let recorder: Recorder;
let searchClient: SearchClient<Hotel>;
let indexClient: SearchIndexClient;
this.timeout(99999);
beforeEach(async function() {
({ searchClient, indexClient } = createClients<Hotel>(TEST_INDEX_NAME));
if (!isPlaybackMode()) {
await createIndex(indexClient, TEST_INDEX_NAME);
await delay(WAIT_TIME);
await populateIndex(searchClient);
beforeEach(
/** @this Mocha.Context */ async function() {
({ searchClient, indexClient } = createClients<Hotel>(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<Hotel>(TEST_INDEX_NAME));
}
recorder = record(this, environmentSetup);
// create the clients again, but hooked up to the recorder
({ searchClient, indexClient } = createClients<Hotel>(TEST_INDEX_NAME));
});
);
afterEach(async function() {
if (recorder) {

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/* eslint-disable no-invalid-this */
import { isPlaybackMode, record, Recorder, isLiveMode } from "@azure/test-utils-recorder";
import { assert } from "chai";
import { SearchIndexClient, SynonymMap, SearchIndex } from "../../../src";
@ -18,23 +17,25 @@ import { delay } from "@azure/core-http";
const TEST_INDEX_NAME = isLiveMode() ? createRandomIndexName() : "hotel-live-test3";
describe("SearchIndexClient", function() {
describe("SearchIndexClient", /** @this Mocha.Context */ function() {
let recorder: Recorder;
let indexClient: SearchIndexClient;
this.timeout(99999);
beforeEach(async function() {
({ indexClient } = createClients<Hotel>(TEST_INDEX_NAME));
if (!isPlaybackMode()) {
await createSynonymMaps(indexClient);
await createSimpleIndex(indexClient, TEST_INDEX_NAME);
await delay(WAIT_TIME);
beforeEach(
/** @this Mocha.Context */ async function() {
({ indexClient } = createClients<Hotel>(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<Hotel>(TEST_INDEX_NAME));
}
recorder = record(this, environmentSetup);
// create the clients again, but hooked up to the recorder
({ indexClient } = createClients<Hotel>(TEST_INDEX_NAME));
});
);
afterEach(async function() {
if (recorder) {

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/* eslint-disable no-invalid-this */
import { isPlaybackMode, record, Recorder, isLiveMode } from "@azure/test-utils-recorder";
import { assert } from "chai";
import {
@ -28,26 +27,28 @@ import { delay } from "@azure/core-http";
const TEST_INDEX_NAME = isLiveMode() ? createRandomIndexName() : "hotel-live-test2";
describe("SearchIndexerClient", function() {
describe("SearchIndexerClient", /** @this Mocha.Context */ function() {
let recorder: Recorder;
let indexerClient: SearchIndexerClient;
let indexClient: SearchIndexClient;
this.timeout(99999);
beforeEach(async function() {
({ indexClient, indexerClient } = createClients<Hotel>(TEST_INDEX_NAME));
if (!isPlaybackMode()) {
await createDataSourceConnections(indexerClient);
await createSkillsets(indexerClient);
await createIndex(indexClient, TEST_INDEX_NAME);
await delay(5000);
await createIndexers(indexerClient, TEST_INDEX_NAME);
beforeEach(
/** @this Mocha.Context */ async function() {
({ indexClient, indexerClient } = createClients<Hotel>(TEST_INDEX_NAME));
if (!isPlaybackMode()) {
await createDataSourceConnections(indexerClient);
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<Hotel>(TEST_INDEX_NAME));
}
recorder = record(this, environmentSetup);
// create the clients again, but hooked up to the recorder
({ indexClient, indexerClient } = createClients<Hotel>(TEST_INDEX_NAME));
});
);
afterEach(async function() {
if (recorder) {

Просмотреть файл

@ -26,20 +26,21 @@ describe("batch operations", () => {
// which wouldn't match the recorded one. Fallingback to SAS for recorded tests.
const authMode = !isNode || !isLiveMode() ? "SASConnectionString" : "AccountConnectionString";
beforeEach(async function() {
sinon.stub(Uuid, "generateUuid").returns("fakeId");
// eslint-disable-next-line no-invalid-this
recorder = record(this, recordedEnvironmentSetup);
client = createTableClient(tableName, authMode);
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();
try {
if (!isPlaybackMode()) {
await client.create();
}
} catch {
console.warn("Table already exists");
}
} catch {
console.warn("Table already exists");
}
});
);
afterEach(async function() {
sinon.restore();

Просмотреть файл

@ -18,12 +18,13 @@ describe("TableClient", () => {
// which wouldn't match the recorded one. Fallingback to SAS for recorded tests.
const authMode = !isNode || !isLiveMode() ? "SASConnectionString" : "AccountConnectionString";
beforeEach(function() {
// eslint-disable-next-line no-invalid-this
recorder = record(this, recordedEnvironmentSetup);
beforeEach(
/** @this Mocha.Context */ function() {
recorder = record(this, recordedEnvironmentSetup);
client = createTableClient(tableName, authMode);
});
client = createTableClient(tableName, authMode);
}
);
before(async () => {
if (!isPlaybackMode()) {
@ -44,25 +45,26 @@ describe("TableClient", () => {
describe("listEntities", () => {
// Create required entities for testing list operations
before(async function() {
if (!isPlaybackMode()) {
// eslint-disable-next-line no-invalid-this
this.timeout(10000);
await client.createEntity({
partitionKey: listPartitionKey,
rowKey: "binary1",
foo: new Uint8Array([66, 97, 114])
});
for (let i = 0; i < 20; i++) {
before(
/** @this Mocha.Context */ async function() {
if (!isPlaybackMode()) {
this.timeout(10000);
await client.createEntity({
partitionKey: listPartitionKey,
rowKey: `${i}`,
foo: "testEntity"
rowKey: "binary1",
foo: new Uint8Array([66, 97, 114])
});
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 };

Просмотреть файл

@ -14,11 +14,12 @@ describe("TableServiceClient", () => {
const suffix = isNode ? "node" : "browser";
const authMode = !isNode || !isLiveMode() ? "SASConnectionString" : "AccountConnectionString";
beforeEach(function() {
// eslint-disable-next-line no-invalid-this
recorder = record(this, recordedEnvironmentSetup);
client = createTableServiceClient(authMode);
});
beforeEach(
/** @this Mocha.Context */ function() {
recorder = record(this, recordedEnvironmentSetup);
client = createTableServiceClient(authMode);
}
);
afterEach(async function() {
await recorder.stop();
@ -50,33 +51,35 @@ describe("TableServiceClient", () => {
describe("listTables", () => {
const tableNames: string[] = [];
const expectedTotalItems = 20;
before(async function() {
// Create tables to be listed
if (!isPlaybackMode()) {
// eslint-disable-next-line no-invalid-this
this.timeout(10000);
for (let i = 0; i < 20; i++) {
const tableName = `ListTableTest${suffix}${i}`;
await client.createTable(tableName);
tableNames.push(tableName);
}
}
});
after(async function() {
// Cleanup tables
if (!isPlaybackMode()) {
// eslint-disable-next-line no-invalid-this
this.timeout(10000);
try {
for (const table of tableNames) {
await client.deleteTable(table);
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);
}
} catch (error) {
console.warn(`Failed to delete a table during cleanup`);
}
}
});
);
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`);
}
}
}
);
it("should list all", async () => {
const tables = client.listTables();

Просмотреть файл

@ -25,10 +25,9 @@ describe("TablesSharedKeyCredential", () => {
Date.prototype.toUTCString = originalToUTCString;
});
it("It should sign", async function() {
it("It should sign", /** @this Mocha.Context */ async function() {
if (!isNode) {
// TablesSharedKeyCredential auth is not supported in Browser
// eslint-disable-next-line no-invalid-this
this.skip();
}
const url =

Просмотреть файл

@ -10,13 +10,14 @@ import { ConnectionString } from "../../src/utils/internalModels";
describe("Utility Helpers", () => {
describe("extractConnectionStringParts", () => {
describe("Account Connection String", () => {
beforeEach(function() {
if (!isNode) {
// Account connection string is not supported for Browsers
// eslint-disable-next-line no-invalid-this
this.skip();
beforeEach(
/** @this Mocha.Context */ function() {
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";

Просмотреть файл

@ -52,35 +52,36 @@ 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(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.
// eslint-disable-next-line no-invalid-this
recorder = record(this, {
// == Recorder Environment Setup == Add the replaceable variables from
// above
replaceableVariables,
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: [],
// 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 = createConfigurationClient();
});
// 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() {

Просмотреть файл

@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
"extends": ["../../../tsdoc.json"]
}

Просмотреть файл

@ -41,7 +41,9 @@ versionsToTest(serviceVersions, {}, (serviceVersion, onVersions) => {
console.log(`creating test client for service version ${serviceVersion}`);
});
afterEach(async function() { /** empty */});
afterEach(async function() {
/** empty */
});
it("test case 2", function() {
if (serviceVersion === "7.0") {
@ -50,7 +52,9 @@ versionsToTest(serviceVersions, {}, (serviceVersion, onVersions) => {
});
describe("nested test suite 3a", function() {
it("nested test 4a", function() { /** empty */});
it("nested test 4a", function() {
/** empty */
});
});
onVersions(["7.0"]).describe("nested test suite 3b", function() {

Просмотреть файл

@ -19,28 +19,29 @@ const testDataEn = [
"I didn't like the last book I read at all."
];
describe("[API Key] TextAnalyticsClient", function() {
describe("[API Key] TextAnalyticsClient", /** @this Mocha.Context */ function() {
let recorder: Recorder;
let client: TextAnalyticsClient;
// eslint-disable-next-line no-invalid-this
const CLITimeout = this.timeout();
const fastTimeout = 10000;
beforeEach(function() {
// eslint-disable-next-line no-invalid-this
recorder = createRecorder(this);
client = createClient("APIKey");
});
beforeEach(
/** @this Mocha.Context */ function() {
recorder = createRecorder(this);
client = createClient("APIKey");
}
);
afterEach(async function() {
await recorder.stop();
});
describe("fast tests", function() {
before(function() {
// eslint-disable-next-line no-invalid-this
this.timeout(fastTimeout);
});
before(
/** @this Mocha.Context */ function() {
this.timeout(fastTimeout);
}
);
it("#analyzeSentiment", async function() {
const results = await client.analyzeSentiment(testDataEn);
@ -88,10 +89,11 @@ describe("[API Key] TextAnalyticsClient", function() {
describe("LROs", function() {
const pollingInterval = isPlaybackMode() ? 0 : 2000;
before(function() {
// eslint-disable-next-line no-invalid-this
this.timeout(isPlaybackMode() ? fastTimeout : CLITimeout);
});
before(
/** @this Mocha.Context */ function() {
this.timeout(isPlaybackMode() ? fastTimeout : CLITimeout);
}
);
describe("#health", function() {
it("input strings", async function() {

Просмотреть файл

@ -35,35 +35,36 @@ 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", function() {
describe("[AAD] TextAnalyticsClient", /** @this Mocha.Context */ function() {
let recorder: Recorder;
let client: TextAnalyticsClient;
// eslint-disable-next-line no-invalid-this
const CLITimeout = this.timeout();
const fastTimeout = 10000;
let getId: () => string;
beforeEach(function() {
// eslint-disable-next-line no-invalid-this
recorder = createRecorder(this);
client = createClient("AAD");
let nextId = 0;
getId = function() {
nextId += 1;
return nextId.toString();
};
});
beforeEach(
/** @this Mocha.Context */ function() {
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(function() {
// eslint-disable-next-line no-invalid-this
this.timeout(fastTimeout);
});
before(
/** @this Mocha.Context */ function() {
this.timeout(fastTimeout);
}
);
describe("#analyzeSentiment", function() {
it("client throws on empty list", async function() {
@ -929,10 +930,11 @@ describe("[AAD] TextAnalyticsClient", function() {
describe("LROs", function() {
const pollingInterval = isPlaybackMode() ? 0 : 2000;
before(function() {
// eslint-disable-next-line no-invalid-this
this.timeout(isPlaybackMode() ? fastTimeout : CLITimeout);
});
before(
/** @this Mocha.Context */ function() {
this.timeout(isPlaybackMode() ? fastTimeout : CLITimeout);
}
);
describe("#analyze", function() {
it("single entity recognition action", async function() {

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше