Skip to content
Source
Sign inSign up

source-file-document.test.ts

20 lines795 Bytes

1import { expect, it } from "vite-plus/test";
2import { prepareSourceFileDocument, selectableSourceHtml } from "./source-file-document";
3​
4it("preserves source whitespace and markup as literal selectable text", () => {
5 const source = prepareSourceFileDocument(
6 "\n\tlead\r\n<script>alert(1)</script> &amp; > πŸ˜€\u00a0end\n",
7 );
8 const html = selectableSourceHtml(source.contents, {
9 foreground: "#000000",
10 selection: "#3366ff",
11 fontSize: 14,
12 rowHeight: 24,
13 wordBreak: true,
14 });
15 const page = new DOMParser().parseFromString(html, "text/html");
16​
17 expect(page.querySelector("script")).toBeNull();
18 expect(page.body.textContent).toBe("\n\tlead\n<script>alert(1)</script> &amp; > πŸ˜€\u00a0end\n");
19 expect(page.getElementById("L2")?.textContent).toBe("\tlead");
20});