Skip to content

Commit cbe249a

Browse files
committed
refactor: Update type imports for portability loadTestCaseFixture
1 parent ac55f63 commit cbe249a

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed
Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
11
import { generateHtml } from "./generateHtml";
2-
import type { LoadFixtureProps } from "./types";
2+
import type { DataFixture } from "./types";
3+
import type { BundledLanguage } from "shiki";
4+
import type { TestCaseSnapshot } from "@cursorless/common";
5+
import type { CommandLatest } from "@cursorless/common";
36

4-
export async function loadTestCaseFixture(data: LoadFixtureProps) {
5-
const { before, during, after } = await generateHtml(data)
6-
7-
const { command, filename, languageId: language } = data
7+
export interface LoadFixtureProps extends DataFixture {
8+
filename: string;
9+
languageId: BundledLanguage;
10+
initialState: TestCaseSnapshot;
11+
finalState: TestCaseSnapshot;
12+
}
813

9-
const returnObj = {
10-
before, during, after, command, filename, language
11-
}
12-
try {
14+
export interface PortableTestCaseFixture {
15+
before: string;
16+
during: string;
17+
after: string;
18+
command: object; // Use plain object for portability
19+
filename: string;
20+
language: string;
21+
}
1322

14-
return returnObj
23+
function extractHtml(step: string | { html: string; data: any[] }): string {
24+
return typeof step === "string" ? step : step.html;
25+
}
1526

16-
} catch (e) {
17-
console.error("error", e);
18-
throw e;
19-
}
27+
export async function loadTestCaseFixture(
28+
data: LoadFixtureProps
29+
): Promise<PortableTestCaseFixture> {
30+
const { before, during, after } = await generateHtml(data);
31+
const { command, filename, languageId: language } = data;
32+
return {
33+
before: extractHtml(before),
34+
during: extractHtml(during),
35+
after: extractHtml(after),
36+
command: JSON.parse(JSON.stringify(command)), // ensure plain object
37+
filename,
38+
language,
39+
};
2040
}
2141

0 commit comments

Comments
 (0)