Skip to content

Commit bd3861a

Browse files
Clean up of cheatsheet test (#3365)
1 parent e0274ac commit bd3861a

4 files changed

Lines changed: 13 additions & 9 deletions

File tree

packages/lib-node-common/test/Cheatsheet.test.ts renamed to packages/lib-node-common/src/cheatsheet/Cheatsheet.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import assert from "node:assert/strict";
22
import { parse } from "node-html-parser";
33
import type { CheatsheetInfo } from "@cursorless/lib-common";
4-
import { injectCheatsheetInfo } from "../src/injectCheatsheetInfo";
4+
import { injectCheatsheetInfo } from "./injectCheatsheetInfo";
55

66
suite("Cheatsheet", () => {
77
test("injects cheatsheet info as executable script text", () => {

packages/lib-node-common/src/Cheatsheet.ts renamed to packages/lib-node-common/src/cheatsheet/Cheatsheet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
getErrorMessage,
88
showWarning,
99
} from "@cursorless/lib-common";
10-
import type { FileSystemTalonSpokenForms } from "./FileSystemTalonSpokenForms";
10+
import type { FileSystemTalonSpokenForms } from "../FileSystemTalonSpokenForms";
1111
import { injectCheatsheetInfo } from "./injectCheatsheetInfo";
1212

1313
interface CheatSheetCommandArgV0 {

packages/lib-node-common/src/injectCheatsheetInfo.ts renamed to packages/lib-node-common/src/cheatsheet/injectCheatsheetInfo.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { parse, TextNode } from "node-html-parser";
1+
import { parse } from "node-html-parser";
22
import type { CheatsheetInfo } from "@cursorless/lib-common";
33

44
export function injectCheatsheetInfo(
@@ -11,11 +11,15 @@ export function injectCheatsheetInfo(
1111
String.raw`\u003c`,
1212
);
1313

14-
root
15-
.getElementById("cheatsheet-data")!
16-
.set_content(
17-
new TextNode(`document.cheatsheetInfo = ${serializedCheatsheetInfo};`),
18-
);
14+
const dataElement = root.getElementById("cheatsheet-data");
15+
16+
if (dataElement == null) {
17+
throw new Error("Cheatsheet cheatsheet-data element not found");
18+
}
19+
20+
dataElement.set_content(
21+
`document.cheatsheetInfo = ${serializedCheatsheetInfo};`,
22+
);
1923

2024
return root.toString();
2125
}

‎packages/lib-node-common/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from "./Cheatsheet";
1+
export * from "./cheatsheet/Cheatsheet";
22
export * from "./FileSystemCommandHistoryStorage";
33
export * from "./FileSystemRawTreeSitterQueryProvider";
44
export * from "./FileSystemTalonSpokenForms";

0 commit comments

Comments
 (0)