Open History to see the last commit
1import JSZip from "jszip";
2import { openRtf, openNotebook, openDocument, openEpub } from "./extendedDocumentPreview";
3import type { ScopedThreadRef } from "@t3tools/contracts";
4import { ProjectReadFileError } from "@t3tools/contracts";
5import * as Schema from "effect/Schema";
6import { describe, expect, it, vi } from "vite-plus/test";
7
8import { remapFileCommentAnnotations } from "./fileCommentAnnotations";
9import {
10 filePreviewReadErrorMessage,
11 isMarkdownPreviewFile,
12 resolveFilePreviewPath,
13 shouldShowFileExplorer,
14 workspaceAssetResource,
15} from "./filePreviewMode";
16
17const decodeReadError = Schema.decodeSync(ProjectReadFileError);
18
19describe("file preview read errors", () => {
20 // regression: #15628 read errors from servers without attempted paths keep their own message
21 it("preserves the public message from older servers", () => {
22 const error = decodeReadError({
23 _tag: "ProjectReadFileError",
24 message: "Legacy file read failure.",
25 });
26 expect(filePreviewReadErrorMessage(error)).toBe("Legacy file read failure.");
27 });
28});
29
30describe("file comment annotations", () => {
31 it("keeps an annotation range attached when Pierre remaps its anchor line", () => {
32 expect(
33 remapFileCommentAnnotations([
34 {
35 lineNumber: 20,
36 metadata: {
37 entries: [
38 {
39 id: "comment-1",
40 kind: "comment",
41 startLine: 7,
42 endLine: 16,
43 text: "Keep this guarded.",
44 },
45 ],
46 },
47 },
48 ]),
49 ).toEqual([
50 {
51 lineNumber: 20,
52 metadata: {
53 entries: [
54 {
55 id: "comment-1",
56 kind: "comment",
57 startLine: 11,
58 endLine: 20,
59 text: "Keep this guarded.",
60 },
61 ],
62 },
63 },
64 ]);
65 });
66});
67
68describe("isMarkdownPreviewFile", () => {
69 it("recognizes markdown and MDX files case-insensitively", () => {
70 expect(isMarkdownPreviewFile("README.md")).toBe(true);
71 expect(isMarkdownPreviewFile("docs/guide.MDX")).toBe(true);
72 expect(isMarkdownPreviewFile("docs/guide.MARKDOWN")).toBe(true);
73 expect(isMarkdownPreviewFile("docs/guide.mdown")).toBe(true);
74 expect(isMarkdownPreviewFile("docs/guide.mkd")).toBe(true);
75 });
76});
77
78describe("resolveFilePreviewPath", () => {
79 it.each([
80 ["/repo/project", null],
81 ["/repo/project/", null],
82 [".", null],
83 [null, null],
84 ["/repo/project/src", "/repo/project/src"],
85 ["/repo/project/src/main.ts", "/repo/project/src/main.ts"],
86 ["src/main.ts", "src/main.ts"],
87 ["/repo/project-other", "/repo/project-other"],
88 ])("opens %s in the appropriate workspace surface", (path, expected) => {
89 const relativePath = resolveFilePreviewPath(path, "/repo/project");
90 expect(relativePath).toBe(expected);
91 if (expected === null) {
92 expect(
93 shouldShowFileExplorer({ relativePath, explorerOpen: false, attachmentOpen: false }),
94 ).toBe(true);
95 }
96 });
97});
98
99describe("workspaceAssetResource", () => {
100 const input = {
101 kind: "workspace-file" as const,
102 threadRef: {
103 environmentId: "env" as ScopedThreadRef["environmentId"],
104 threadId: "thread-1" as ScopedThreadRef["threadId"],
105 },
106 workspaceRoot: "/repo",
107 absolutePath: "/repo/docs/index.html",
108 };
109
110 // regression: #21067 images outside the workspace load through the host media resource
111 it("serves a file outside the workspace as host media and keeps workspace files on workspace access", () => {
112 expect(
113 workspaceAssetResource({ ...input, absolutePath: "/tmp/screenshots/shot.png", draft: false }),
114 ).toEqual({ _tag: "media-file", threadId: "thread-1", path: "/tmp/screenshots/shot.png" });
115 expect(workspaceAssetResource({ ...input, draft: false })).toEqual({
116 _tag: "workspace-file",
117 threadId: "thread-1",
118 path: "/repo/docs/index.html",
119 });
120 });
121
122 it("names the workspace root for a draft, which the server cannot resolve from a thread", () => {
123 expect(workspaceAssetResource({ ...input, draft: true })).toEqual({
124 _tag: "draft-workspace-file",
125 cwd: "/repo",
126 path: "/repo/docs/index.html",
127 });
128 expect(
129 workspaceAssetResource({ ...input, absolutePath: "/tmp/screenshots/shot.png", draft: true }),
130 ).toEqual({ _tag: "draft-workspace-file", cwd: "/repo", path: "/tmp/screenshots/shot.png" });
131 });
132});
133
134describe("document preview contents", () => {
135 const bytes = (text: string) => new TextEncoder().encode(text).buffer;
136
137 it.each([
138 ["control symbols", String.raw`{\rtf1 Jean\_Luc\-X\~Y}`, "Jean\u2011Luc\u00adX\u00a0Y"],
139 [
140 "named spaces, joiners and direction marks",
141 String.raw`{\rtf1 A\tab B\emspace C\enspace D\qmspace E\zwj F\zwnj G\zwbo H\ltrmark I\rtlmark J}`,
142 "A\tB\u2003C\u2002D\u2005E\u200dF\u200cG\u200bH\u200eI\u200fJ",
143 ],
144 ["a Unicode fallback", String.raw`{\rtf1 Jean\u8209\_Luc}`, "Jean\u2011Luc"],
145 ])("keeps the text of %s", (_name, source, expected) => {
146 const result = openRtf(bytes(source));
147 if (result.type !== "document") throw new Error("Expected document");
148 expect(result.pages[0]!.html.replaceAll(/<[^>]*>/g, "")).toBe(expected);
149 });
150
151 it.each(["?", String.raw`\'3f`, String.raw`\\`])(
152 "consumes skipped rich text Unicode fallback %s",
153 (fallback) => {
154 const result = openRtf(bytes(String.raw`{\rtf1{\*\unknown\u945` + fallback + "}Hello}"));
155 if (result.type !== "document") throw new Error("Expected document");
156 expect(result.pages[0]!.html).toBe("<p>Hello</p>");
157 },
158 );
159
160 it("bounds EPUB markup made entirely of empty allowed elements", async () => {
161 const archive = new JSZip()
162 .file(
163 "META-INF/container.xml",
164 '<container><rootfiles><rootfile full-path="book.opf"/></rootfiles></container>',
165 )
166 .file(
167 "book.opf",
168 '<package><manifest><item id="a" href="chapter.xhtml" media-type="application/xhtml+xml"/></manifest><spine>' +
169 '<itemref idref="a"/>'.repeat(30) +
170 "</spine></package>",
171 )
172 .file("chapter.xhtml", "<html><body>" + "<figcaption/>".repeat(30_000) + "</body></html>");
173 await expect(openEpub(archive)).rejects.toThrow("too large");
174 });
175
176 it("decodes rich text formatting and Unicode without showing hidden destinations", () => {
177 const result = openRtf(
178 bytes(
179 String.raw`{\rtf1\ansi{\fonttbl{\f0 Hidden font;}}Hello \b bold\b0\par Unicode: \u945?{\*\unknown hidden\_\emspace\zwj}{\field{\*\fldinst HYPERLINK "https://example.com"}{\fldrslt visible}}}`,
180 ),
181 );
182 expect(result.type).toBe("document");
183 if (result.type !== "document") throw new Error("Expected document");
184 const html = result.pages[0]!.html;
185 expect(html.replaceAll(/<[^>]*>/g, "")).toBe("Hello boldUnicode: αvisible");
186 expect(html).toContain("<strong>");
187 expect(html).not.toContain("https:");
188 });
189
190 it("treats a backslash before a line break as a paragraph break, as TextEdit writes them", () => {
191 const html = (rtf: string) => {
192 const result = openRtf(bytes(rtf));
193 if (result.type !== "document") throw new Error("Expected document");
194 return result.pages.map((page) => page.html);
195 };
196 const textEdit = String.raw`{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}
197\pard\f0\fs24 \cf0 First\
198Second\
199\
200Third}`;
201 const expected = html(
202 String.raw`{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\pard\f0\fs24 \cf0 First\par Second\par \par Third}`,
203 );
204 expect(html(textEdit)).toEqual(expected);
205 expect(html(textEdit.replaceAll("\n", "\r\n"))).toEqual(expected);
206 });
207
208 it("preserves rich text page breaks and formatting without splitting hidden destinations", () => {
209 const result = openRtf(
210 bytes(String.raw`{\rtf1\b First\page Second\b0{\*\unknown \page hidden}\page Third\page}`),
211 );
212 if (result.type !== "document") throw new Error("Expected document");
213 expect(result.navigation).toBe("page");
214 expect(result.pages.map((page) => page.html)).toEqual([
215 "<p><strong>First</strong></p>",
216 "<p><strong>Second</strong></p>",
217 "<p>Third</p>",
218 ]);
219 expect(() => openRtf(bytes(String.raw`{\rtf1 ` + String.raw`\page`.repeat(501) + "}"))).toThrow(
220 "500 pages",
221 );
222 });
223
224 it("decodes declared rich text code pages for raw bytes and escaped byte runs", () => {
225 const input = new TextEncoder().encode(
226 String.raw`{\rtf1\ansi\ansicpg1251 A \'c0\par\ansicpg932\'82\'a0}`,
227 );
228 input[input.indexOf(65)] = 0xc0;
229 const result = openRtf(input.buffer);
230 if (result.type !== "document") throw new Error("Expected document");
231 expect(result.pages[0]!.html).toBe("<p>А А<br>あ</p>");
232 expect(() => openRtf(bytes(String.raw`{\rtf1\ansicpg99999 text}`))).toThrow("code page");
233 });
234
235 it("resolves scoped ODF namespaces and explicit spreadsheet whitespace", async () => {
236 const archive = new JSZip().file(
237 "content.xml",
238 '<o:document-content xmlns:o="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:t="urn:oasis:names:tc:opendocument:xmlns:table:1.0"><o:body><o:spreadsheet><t:table t:name="Accounts & names"><t:table-row><t:table-cell><p xmlns="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:x="urn:oasis:names:tc:opendocument:xmlns:text:1.0">Account<s/>Name<s x:c="3"/>A<tab/>B<line-break/>C & <![CDATA[&]]></p></t:table-cell></t:table-row></t:table></o:spreadsheet></o:body></o:document-content>',
239 );
240 const result = await openDocument(archive, "ods");
241 if (result.type !== "ods") throw new Error("Expected workbook");
242 expect(result.sheets[0]!.name).toBe("Accounts & names");
243 expect(result.sheets[0]!.rows[0]).toEqual(["Account Name A\tB\nC & &"]);
244 });
245
246 it("stops repeated slide images before encoding beyond the output budget", async () => {
247 const pixels = new Uint8Array(4 * 1024 * 1024);
248 pixels.set(
249 Buffer.from(
250 "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIHWP4z8DwHwAFgAI/ScLbtAAAAABJRU5ErkJggg==",
251 "base64",
252 ),
253 );
254 const archive = new JSZip()
255 .file(
256 "content.xml",
257 '<o:document-content xmlns:o="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:d="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:l="http://www.w3.org/1999/xlink"><o:body>' +
258 '<d:page><d:image l:href="picture.png"/></d:page>'.repeat(500) +
259 "</o:body></o:document-content>",
260 )
261 .file("picture.png", pixels);
262 const image = archive.file("picture.png")!;
263 const read = vi.spyOn(image, "async");
264 await expect(openDocument(archive, "odp")).rejects.toThrow("too large");
265 expect(read.mock.calls.filter(([type]) => type === "base64")).toHaveLength(2);
266 expect(read).toHaveBeenCalledTimes(5);
267 });
268
269 it("reads saved notebook cells and preferred outputs without executing code", () => {
270 const result = openNotebook(
271 bytes(
272 JSON.stringify({
273 nbformat: 4,
274 metadata: { language_info: { name: "python" } },
275 cells: [
276 { cell_type: "markdown", source: ["# Results"] },
277 {
278 cell_type: "code",
279 source: ["print(42)"],
280 outputs: [
281 { output_type: "stream", text: ["\n "] },
282 { output_type: "display_data", data: {} },
283 { data: { "text/html": [""] } },
284 { data: { "text/html": [], "text/plain": "array fallback" } },
285 { data: { "text/html": "", "text/plain": "string fallback" } },
286 { data: { "text/html": " ", "text/plain": "space fallback" } },
287 { output_type: "stream", text: ["42\n"] },
288 { data: { "text/html": ["<b>Results</b>"], "text/plain": ["Results"] } },
289 ],
290 },
291 ],
292 }),
293 ),
294 );
295 expect(result).toEqual({
296 type: "notebook",
297 language: "python",
298 cells: [
299 { kind: "markdown", source: "# Results", outputs: [] },
300 {
301 kind: "code",
302 source: "print(42)",
303 outputs: [
304 { kind: "text", text: "array fallback" },
305 { kind: "text", text: "string fallback" },
306 { kind: "text", text: "space fallback" },
307 { kind: "text", text: "42\n" },
308 { kind: "html", text: "<b>Results</b>" },
309 ],
310 },
311 ],
312 });
313 // IPython traceback frames can omit trailing newlines or place ANSI resets after them.
314 const failed = openNotebook(
315 bytes(
316 JSON.stringify({
317 nbformat: 4,
318 cells: [
319 {
320 cell_type: "code",
321 source: "fail()",
322 outputs: [
323 {
324 output_type: "error",
325 traceback: [
326 "-----",
327 "ValueError Traceback (most recent call last)",
328 "Cell In[1], line 4\n----> 4 fail()\n",
329 "Cell In[1], line 2, in fail()\n----> 2 raise ValueError()\n",
330 "ValueError: preview proof",
331 ],
332 },
333 {
334 output_type: "error",
335 traceback: [
336 "Traceback (most recent call last):\n",
337 " Cell In[2], line 5\n fail()\n",
338 "ValueError: preview proof\n",
339 ],
340 },
341 {
342 output_type: "error",
343 traceback: [
344 "\u001b[31mTraceback (most recent call last):\n\u001b[0m",
345 "\u001b[32mCell In[3], line 1\n----> 1 fail()\n\u001b[0m\u001b[39m",
346 "\u001b[31mValueError: preview proof\u001b[0m",
347 "final entry",
348 ],
349 },
350 ],
351 },
352 ],
353 }),
354 ),
355 );
356 if (failed.type !== "notebook") throw new Error("Expected notebook");
357 expect(failed.cells[0]!.outputs).toEqual([
358 {
359 kind: "text",
360 text: "-----\nValueError Traceback (most recent call last)\nCell In[1], line 4\n----> 4 fail()\nCell In[1], line 2, in fail()\n----> 2 raise ValueError()\nValueError: preview proof",
361 },
362 {
363 kind: "text",
364 text: "Traceback (most recent call last):\n Cell In[2], line 5\n fail()\nValueError: preview proof\n",
365 },
366 {
367 kind: "text",
368 text: "Traceback (most recent call last):\nCell In[3], line 1\n----> 1 fail()\nValueError: preview proof\nfinal entry",
369 },
370 ]);
371 expect(() => openNotebook(bytes('{"nbformat":3,"cells":[]}'))).toThrow("version 4");
372 expect(() =>
373 openNotebook(
374 bytes(JSON.stringify({ nbformat: 4, cells: Array.from({ length: 501 }, () => ({})) })),
375 ),
376 ).toThrow("500 cells");
377 });
378
379 it("bounds repeated OpenDocument spreadsheet cells and keeps sheet names and values", async () => {
380 const archive = new JSZip().file(
381 "content.xml",
382 '<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"><office:body><office:spreadsheet><table:table table:name="Budget"><table:table-row table:number-rows-repeated="999999999"><table:table-cell table:number-columns-repeated="999999999"><text:p>Research & design</text:p></table:table-cell></table:table-row></table:table></office:spreadsheet></office:body></office:document-content>',
383 );
384 const result = await openDocument(archive, "ods");
385 expect(result.type).toBe("ods");
386 if (result.type !== "ods") throw new Error("Expected workbook");
387 expect(result.sheets[0]!.name).toBe("Budget");
388 expect(result.sheets[0]!.truncated).toBe(true);
389 expect(result.sheets[0]!.rows).toHaveLength(500);
390 expect(result.sheets[0]!.rows[0]).toHaveLength(50);
391 expect(result.sheets[0]!.rows[0]![0]).toBe("Research & design");
392 });
393
394 it("reads an ODS time cell that has no display paragraph", async () => {
395 const archive = new JSZip().file(
396 "content.xml",
397 `<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"><office:body><office:spreadsheet><table:table table:name="Values"><table:table-row><table:table-cell office:value-type="time" office:time-value="PT03H30M00S"></table:table-cell></table:table-row></table:table></office:spreadsheet></office:body></office:document-content>`,
398 );
399 const result = await openDocument(archive, "ods");
400 if (result.type !== "ods") throw new Error("Expected workbook");
401 expect(result.sheets[0]!.rows).toEqual([["PT03H30M00S"]]);
402 });
403
404 it.each([1, 500])("ignores styled ODS filler after %s populated rows", async (count) => {
405 const archive = new JSZip().file(
406 "content.xml",
407 `<office:document><table:table><table:table-row table:number-rows-repeated="${count}"><table:table-cell><text:p>North</text:p></table:table-cell><table:table-cell table:number-columns-repeated="1024"/></table:table-row><table:table-row table:number-rows-repeated="1048570"><table:table-cell table:number-columns-repeated="1024"/></table:table-row></table:table></office:document>`,
408 );
409 const result = await openDocument(archive, "ods");
410 if (result.type !== "ods") throw new Error("Expected workbook");
411 expect(result.sheets[0]).toMatchObject({ rowCount: count, columns: 1, truncated: false });
412 expect(result.sheets[0]!.rows).toEqual(Array.from({ length: count }, () => ["North"]));
413 });
414
415 it.each([2, 999999])(
416 "preserves internal ODS gaps of %s rows and reports real overflow",
417 async (gap) => {
418 const archive = new JSZip().file(
419 "content.xml",
420 `<office:document><table:table><table:table-row><table:table-cell><text:p>First</text:p></table:table-cell></table:table-row><table:table-row table:number-rows-repeated="${gap}"><table:table-cell/></table:table-row><table:table-row><table:table-cell table:number-columns-repeated="2"/><table:table-cell><text:p>Last</text:p></table:table-cell></table:table-row></table:table></office:document>`,
421 );
422 const result = await openDocument(archive, "ods");
423 if (result.type !== "ods") throw new Error("Expected workbook");
424 expect(result.sheets[0]).toMatchObject({
425 rowCount: Math.min(gap + 2, 500),
426 columns: gap === 2 ? 3 : 1,
427 truncated: gap !== 2,
428 });
429 expect(result.sheets[0]!.rows[1]).toEqual([]);
430 if (gap === 2) expect(result.sheets[0]!.rows[3]).toEqual(["", "", "Last"]);
431 },
432 );
433
434 const approved = "<text:p>Approved <text:span>now</text:span></text:p>";
435 const approvedRow = `<tr>${"<td><p>Approved <span>now</span></p></td>".repeat(2)}</tr>`;
436 it.each([
437 [
438 "expands",
439 `<table:table-row>${`<table:table-cell>${approved}</table:table-cell>`.repeat(2)}</table:table-row><table:table-row table:number-rows-repeated="2"><table:table-cell table:number-columns-repeated="2">${approved}</table:table-cell></table:table-row>`,
440 approvedRow.repeat(3),
441 ],
442 [
443 "bounds",
444 '<table:table-row table:number-rows-repeated="999999999"><table:table-cell table:number-columns-repeated="999999999"><text:p>x</text:p></table:table-cell></table:table-row>',
445 `<tr>${"<td><p>x</p></td>".repeat(50)}</tr>`.repeat(500),
446 ],
447 ])("%s repeated ODT table rows and cells", async (_, rows, html) => {
448 const archive = new JSZip().file(
449 "content.xml",
450 `<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"><office:body><office:text><table:table><table:table-column table:number-columns-repeated="2"/>${rows}</table:table></office:text></office:body></office:document-content>`,
451 );
452 const result = await openDocument(archive, "odt");
453 if (result.type !== "document") throw new Error("Expected document");
454 expect(result.pages[0]!.html).toBe(`<table>${html}</table>`);
455 });
456
457 it.each(["odt", "odp"] as const)("reads %s text and rejects XML entities", async (kind) => {
458 const archive = new JSZip().file(
459 "content.xml",
460 `<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"><office:body>${kind === "odt" ? "<office:text><text:p>Field notes</text:p></office:text>" : '<draw:page draw:name="Overview"><text:h>Launch plan</text:h></draw:page>'}</office:body></office:document-content>`,
461 );
462 const result = await openDocument(archive, kind);
463 expect(result.type).toBe("document");
464 if (result.type !== "document") throw new Error("Expected document");
465 expect(result.pages[0]!.html).toContain(kind === "odt" ? "Field notes" : "Launch plan");
466 archive.file(
467 "content.xml",
468 '<!DOCTYPE x [<!ENTITY external SYSTEM "file:///etc/passwd">]><x>&external;</x>',
469 );
470 await expect(openDocument(archive, kind)).rejects.toThrow("unsupported XML");
471 });
472
473 it("reads EPUB chapters in spine order and removes active and remote content", async () => {
474 const archive = new JSZip()
475 .file(
476 "META-INF/container.xml",
477 '<container><rootfiles><rootfile full-path="Book/book.opf"/></rootfiles></container>',
478 )
479 .file(
480 "Book/book.opf",
481 '<package><manifest><item id="a" href="one.xhtml" media-type="application/xhtml+xml"/><item id="b" href="two&&&.xhtml" media-type="application/xhtml+xml"/></manifest><spine><itemref idref="b"/><itemref idref="a"/></spine></package>',
482 )
483 .file(
484 "Book/one.xhtml",
485 '<html><head><title>First</title></head><body><h1>First chapter</h1><img src="cover.png" alt="Cover"/><img src="https://example.com/tracker.png"/><script>alert(1)</script><style>@import "https://example.com/style.css";</style></body></html>',
486 )
487 .file(
488 "Book/two&&&.xhtml",
489 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><head><title>Second</title></head><body><h1>Second chapter</h1><p>A B © — ≂̸ &lt;</p><pre><![CDATA[Use & and < literally]]></pre><img src="cover.png" alt="© ≂̸"/></body></html>',
490 )
491 .file(
492 "Book/cover.png",
493 Buffer.from(
494 "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIHWP4z8DwHwAFgAI/ScLbtAAAAABJRU5ErkJggg==",
495 "base64",
496 ),
497 );
498 const result = await openEpub(archive);
499 expect(result.type).toBe("document");
500 if (result.type !== "document") throw new Error("Expected document");
501 expect(result.pages.map((page) => page.title)).toEqual(["Second", "First"]);
502 expect(result.pages[0]!.html).toContain("A\u00a0B © — ≂̸ &lt;");
503 expect(result.pages[0]!.html).toContain("<pre>Use &amp; and &lt; literally</pre>");
504 expect(result.pages[0]!.html).toContain('alt="© ≂̸"');
505 expect(result.pages[1]!.html).toContain('src="data:image/png;base64,');
506 expect(result.pages[1]!.html).not.toMatch(/https:|script|alert/);
507 });
508});