kitchen-sink.test.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import fs from 'fs'
  2. import path from 'path'
  3. import { run, css } from './util/run'
  4. test('it works', () => {
  5. let config = {
  6. darkMode: 'class',
  7. content: [path.resolve(__dirname, './kitchen-sink.test.html')],
  8. corePlugins: { preflight: false },
  9. theme: {
  10. extend: {
  11. screens: {
  12. range: { min: '1280px', max: '1535px' },
  13. multi: [{ min: '640px', max: '767px' }, { max: '868px' }],
  14. },
  15. gradientColorStops: {
  16. foo: '#bada55',
  17. },
  18. backgroundImage: {
  19. 'hero--home-1': "url('/images/homepage-1.jpg')",
  20. },
  21. },
  22. },
  23. plugins: [
  24. function ({ addVariant }) {
  25. addVariant(
  26. 'foo',
  27. ({ container }) => {
  28. container.walkRules((rule) => {
  29. rule.selector = `.foo\\:${rule.selector.slice(1)}`
  30. rule.walkDecls((decl) => {
  31. decl.important = true
  32. })
  33. })
  34. },
  35. { before: 'sm' }
  36. )
  37. },
  38. function ({ addUtilities, addBase, theme }) {
  39. addBase({
  40. h1: {
  41. fontSize: theme('fontSize.2xl'),
  42. fontWeight: theme('fontWeight.bold'),
  43. '&:first-child': {
  44. marginTop: '0px',
  45. },
  46. },
  47. })
  48. addUtilities(
  49. {
  50. '.magic-none': {
  51. magic: 'none',
  52. },
  53. '.magic-tons': {
  54. magic: 'tons',
  55. },
  56. },
  57. ['responsive', 'hover']
  58. )
  59. },
  60. ],
  61. }
  62. let input = css`
  63. @layer utilities {
  64. .custom-util {
  65. background: #abcdef;
  66. }
  67. *,
  68. ::before,
  69. ::after,
  70. ::backdrop {
  71. margin: 10px;
  72. }
  73. }
  74. @layer components {
  75. .test-apply-font-variant {
  76. @apply ordinal tabular-nums;
  77. }
  78. .custom-component {
  79. background: #123456;
  80. }
  81. *,
  82. ::before,
  83. ::after,
  84. ::backdrop {
  85. padding: 5px;
  86. }
  87. .foo .bg-black {
  88. appearance: none;
  89. }
  90. }
  91. @layer base {
  92. div {
  93. background: #654321;
  94. }
  95. }
  96. .theme-test {
  97. font-family: theme('fontFamily.sans');
  98. color: theme('colors.blue.500');
  99. }
  100. @screen lg {
  101. .screen-test {
  102. color: purple;
  103. }
  104. }
  105. .apply-1 {
  106. @apply mt-6;
  107. }
  108. .apply-2 {
  109. @apply mt-6;
  110. }
  111. .apply-test {
  112. @apply mt-6 bg-pink-500 hover:font-bold focus:hover:font-bold sm:bg-green-500 sm:focus:even:bg-pink-200;
  113. }
  114. .apply-components {
  115. @apply container mx-auto;
  116. }
  117. .drop-empty-rules {
  118. @apply hover:font-bold;
  119. }
  120. .apply-group {
  121. @apply group-hover:font-bold;
  122. }
  123. .apply-dark-mode {
  124. @apply dark:font-bold;
  125. }
  126. .apply-with-existing:hover {
  127. @apply font-normal sm:bg-green-500;
  128. }
  129. .multiple,
  130. .selectors {
  131. @apply font-bold group-hover:font-normal;
  132. }
  133. .list {
  134. @apply space-x-4;
  135. }
  136. .nested {
  137. .example {
  138. @apply font-bold hover:font-normal;
  139. }
  140. }
  141. .apply-order-a {
  142. @apply m-5 mt-6;
  143. }
  144. .apply-order-b {
  145. @apply m-5 mt-6;
  146. }
  147. .apply-dark-group-example-a {
  148. @apply dark:group-hover:bg-green-500;
  149. }
  150. .crazy-example {
  151. @apply sm:motion-safe:group-active:focus:opacity-10;
  152. }
  153. @tailwind base;
  154. @tailwind components;
  155. @tailwind utilities;
  156. `
  157. return run(input, config).then((result) => {
  158. let expectedPath = path.resolve(__dirname, './kitchen-sink.test.css')
  159. let expected = fs.readFileSync(expectedPath, 'utf8')
  160. expect(result.css).toMatchFormattedCss(expected)
  161. })
  162. })