Open History to see the last commit
1import { describe, expect, it } from "@effect/vitest";
2import * as Effect from "effect/Effect";
3import * as Option from "effect/Option";
4import * as Stream from "effect/Stream";
5import { FetchHttpClient } from "effect/http";
6
7import { downloadText } from "./fullFileText";
8import { RENDERED_MAX_LINES } from "./largeTextProtocol";
9
10const encoder = new TextEncoder();
11
12const download = (file: Uint8Array) =>
13 downloadText("http://localhost/assets/file.ts").pipe(
14 Stream.runLast,
15 Effect.map(Option.getOrThrow),
16 Effect.provide(FetchHttpClient.layer),
17 Effect.provideService(FetchHttpClient.Fetch, () => Promise.resolve(new Response(file.slice()))),
18 );
19
20describe("downloadText", () => {
21 it.effect(
22 "drops a leading byte order mark as the preview read does, and keeps a later U+FEFF",
23 () =>
24 Effect.gen(function* () {
25 const whole = new Uint8Array([0xef, 0xbb, 0xbf, ...encoder.encode("one\ntwo\n")]);
26 expect((yield* download(whole)).text).toBe("one\ntwo\n");
27 }),
28 );
29
30 it.effect("stops at the first text past the lines the main thread can lay out", () =>
31 Effect.gen(function* () {
32 const file = yield* download(encoder.encode("\n".repeat(RENDERED_MAX_LINES + 10)));
33 expect(file.lines).toBeGreaterThan(RENDERED_MAX_LINES);
34 }),
35 );
36});