Skip to content

Commit

Permalink
Fix build failures (#28423)
Browse files Browse the repository at this point in the history
PR #28350 somehow cause many packages to fail to build because they
don't have a dev dependency on @types/mocha. Reverting for now.

Revert "[test-recorder] Support test context from vitest (#28350)"

This reverts commit a2a2d03.
  • Loading branch information
jeremymeng authored Jan 31, 2024
1 parent 54887ec commit 3c20c8a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 215 deletions.
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.

0 comments on commit 3c20c8a

Please sign in to comment.