Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

659 B
Raw Blame
import { expect, test } from "vitest";
import { AssetUploadSizeLimitError, createSizeLimiter } from "./size-limiter";

const collect = async (iterable: AsyncIterable<Uint8Array>) => {
  const chunks: Uint8Array[] = [];
  for await (const chunk of iterable) {
    chunks.push(chunk);
  }
  return chunks;
};

test("throws a typed error when streamed upload content exceeds the limit", async () => {
  const source = {
    async *[Symbol.asyncIterator]() {
      yield new Uint8Array(6);
      yield new Uint8Array(5);
    },
  };

  await expect(
    collect(createSizeLimiter(10, "post.md")(source))
  ).rejects.toBeInstanceOf(AssetUploadSizeLimitError);
});