|
5 | 5 | highlightCodeSnippet, |
6 | 6 | highlightReviewSelectedLines, |
7 | 7 | highlightSourceFile, |
| 8 | + type ReviewHighlightedToken, |
8 | 9 | } from "./shikiReviewHighlighter"; |
9 | 10 |
|
10 | 11 | describe("highlightSourceFile", () => { |
@@ -51,23 +52,31 @@ describe("highlightSourceFile", () => { |
51 | 52 | vi.resetModules(); |
52 | 53 | const highlighter = await import("./shikiReviewHighlighter"); |
53 | 54 | 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( |
69 | 78 | await highlighter.highlightCodeSnippet({ code: source, language: "ts", theme: "dark" }), |
70 | | - ).toEqual(highlighted); |
| 79 | + ); |
71 | 80 | }); |
72 | 81 | }); |
73 | 82 |
|
|
0 commit comments