import dedent from "dedent" import { describe, test, expect, beforeAll } from "vitest" import { Herb } from "@herb-tools/node-wasm" import { IdentityPrinter } from "@herb-tools/printer" import { Minifier, minify } from "../src/index.js" describe("Minifier", () => { let minifier: Minifier beforeAll(async () => { minifier = new Minifier(Herb) await minifier.initialize() }) describe("top-level minify function", () => { test("minify", () => { const template = `
This is a test
This is a test
a b
`)).toBe(`a b
`) }) test("collapses a run of whitespace between two inline elements to one space", () => { expect(minifier.minifyString(`a \n b
`)).toBe(`a b
`) }) test("keeps the spaces around an inline element inside a sentence", () => { expect(minifier.minifyString(`one two three
`)).toBe(`one two three
`) }) test("drops the whitespace between two block elements", () => { expect(minifier.minifyString(`a
b
a
b
world
world
world
world tags", () => {
const template = dedent`
Line 1
Line 2
Line 3
`
const result = minifier.minifyString(template)
expect(result).toBe(dedent`
Line 1
Line 2
Line 3
`)
})
test("collapses whitespace in tags, which render with `white-space: normal`", () => {
const template = dedent`
const x = 1
const y = 2
`
const result = minifier.minifyString(template)
expect(result).toBe(`const x = 1 const y = 2`)
})
test("preserves whitespace in