MCPcopy Create free account
hub / github.com/cursorless-dev/cursorless / runTest

Function runTest

src/test/suite/recorded.test.ts:52–145  ·  view source on GitHub ↗
(file: string)

Source from the content-addressed store, hash-verified

50});
51
52async function runTest(file: string) {
53 const buffer = await fsp.readFile(file);
54 const fixture = yaml.load(buffer.toString()) as TestCaseFixture;
55 const excludeFields: string[] = [];
56
57 const cursorlessApi = await getCursorlessApi();
58 const graph = cursorlessApi.graph!;
59
60 const editor = await openNewEditor(
61 fixture.initialState.documentContents,
62 fixture.languageId
63 );
64
65 if (!fixture.initialState.documentContents.includes("\n")) {
66 await editor.edit((editBuilder) => {
67 editBuilder.setEndOfLine(vscode.EndOfLine.LF);
68 });
69 }
70
71 editor.selections = fixture.initialState.selections.map(createSelection);
72
73 if (fixture.initialState.thatMark) {
74 const initialThatMark = fixture.initialState.thatMark.map((mark) => ({
75 selection: createSelection(mark),
76 editor,
77 }));
78 cursorlessApi.thatMark.set(initialThatMark);
79 }
80 if (fixture.initialState.sourceMark) {
81 const initialSourceMark = fixture.initialState.sourceMark.map((mark) => ({
82 selection: createSelection(mark),
83 editor,
84 }));
85 cursorlessApi.sourceMark.set(initialSourceMark);
86 }
87
88 if (fixture.initialState.clipboard) {
89 let mockClipboard = fixture.initialState.clipboard;
90 sinon.replace(Clipboard, "readText", async () => mockClipboard);
91 sinon.replace(Clipboard, "writeText", async (value: string) => {
92 mockClipboard = value;
93 });
94 } else {
95 excludeFields.push("clipboard");
96 }
97
98 await graph.hatTokenMap.addDecorations();
99
100 const readableHatMap = await graph.hatTokenMap.getReadableMap(false);
101
102 // Assert that recorded decorations are present
103 checkMarks(fixture.initialState.marks, readableHatMap);
104
105 const returnValue = await vscode.commands.executeCommand(
106 "cursorless.command",
107 fixture.command
108 );
109

Callers 1

recorded.test.tsFile · 0.70

Calls 14

getCursorlessApiFunction · 0.90
openNewEditorFunction · 0.90
marksToPlainObjectFunction · 0.90
extractTargetedMarksFunction · 0.90
takeSnapshotFunction · 0.90
createSelectionFunction · 0.85
checkMarksFunction · 0.85
serializeFunction · 0.85
toStringMethod · 0.80
editMethod · 0.80
setMethod · 0.80
getReadableMapMethod · 0.80

Tested by

no test coverage detected