Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test comm recorder - testing skip #17

Open
wants to merge 4 commits into
base: CommonRecorder
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/keyvault/keyvault-secrets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"tslib": "^1.9.3"
},
"devDependencies": {
"@azure/test-utils-recorder": "1.0.0",
"@microsoft/api-extractor": "^7.1.5",
"@types/chai": "^4.1.6",
"@types/dotenv": "^6.1.0",
Expand Down
11 changes: 7 additions & 4 deletions sdk/keyvault/keyvault-secrets/tests/CRUD.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import * as assert from "assert";
import { SecretsClient } from "../src";
import { retry, env } from "./utils/recorder";
import { retry } from "./utils/recorder";
import { env, Recorder } from "@azure/test-utils-recorder";
import { authenticate } from "./utils/testAuthentication";
import TestClient from "./utils/testClient";
import { AbortController } from "@azure/abort-controller";
Expand All @@ -14,17 +15,17 @@ describe("Secret client - create, read, update and delete operations", () => {
let secretSuffix: string;
let client: SecretsClient;
let testClient: TestClient;
let recorder: any;
let recorder: Recorder;

before(async function() {
beforeEach(async function() {
const authentication = await authenticate(this);
secretSuffix = authentication.secretSuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});

after(async function() {
afterEach(async function() {
recorder.stop();
});

Expand All @@ -41,6 +42,8 @@ describe("Secret client - create, read, update and delete operations", () => {
});

it("can abort adding a secret", async function() {
// recorder.skip("browser");
recorder.skip();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recorder.skip(); skips the test in both node and browser runtimes.

recorder.skip("browser") skips the test in browser runtime.

const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
Expand Down
19 changes: 10 additions & 9 deletions sdk/keyvault/keyvault-secrets/tests/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import * as assert from "assert";
import chai from "chai";
import { SecretsClient } from "../src";
import { retry, env } from "./utils/recorder";
import { retry } from "./utils/recorder";
import { env } from "@azure/test-utils-recorder";
import { authenticate } from "./utils/testAuthentication";
import TestClient from "./utils/testClient";
const { expect } = chai;
Expand All @@ -17,15 +18,15 @@ describe("Secret client - list secrets in various ways", () => {
let testClient: TestClient;
let recorder: any;

before(async function() {
beforeEach(async function() {
const authentication = await authenticate(this);
secretSuffix = authentication.secretSuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});

after(async function() {
afterEach(async function() {
recorder.stop();
});

Expand All @@ -36,12 +37,12 @@ describe("Secret client - list secrets in various ways", () => {
for await (const secret of client.listSecrets()) {
try {
await testClient.flushSecret(secret.name);
} catch(e) {}
} catch (e) {}
}
for await (const secret of client.listDeletedSecrets()) {
try {
await testClient.purgeSecret(secret.name);
} catch(e) {}
} catch (e) {}
}
});

Expand Down Expand Up @@ -146,7 +147,7 @@ describe("Secret client - list secrets in various ways", () => {
assert.equal(totalVersions, 0, `Unexpected total versions for secret ${secretName}`);
});

it("can list secrets", async function() {
it("can list secrets - byPage()", async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
Expand All @@ -168,7 +169,7 @@ describe("Secret client - list secrets in various ways", () => {
}
});

it("can list deleted secrets", async function() {
it("can list deleted secrets - byPage()", async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
Expand Down Expand Up @@ -199,7 +200,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 - byPage()", async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
Expand Down Expand Up @@ -232,7 +233,7 @@ describe("Secret client - list secrets in various ways", () => {
await testClient.flushSecret(secretName);
});

it("can list secret versions (non existing)", async function() {
it("can list secret versions (non existing) - byPage()", async function() {
const secretName = testClient.formatName(
`${secretPrefix}-${this!.test!.title}-${secretSuffix}`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import * as assert from "assert";
import { SecretsClient } from "../src";
import { retry, isNode, env } from "./utils/recorder";
import { retry } from "./utils/recorder";
import { isNode } from "@azure/core-http";
import { env } from "@azure/test-utils-recorder";
import { authenticate } from "./utils/testAuthentication";
import TestClient from "./utils/testClient";

Expand All @@ -14,15 +16,15 @@ describe("Secret client - restore secrets and recover backups", () => {
let testClient: TestClient;
let recorder: any;

before(async function() {
beforeEach(async function() {
const authentication = await authenticate(this);
secretSuffix = authentication.secretSuffix;
client = authentication.client;
testClient = authentication.testClient;
recorder = authentication.recorder;
});

after(async function() {
afterEach(async function() {
recorder.stop();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ClientSecretCredential } from "@azure/identity";
import { getKeyvaultName } from "./utils.common";
import { SecretsClient } from "../../src";
import { env, record, setReplaceableVariables, setReplacements, uniqueString } from "./recorder";
import { env, record, setReplaceableVariables, setReplacements } from "@azure/test-utils-recorder";
import { uniqueString } from "./recorder";
import TestClient from "./testClient";

export async function authenticate(that: any): Promise<any> {
Expand Down
3 changes: 1 addition & 2 deletions sdk/test-utils/recorder/GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,8 @@ Add `@azure/test-utils-recorder` as a devDependency of your sdk.

- We leverage mocha's `.skip()` functionality to skip the test
`this.skip()` - https://mochajs.org/#inclusive-tests.
By this, the tests in the skip list will only be executed if the `TEST_MODE` is neither `"record"` nor `"playback"`.

- If the new test is supposed to skipped, it must be added in the skip list. Doing this would allow the tests in the skip list to be executed only if the `TEST_MODE` is neither `"record"` nor `"playback"`.
- `{recorder.skip(runtime?: "node" | "browser")}` will skip the test in node or browser runtimes based on the `{runtime}` argument. If the `{runtime}` is undefined, the test will be skipped in both the node and browser runtimes. Has no effect if the `TEST_MODE` is neither `"record"` nor `"playback"`.

---

Expand Down
10 changes: 0 additions & 10 deletions sdk/test-utils/recorder/src/baseRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ export function setEnviromentOnLoad() {
}
}

// TODO - skip list will be removed - #4336
const skip = [
// Abort
"browsers/aborter/recording_should_abort_after_aborter_timeout.json"
];

export abstract class BaseRecorder {
protected readonly filepath: string;
public uniqueTestInfo: TestInfo = { uniqueName: {}, newDate: {} };
Expand Down Expand Up @@ -110,10 +104,6 @@ export abstract class BaseRecorder {
return updatedRecording;
}

public skip(): boolean {
return skip.includes(this.filepath);
}

public abstract record(): void;
public abstract playback(filePath: string): void;
public abstract stop(): void;
Expand Down
35 changes: 31 additions & 4 deletions sdk/test-utils/recorder/src/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export interface Recorder {
* Has no effect in the playback/live test modes.
*/
stop(): void;
/**
* `skip()` method is supposed to be called at the end of the test, stops and saves the recording in the "record" mode.
* Has no effect in the live test mode.
*/
skip(runtime?: "node" | "browser"): void;
/**
* In live test mode, random string is generated, appended to `prefix` and returned.
*
Expand Down Expand Up @@ -74,10 +79,6 @@ export function record(testContext: Mocha.Context): Recorder {
recorder = new NockRecorder(testHierarchy, testTitle);
}

if (recorder.skip() && (isRecordMode() || isPlaybackMode())) {
testContext.skip();
}

// If neither recording nor playback is enabled, requests hit the live-service and no recordings are generated
if (isRecordMode()) {
recorder.record();
Expand All @@ -91,6 +92,32 @@ export function record(testContext: Mocha.Context): Recorder {
recorder.stop();
}
},
/**
* `{recorder.skip("node")}` and `{recorder.skip("browser")}` will skip the test in node.js and browser runtimes repectively.
* If the `{runtime}` is undefined, the test will be skipped in both the node and browser runtimes.
* @param runtime Can either be "node" or "browser"
*/
skip: function(runtime?: "node" | "browser"): void {
// 1. skipping the test only in node
// 2. skipping the test only in browser
// 3. skipping the test in both the node and browser runtimes
if (
(runtime === "node" && !isBrowser()) ||
(runtime === "browser" && isBrowser()) ||
!runtime
) {
if (isRecordMode()) {
// record mode - recorder is stopped, test is skipped
recorder.stop();
testContext.skip();
} else if (isPlaybackMode()) {
// playback mode - test is skipped
testContext.skip();
} else {
// live mode - no effect
}
}
},
getUniqueName: function(prefix: string, label?: string): string {
let name: string;
if (!label) {
Expand Down