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

Fix build failures #28423

Merged
merged 1 commit into from
Jan 31, 2024
Merged
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: 0 additions & 1 deletion sdk/test-utils/recorder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ export {
export { env } from "./utils/env";
export { delay } from "./utils/delay";
export { CustomMatcherOptions } from "./matcher";
export { TestInfo, MochaTest, VitestTestContext } from "./testInfo";
62 changes: 10 additions & 52 deletions sdk/test-utils/recorder/src/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
RecorderStartOptions,
RecordingStateManager,
} from "./utils/utils";
import { assetsJsonPath, sessionFilePath, TestContext } from "./utils/sessionFilePath";
import { Test } from "mocha";
import { assetsJsonPath, sessionFilePath } from "./utils/sessionFilePath";
import { SanitizerOptions } from "./utils/utils";
import { paths } from "./utils/paths";
import { addSanitizers, transformsInfo } from "./sanitizer";
Expand All @@ -34,45 +35,6 @@ import { isNode } from "@azure/core-util";
import { env } from "./utils/env";
import { decodeBase64 } from "./utils/encoding";
import { AdditionalPolicyConfig } from "@azure/core-client";
import { isMochaTest, isVitestTestContext, TestInfo, VitestSuite } from "./testInfo";

/**
* Caculates session file path and JSON assets path from test context
*
* @internal
*/
export function calculatePaths(testContext: TestInfo): TestContext {
if (isMochaTest(testContext)) {
if (!testContext.parent) {
throw new RecorderError(
`The parent of test '${testContext.title}' is undefined, so a file path for its recording could not be generated. Please place the test inside a describe block.`,
);
}
return {
suiteTitle: testContext.parent.fullTitle(),
testTitle: testContext.title,
};
} else if (isVitestTestContext(testContext)) {
if (!testContext.task.name || !testContext.task.suite.name) {
throw new RecorderError(
`Unable to determine the recording file path. Unexpected empty Vitest context`,
);
}
const suites: string[] = [];
let p: VitestSuite | undefined = testContext.task.suite;
while (p?.name) {
suites.push(p.name);
p = p.suite;
}

return {
suiteTitle: suites.reverse().join("_"),
testTitle: testContext.task.name,
};
} else {
throw new RecorderError(`Unrecognized test info: ${testContext}`);
}
}

/**
* This client manages the recorder life cycle and interacts with the proxy-tool to do the recording,
Expand All @@ -91,23 +53,19 @@ export class Recorder {
private assetsJson?: string;
private variables: Record<string, string>;

constructor(private testContext?: TestInfo) {
if (!this.testContext) {
throw new Error(
"Unable to determine the recording file path, testContext provided is not defined.",
);
}

constructor(private testContext?: Test | undefined) {
logger.info(`[Recorder#constructor] Creating a recorder instance in ${getTestMode()} mode`);
if (isRecordMode() || isPlaybackMode()) {
const context = calculatePaths(this.testContext);

this.sessionFile = sessionFilePath(context);
this.assetsJson = assetsJsonPath();

if (this.testContext) {
this.sessionFile = sessionFilePath(this.testContext);
this.assetsJson = assetsJsonPath();

logger.info(`[Recorder#constructor] Using a session file located at ${this.sessionFile}`);
this.httpClient = createDefaultHttpClient();
} else {
throw new Error(
"Unable to determine the recording file path, testContext provided is not defined.",
);
}
}
this.variables = {};
Expand Down
91 changes: 0 additions & 91 deletions sdk/test-utils/recorder/src/testInfo.ts

This file was deleted.

20 changes: 11 additions & 9 deletions sdk/test-utils/recorder/src/utils/sessionFilePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
import { isNode } from "@azure/core-util";
import { generateTestRecordingFilePath } from "./filePathGenerator";
import { relativeRecordingsPath } from "./relativePathCalculator";
import { RecorderError } from "./utils";

export interface TestContext {
suiteTitle: string; // describe(suiteTitle, () => {})
testTitle: string; // it(testTitle, () => {})
}

export function sessionFilePath(testContext: TestContext): string {
export function sessionFilePath(testContext: Mocha.Test): string {
// sdk/service/project/recordings/{node|browsers}/<describe-block-title>/recording_<test-title>.json
return `${relativeRecordingsPath()}/${recordingFilePath(testContext)}`;
}
Expand All @@ -20,11 +16,17 @@ export function sessionFilePath(testContext: TestContext): string {
*
* `{node|browsers}/<describe-block-title>/recording_<test-title>.json`
*/
export function recordingFilePath(testContext: TestContext): string {
export function recordingFilePath(testContext: Mocha.Test): string {
if (!testContext.parent) {
throw new RecorderError(
`Test ${testContext.title} is not inside a describe block, so a file path for its recording could not be generated. Please place the test inside a describe block.`,
);
}

return generateTestRecordingFilePath(
isNode ? "node" : "browsers",
testContext.suiteTitle,
testContext.testTitle,
testContext.parent.fullTitle(),
testContext.title,
);
}

Expand Down
62 changes: 0 additions & 62 deletions sdk/test-utils/recorder/test/recorder.spec.ts

This file was deleted.

Loading