Skip to content

Commit

Permalink
add test for empty atrule
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart Veneman committed Feb 17, 2024
1 parent f2371f9 commit da4d7d7
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions test/minify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,32 @@ import { format } from "../index.js"

let test = suite("Minify")

const MINIFY_OPTIONS = { minify: true }

test('empty rule', () => {
let actual = format(`a {}`, {
minify: true
})
let actual = format(`a {}`, MINIFY_OPTIONS)
let expected = `a{}`
assert.equal(actual, expected)
})

test('simple declaration', () => {
let actual = format(`:root { --color: red; }`, {
minify: true
})
let actual = format(`:root { --color: red; }`, MINIFY_OPTIONS)
let expected = `:root{--color:red;}`
assert.equal(actual, expected)
})

test('simple atrule', () => {
let actual = format(`@media (min-width: 100px) { body { color: red; } }`, {
minify: true
})
let actual = format(`@media (min-width: 100px) { body { color: red; } }`, MINIFY_OPTIONS)
let expected = `@media (min-width: 100px){body{color:red;}}`
assert.equal(actual, expected)
})

test('empty atrule', () => {
let actual = format(`@media (min-width: 100px) {}`, MINIFY_OPTIONS)
let expected = `@media (min-width: 100px){}`
assert.equal(actual, expected)
})

test("formats multiline values on a single line", () => {
let actual = format(`
a {
Expand All @@ -36,7 +38,7 @@ a {
10% blue,
20% green,100% yellow);
}
`, { minify: true });
`, MINIFY_OPTIONS);
let expected = `a{background:linear-gradient(red, 10% blue, 20% green, 100% yellow);}`;
assert.equal(actual, expected);
})
Expand All @@ -54,17 +56,13 @@ test('Vadim Makeevs example works', () => {
}
}
}
`, {
minify: true
})
`, MINIFY_OPTIONS)
let expected = `@layer what{@container (width > 0){ul:has(:nth-child(1 of li)){@media (height > 0){&:hover{--is:this;}}}}}`
assert.equal(actual, expected)
})

test('minified Vadims example', () => {
let actual = format(`@layer what{@container (width>0){@media (min-height:.001px){ul:has(:nth-child(1 of li)):hover{--is:this}}}}`, {
minify: true
})
let actual = format(`@layer what{@container (width>0){@media (min-height:.001px){ul:has(:nth-child(1 of li)):hover{--is:this}}}}`, MINIFY_OPTIONS)
let expected = `@layer what{@container (width > 0){@media (min-height: .001px){ul:has(:nth-child(1 of li)):hover{--is:this;}}}}`
assert.equal(actual, expected)
})
Expand Down

0 comments on commit da4d7d7

Please sign in to comment.