Skip to content

Commit 0d64740

Browse files
committed
test(mobile): a cold highlighter is not held to a warm one's tokens
Signed-off-by: Yordis Prieto <[email protected]>
1 parent aa11cbc commit 0d64740

1 file changed

Lines changed: 25 additions & 16 deletions

File tree

‎apps/mobile/src/features/review/shikiReviewHighlighter.test.ts‎

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
highlightCodeSnippet,
66
highlightReviewSelectedLines,
77
highlightSourceFile,
8+
type ReviewHighlightedToken,
89
} from "./shikiReviewHighlighter";
910

1011
describe("highlightSourceFile", () => {
@@ -51,23 +52,31 @@ describe("highlightSourceFile", () => {
5152
vi.resetModules();
5253
const highlighter = await import("./shikiReviewHighlighter");
5354
const source = "const answer: number = 42;";
54-
55-
const highlighted = await highlighter.highlightSourceFile({
56-
path: "example.ts",
57-
contents: source,
58-
theme: "dark",
59-
});
60-
61-
expect(
62-
highlighted
63-
.flat()
64-
.map((token) => token.content)
65-
.join(""),
66-
).toBe(source);
67-
expect(highlighted.flat().some((token) => token.color !== null)).toBe(true);
68-
expect(
55+
// Each entry point is held to the source text and to having highlighted it, rather than to
56+
// the other's tokens. Both ask for the same language and theme, so comparing the two only
57+
// pins how much of the grammar the engine had compiled by the time each one ran.
58+
const expectHighlighted = (
59+
tokenLines: ReadonlyArray<ReadonlyArray<ReviewHighlightedToken>>,
60+
) => {
61+
expect(
62+
tokenLines
63+
.flat()
64+
.map((token) => token.content)
65+
.join(""),
66+
).toBe(source);
67+
expect(tokenLines.flat().some((token) => token.color !== null)).toBe(true);
68+
};
69+
70+
expectHighlighted(
71+
await highlighter.highlightSourceFile({
72+
path: "example.ts",
73+
contents: source,
74+
theme: "dark",
75+
}),
76+
);
77+
expectHighlighted(
6978
await highlighter.highlightCodeSnippet({ code: source, language: "ts", theme: "dark" }),
70-
).toEqual(highlighted);
79+
);
7180
});
7281
});
7382

0 commit comments

Comments
 (0)