Skip to content

Commit 1091c71

Browse files
committed
wip: Adapt old loadFixture to use Shiki
1 parent 2fea787 commit 1091c71

File tree

1 file changed

+57
-48
lines changed

1 file changed

+57
-48
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1-
import type { PositionPlainObject } from "@cursorless/common";
2-
import type { TestCaseFixture, TestCaseSnapshot } from "@cursorless/common";
3-
import { generateHtml } from "./generateHtml";
1+
import type { TargetPlainObject, TestCaseFixture, TestCaseSnapshot } from "@cursorless/common";
2+
import { generateHtml } from "./generateHtml.js";
3+
import type { BundledLanguage } from "shiki";
44

5-
async function safeGenerateHtml(
6-
...args: [stateName: string, ...rest: Parameters<typeof generateHtml>]
7-
) {
8-
const [stateName, state, languageId] = args;
5+
async function safeGenerateHtml({
6+
stateName,
7+
state,
8+
languageId,
9+
command,
10+
ide,
11+
thatMarkFinalState
12+
}: {
13+
stateName: string;
14+
state: TestCaseSnapshot;
15+
languageId: BundledLanguage;
16+
command?: any; // Replace `any` with the appropriate type if known
17+
ide?: any; // Replace `any` with the appropriate type if known
18+
thatMarkFinalState?: TargetPlainObject
19+
}) {
20+
console.log("✨" + stateName + "✨");
921
try {
10-
return await generateHtml(state, languageId);
22+
const genObj = { stateName, state, languageId, command, ide }
23+
return await generateHtml(genObj);
1124
} catch (e) {
1225
console.error("error in state", stateName, e);
1326
console.error(JSON.stringify(state, null, 2));
@@ -17,18 +30,21 @@ async function safeGenerateHtml(
1730

1831
interface loadFixtureProps extends TestCaseFixture {
1932
filename: string;
33+
languageId: BundledLanguage;
34+
initialState: TestCaseSnapshot;
35+
finalState: TestCaseSnapshot;
2036
}
2137

2238
export async function loadFixture(data: loadFixtureProps) {
2339
try {
24-
const during = await getDuring(data);
25-
2640
const before = await getBefore({
2741
stateName: "initialState",
2842
state: data.initialState,
2943
languageId: data.languageId,
3044
});
3145

46+
const during = await getDuring(data);
47+
3248
const after = await getAfter({
3349
stateName: "finalState",
3450
state: data.finalState,
@@ -50,57 +66,50 @@ export async function loadFixture(data: loadFixtureProps) {
5066
}
5167
}
5268

53-
async function getBefore({
69+
type Foo = TestCaseSnapshot & TargetPlainObject;
70+
71+
async function getAfter({
5472
stateName,
5573
state,
5674
languageId,
5775
}: {
5876
stateName: string;
59-
state: TestCaseSnapshot;
60-
languageId: string;
77+
state: Foo;
78+
languageId: BundledLanguage;
6179
}) {
62-
return await safeGenerateHtml(stateName, state, languageId);
80+
if (!state) {
81+
throw new Error("finalState is undefined");
82+
}
83+
return await safeGenerateHtml({ stateName, state, languageId });
6384
}
6485

65-
async function getAfter({
86+
type DataFixture = Partial<TestCaseFixture & TargetPlainObject>
87+
88+
async function getDuring(data: DataFixture) {
89+
const { command, ide } = data
90+
const stateName = "middleState"
91+
const state = data.initialState
92+
const languageId = data.languageId as BundledLanguage
93+
const { thatMark: thatMarkFinalState } = data.finalState
94+
const genObj: TestCaseSnapshot & typeof thatMarkFinalState = { stateName, state, languageId, raw: data }
95+
if (command) {
96+
genObj.command = command
97+
}
98+
if (ide) {
99+
genObj.ide = ide
100+
}
101+
102+
return await generateHtml(genObj);
103+
}
104+
105+
async function getBefore({
66106
stateName,
67107
state,
68108
languageId,
69109
}: {
70110
stateName: string;
71111
state: TestCaseSnapshot;
72-
languageId: string;
112+
languageId: BundledLanguage;
73113
}) {
74-
// todo, handle clipboard
75-
return await safeGenerateHtml(stateName, state, languageId);
76-
}
77-
78-
async function getDuring(data: TestCaseFixture) {
79-
if (!!data.ide && data.ide.flashes) {
80-
return await safeGenerateHtml(
81-
"flashes",
82-
{
83-
...data.initialState,
84-
flashes: data.ide.flashes.map(
85-
(props: {
86-
name: string;
87-
type: string;
88-
start: PositionPlainObject;
89-
end: PositionPlainObject;
90-
}) => {
91-
const { name, type, start, end } = props;
92-
console.log("🦄", props);
93-
return {
94-
name,
95-
type,
96-
anchor: start,
97-
active: end,
98-
};
99-
},
100-
),
101-
},
102-
data.languageId,
103-
);
104-
}
105-
return null;
114+
return await safeGenerateHtml({ stateName, state, languageId });
106115
}

0 commit comments

Comments
 (0)