collapse-duplicate-declarations.test.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import { run, css, html } 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: 100px;
  67. height: 50%;
  68. }
  69. `)
  70. })
  71. })
  72. it('should collapse the duplicate declarations with the same unit, but leave the ones with different units', () => {
  73. let config = {
  74. content: [{ raw: html`<div class="example"></div>` }],
  75. corePlugins: { preflight: false },
  76. plugins: [],
  77. }
  78. let input = css`
  79. @tailwind utilities;
  80. @layer utilities {
  81. .example {
  82. height: 100px;
  83. height: 50%;
  84. height: 20vh;
  85. height: 200px;
  86. height: 100%;
  87. height: 30vh;
  88. }
  89. }
  90. `
  91. return run(input, config).then((result) => {
  92. expect(result.css).toMatchFormattedCss(css`
  93. .example {
  94. height: 200px;
  95. height: 100%;
  96. height: 30vh;
  97. }
  98. `)
  99. })
  100. })
  101. it('should collapse the duplicate declarations with the exact same value', () => {
  102. let config = {
  103. content: [{ raw: html`<div class="example"></div>` }],
  104. corePlugins: { preflight: false },
  105. plugins: [],
  106. }
  107. let input = css`
  108. @tailwind utilities;
  109. @layer utilities {
  110. .example {
  111. height: var(--value);
  112. color: blue;
  113. height: var(--value);
  114. }
  115. }
  116. `
  117. return run(input, config).then((result) => {
  118. expect(result.css).toMatchFormattedCss(css`
  119. .example {
  120. color: blue;
  121. height: var(--value);
  122. }
  123. `)
  124. })
  125. })
  126. it('should work on a real world example', () => {
  127. let config = {
  128. content: [{ raw: html`<div class="h-available"></div>` }],
  129. corePlugins: { preflight: false },
  130. plugins: [],
  131. }
  132. let input = css`
  133. @tailwind utilities;
  134. @layer utilities {
  135. .h-available {
  136. height: 100%;
  137. height: 100vh;
  138. height: -webkit-fill-available;
  139. }
  140. }
  141. `
  142. return run(input, config).then((result) => {
  143. expect(result.css).toMatchFormattedCss(css`
  144. .h-available {
  145. height: 100%;
  146. height: 100vh;
  147. height: -webkit-fill-available;
  148. }
  149. `)
  150. })
  151. })