collapse-duplicate-declarations.test.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import { run, html, css } from './util/run'
  2. it('should collapse duplicate declarations with the same units (px)', () => {
  3. let config = {
  4. content: [{ raw: html`<div class="example"></div>` }],
  5. corePlugins: { preflight: false },
  6. plugins: [],
  7. }
  8. let input = css`
  9. @tailwind utilities;
  10. @layer utilities {
  11. .example {
  12. height: 100px;
  13. height: 200px;
  14. }
  15. }
  16. `
  17. return run(input, config).then((result) => {
  18. expect(result.css).toMatchFormattedCss(css`
  19. .example {
  20. height: 200px;
  21. }
  22. `)
  23. })
  24. })
  25. it('should collapse duplicate declarations with the same units (no unit)', () => {
  26. let config = {
  27. content: [{ raw: html`<div class="example"></div>` }],
  28. corePlugins: { preflight: false },
  29. plugins: [],
  30. }
  31. let input = css`
  32. @tailwind utilities;
  33. @layer utilities {
  34. .example {
  35. line-height: 3;
  36. line-height: 2;
  37. }
  38. }
  39. `
  40. return run(input, config).then((result) => {
  41. expect(result.css).toMatchFormattedCss(css`
  42. .example {
  43. line-height: 2;
  44. }
  45. `)
  46. })
  47. })
  48. it('should not collapse duplicate declarations with the different units', () => {
  49. let config = {
  50. content: [{ raw: html`<div class="example"></div>` }],
  51. corePlugins: { preflight: false },
  52. plugins: [],
  53. }
  54. let input = css`
  55. @tailwind utilities;
  56. @layer utilities {
  57. .example {
  58. height: 100px;
  59. height: 50%;
  60. }
  61. }
  62. `
  63. return run(input, config).then((result) => {
  64. expect(result.css).toMatchFormattedCss(css`
  65. .example {
  66. height: 50%;
  67. }
  68. `)
  69. })
  70. })
  71. it('should collapse the duplicate declarations with the same unit, but leave the ones with different units', () => {
  72. let config = {
  73. content: [{ raw: html`<div class="example"></div>` }],
  74. corePlugins: { preflight: false },
  75. plugins: [],
  76. }
  77. let input = css`
  78. @tailwind utilities;
  79. @layer utilities {
  80. .example {
  81. height: 100px;
  82. height: 50%;
  83. height: 20vh;
  84. height: 200px;
  85. height: 100%;
  86. height: 30vh;
  87. }
  88. }
  89. `
  90. return run(input, config).then((result) => {
  91. expect(result.css).toMatchFormattedCss(css`
  92. .example {
  93. height: 30vh;
  94. }
  95. `)
  96. })
  97. })
  98. it('should collapse the duplicate declarations with the exact same value', () => {
  99. let config = {
  100. content: [{ raw: html`<div class="example"></div>` }],
  101. corePlugins: { preflight: false },
  102. plugins: [],
  103. }
  104. let input = css`
  105. @tailwind utilities;
  106. @layer utilities {
  107. .example {
  108. height: var(--value);
  109. color: blue;
  110. height: var(--value);
  111. }
  112. }
  113. `
  114. return run(input, config).then((result) => {
  115. expect(result.css).toMatchFormattedCss(css`
  116. .example {
  117. color: #00f;
  118. height: var(--value);
  119. }
  120. `)
  121. })
  122. })
  123. it('should work on a real world example', () => {
  124. let config = {
  125. content: [{ raw: html`<div class="h-available"></div>` }],
  126. corePlugins: { preflight: false },
  127. plugins: [],
  128. }
  129. let input = css`
  130. @tailwind utilities;
  131. @layer utilities {
  132. .h-available {
  133. height: 100%;
  134. height: 100vh;
  135. height: -moz-available;
  136. height: -webkit-fill-available;
  137. }
  138. }
  139. `
  140. // TODO: This seems like a bug with compat data
  141. // `-moz-available` should still be listed
  142. // and most like `100vh` as well
  143. return run(input, config).then((result) => {
  144. expect(result.css).toMatchFormattedCss(css`
  145. .h-available {
  146. height: -webkit-fill-available;
  147. }
  148. `)
  149. })
  150. })