Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off
2import * as NodeFSP from "node:fs/promises";
3import * as NodeOS from "node:os";
4import * as NodePath from "node:path";
5import { expect, it } from "vite-plus/test";
6import { extractDocumentText } from "./documentTextWorker.ts";
7β
8const cellHeading = "## Cell 1 (code)\n";
9const outputHeading = "\nOutput:\n";
10β
11it.each([
12 {
13 name: "omits the output heading when only half an emoji fits after it",
14 source: "x".repeat(1_000_000 - cellHeading.length - outputHeading.length - 1),
15 outputs: ["π"],
16 remainder: "\n\n[Extracted text truncated at document extraction limits.]",
17 },
18 {
19 name: "keeps reading after a high surrogate in an output below the limit",
20 source: "run()",
21 outputs: ["\uD83D", "\uDE00"],
22 remainder: "\nOutput:\n\uD83D\n\uDE00\n\n## Cell 2 (markdown)\nLater cell",
23 },
24])("$name", async ({ source, outputs, remainder }) => {
25 const folder = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-notebook-budget-"));
26 try {
27 const path = NodePath.join(folder, "output.ipynb");
28 await NodeFSP.writeFile(
29 path,
30 JSON.stringify({
31 cells: [
32 {
33 cell_type: "code",
34 source,
35 outputs: outputs.map((text) => ({ output_type: "stream", text })),
36 },
37 { cell_type: "markdown", source: "Later cell" },
38 ],
39 }),
40 );
41 const extracted = await extractDocumentText(path, ".ipynb");
42 expect(extracted.slice(source.length + cellHeading.length)).toBe(remainder);
43 } finally {
44 await NodeFSP.rm(folder, { recursive: true, force: true });
45 }
46});