123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- import { run, html, css, defaults } from './util/run'
- test('custom user-land utilities', () => {
- let config = {
- content: [
- {
- raw: html`<div
- class="focus:hover:align-chocolate align-banana hover:align-banana uppercase"
- ></div>`,
- },
- ],
- corePlugins: { preflight: false },
- theme: {},
- plugins: [],
- }
- let input = css`
- @layer utilities {
- .align-banana {
- text-align: banana;
- }
- }
- @tailwind base;
- @tailwind components;
- @tailwind utilities;
- @layer utilities {
- .align-chocolate {
- text-align: chocolate;
- }
- }
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- ${defaults}
- .uppercase {
- text-transform: uppercase;
- }
- .align-banana,
- .hover\:align-banana:hover {
- text-align: banana;
- }
- .focus\:hover\:align-chocolate:hover:focus {
- text-align: chocolate;
- }
- `)
- })
- })
- test('comments can be used inside layers without crashing', () => {
- let config = {
- content: [
- {
- raw: html`<div class="important-utility important-component"></div>`,
- },
- ],
- corePlugins: { preflight: false },
- theme: {},
- plugins: [],
- }
- let input = css`
- @tailwind base;
- @tailwind components;
- @tailwind utilities;
- @layer base {
- /* Important base */
- div {
- background-color: #bada55;
- }
- }
- @layer utilities {
- /* Important utility */
- .important-utility {
- text-align: banana;
- }
- }
- @layer components {
- /* Important component */
- .important-component {
- text-align: banana;
- }
- }
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- div {
- background-color: #bada55;
- }
- ${defaults}
- .important-component,
- .important-utility {
- text-align: banana;
- }
- `)
- })
- })
- test('comments can be used inside layers (with important) without crashing', () => {
- let config = {
- important: true,
- content: [
- {
- raw: html`<div class="important-utility important-component"></div>`,
- },
- ],
- corePlugins: { preflight: false },
- theme: {},
- plugins: [],
- }
- let input = css`
- @tailwind base;
- @tailwind components;
- @tailwind utilities;
- @layer base {
- /* Important base */
- div {
- background-color: #bada55;
- }
- }
- @layer utilities {
- /* Important utility */
- .important-utility {
- text-align: banana;
- }
- }
- @layer components {
- /* Important component */
- .important-component {
- text-align: banana;
- }
- }
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- div {
- background-color: #bada55;
- }
- ${defaults}
- .important-component {
- text-align: banana;
- }
- .important-utility {
- text-align: banana !important;
- }
- `)
- })
- })
- test('layers are grouped and inserted at the matching @tailwind rule', () => {
- let config = {
- content: [
- {
- raw: html`<div class="input btn card float-squirrel align-banana align-sandwich"></div>`,
- },
- ],
- plugins: [
- function ({ addBase, addComponents, addUtilities }) {
- addBase({ body: { margin: 0 } })
- addComponents({
- '.input': { background: 'white' },
- })
- addUtilities({
- '.float-squirrel': { float: 'squirrel' },
- })
- },
- ],
- corePlugins: { preflight: false },
- }
- let input = css`
- @layer vanilla {
- strong {
- font-weight: medium;
- }
- }
- @tailwind base;
- @tailwind components;
- @tailwind utilities;
- @layer components {
- .btn {
- background: blue;
- }
- }
- @layer utilities {
- .align-banana {
- text-align: banana;
- }
- }
- @layer base {
- h1 {
- font-weight: bold;
- }
- }
- @layer components {
- .card {
- border-radius: 12px;
- }
- }
- @layer base {
- p {
- font-weight: normal;
- }
- }
- @layer utilities {
- .align-sandwich {
- text-align: sandwich;
- }
- }
- @layer chocolate {
- a {
- text-decoration: underline;
- }
- }
- `
- expect.assertions(2)
- return run(input, config).then((result) => {
- expect(result.warnings().length).toBe(0)
- expect(result.css).toMatchFormattedCss(css`
- @layer vanilla {
- strong {
- font-weight: medium;
- }
- }
- body {
- margin: 0;
- }
- h1 {
- font-weight: bold;
- }
- p {
- font-weight: normal;
- }
- ${defaults}
- .input {
- background: #fff;
- }
- .btn {
- background: #00f;
- }
- .card {
- border-radius: 12px;
- }
- .float-squirrel {
- float: squirrel;
- }
- .align-banana {
- text-align: banana;
- }
- .align-sandwich {
- text-align: sandwich;
- }
- @layer chocolate {
- a {
- text-decoration: underline;
- }
- }
- `)
- })
- })
- it('should keep `@supports` rules inside `@layer`s', () => {
- let config = {
- content: [{ raw: html`<div class="test"></div>` }],
- plugins: [],
- }
- let input = css`
- @tailwind utilities;
- @layer utilities {
- .test {
- --tw-test: 1;
- }
- @supports (backdrop-filter: blur(1px)) {
- .test {
- --tw-test: 0.9;
- }
- }
- }
- `
- return run(input, config).then((result) => {
- return expect(result.css).toMatchFormattedCss(css`
- .test {
- --tw-test: 1;
- }
- @supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
- .test {
- --tw-test: 0.9;
- }
- }
- `)
- })
- })
|