tailwindcss/tests/layer-without-tailwind.test.js
Robin Malfait a4f1ff9052
Improve CSS output in tests to better reflect reality (#10454)
* drop empty lines when diffing output

* replace expected css with optimized lightningcss output

Lightning CSS generates a more optimal CSS output.

Right now the tests are setup in a way that both the generated css and
expected css are run through `lightningcss` to make sure that the output
is concistent for the `stable` and `oxide` engines. But this also means
that the expected output _could_ be larger (aka not optimized) and still
matches (after it runs through lightningcss).

By replacing this with the more optimal output we achieve a few things:

1. This better reflects reality since we will be using `lightningcss`.
2. This gets rid of unnecessary css.
3. Removed code!
2023-01-31 15:37:49 +01:00

82 lines
1.7 KiB
JavaScript

import { crosscheck, run, html, css } from './util/run'
crosscheck(() => {
test('using @layer without @tailwind', async () => {
let config = {
content: [{ raw: html`<div class="foo"></div>` }],
}
let input = css`
@layer components {
.foo {
color: black;
}
}
`
await expect(run(input, config)).rejects.toThrowError(
'`@layer components` is used but no matching `@tailwind components` directive is present.'
)
})
test('using @responsive without @tailwind', async () => {
let config = {
content: [{ raw: html`<div class="foo"></div>` }],
}
let input = css`
@responsive {
.foo {
color: black;
}
}
`
await expect(run(input, config)).rejects.toThrowError(
'`@responsive` is used but `@tailwind utilities` is missing.'
)
})
test('using @variants without @tailwind', async () => {
let config = {
content: [{ raw: html`<div class="foo"></div>` }],
}
let input = css`
@variants hover {
.foo {
color: black;
}
}
`
await expect(run(input, config)).rejects.toThrowError(
'`@variants` is used but `@tailwind utilities` is missing.'
)
})
test('non-Tailwind @layer rules are okay', async () => {
let config = {
content: [{ raw: html`<div class="foo"></div>` }],
}
let input = css`
@layer custom {
.foo {
color: black;
}
}
`
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
@layer custom {
.foo {
color: #000;
}
}
`)
})
})
})