Skip to content

Commit bfc9fa7

Browse files
authored
Improve tests (tailwindlabs#5108)
* change specific selector to universal selector This is the commit that we could "undo" in the future if we need it again. * simplify `relative-purge-paths` test This test doesn't require the "reset" selector (whether it is super specific or universal) Simplified it so that it tests the relative purge config and nothing else. * added css tagged template literal helpers This allows prettier to format the string as CSS. This improves formatting and will improve future diffs. * drop tailwind headers in the sanity tests Every time we bump the Tailwind version, the sanity tests fail, because the current version is encoded in the fixture files. This will ensure that all of the contents is still checked and the header is skipped. The header will be tested against a regex to ensure that it is still there. This should be a small but nice QoL improvement, so that we don't have to think about updating those tests whenever we fix bugs or land new features.
1 parent f7e9831 commit bfc9fa7

11 files changed

+217
-1304
lines changed

tests/jit/basic-usage.test.css

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
.translate-x-5,
2-
.-translate-x-4,
3-
.translate-y-6,
4-
.-translate-x-3,
5-
.rotate-3,
6-
.skew-y-12,
7-
.skew-x-12,
8-
.scale-95,
9-
.transform {
1+
*,
2+
::before,
3+
::after {
104
--tw-translate-x: 0;
115
--tw-translate-y: 0;
126
--tw-rotate: 0;
@@ -17,41 +11,18 @@
1711
--tw-transform: translateX(var(--tw-translate-x)) translateY(var(--tw-translate-y))
1812
rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y))
1913
scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
20-
}
21-
.border,
22-
.border-2,
23-
.border-t,
24-
.border-b-4 {
2514
--tw-border-opacity: 1;
2615
border-color: rgba(229, 231, 235, var(--tw-border-opacity));
27-
}
28-
.shadow,
29-
.shadow-md,
30-
.shadow-lg {
3116
--tw-ring-offset-shadow: 0 0 #0000;
3217
--tw-ring-shadow: 0 0 #0000;
3318
--tw-shadow: 0 0 #0000;
34-
}
35-
.ring,
36-
.ring-4 {
3719
--tw-ring-inset: var(--tw-empty, /*!*/ /*!*/);
3820
--tw-ring-offset-width: 0px;
3921
--tw-ring-offset-color: #fff;
4022
--tw-ring-color: rgba(59, 130, 246, 0.5);
4123
--tw-ring-offset-shadow: 0 0 #0000;
4224
--tw-ring-shadow: 0 0 #0000;
4325
--tw-shadow: 0 0 #0000;
44-
}
45-
.blur-md,
46-
.brightness-150,
47-
.contrast-50,
48-
.drop-shadow-md,
49-
.grayscale,
50-
.hue-rotate-60,
51-
.invert,
52-
.saturate-200,
53-
.sepia,
54-
.filter {
5526
--tw-blur: var(--tw-empty, /*!*/ /*!*/);
5627
--tw-brightness: var(--tw-empty, /*!*/ /*!*/);
5728
--tw-contrast: var(--tw-empty, /*!*/ /*!*/);
@@ -63,17 +34,6 @@
6334
--tw-drop-shadow: var(--tw-empty, /*!*/ /*!*/);
6435
--tw-filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale)
6536
var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
66-
}
67-
.backdrop-blur-lg,
68-
.backdrop-brightness-50,
69-
.backdrop-contrast-0,
70-
.backdrop-grayscale,
71-
.backdrop-hue-rotate-90,
72-
.backdrop-invert,
73-
.backdrop-opacity-75,
74-
.backdrop-saturate-150,
75-
.backdrop-sepia,
76-
.backdrop-filter {
7737
--tw-backdrop-blur: var(--tw-empty, /*!*/ /*!*/);
7838
--tw-backdrop-brightness: var(--tw-empty, /*!*/ /*!*/);
7939
--tw-backdrop-contrast: var(--tw-empty, /*!*/ /*!*/);

tests/jit/basic-usage.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ function run(input, config = {}) {
99
})
1010
}
1111

12+
function css(templates) {
13+
return templates.join('')
14+
}
15+
1216
test('basic usage', () => {
1317
let config = {
1418
mode: 'jit',
@@ -18,13 +22,13 @@ test('basic usage', () => {
1822
plugins: [],
1923
}
2024

21-
let css = `
25+
let input = css`
2226
@tailwind base;
2327
@tailwind components;
2428
@tailwind utilities;
2529
`
2630

27-
return run(css, config).then((result) => {
31+
return run(input, config).then((result) => {
2832
let expectedPath = path.resolve(__dirname, './basic-usage.test.css')
2933
let expected = fs.readFileSync(expectedPath, 'utf8')
3034

tests/jit/kitchen-sink.test.css

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@
126126
}
127127
}
128128
}
129-
.scale-50,
130-
.transform,
131-
.hover\:scale-75 {
129+
*,
130+
::before,
131+
::after {
132132
--tw-translate-x: 0;
133133
--tw-translate-y: 0;
134134
--tw-rotate: 0;
@@ -139,16 +139,9 @@
139139
--tw-transform: translateX(var(--tw-translate-x)) translateY(var(--tw-translate-y))
140140
rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y))
141141
scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
142-
}
143-
.shadow-sm,
144-
.shadow-md,
145-
.hover\:shadow-lg,
146-
.md\:shadow-sm {
147142
--tw-ring-offset-shadow: 0 0 #0000;
148143
--tw-ring-shadow: 0 0 #0000;
149144
--tw-shadow: 0 0 #0000;
150-
}
151-
.focus\:ring-2 {
152145
--tw-ring-inset: var(--tw-empty, /*!*/ /*!*/);
153146
--tw-ring-offset-width: 0px;
154147
--tw-ring-offset-color: #fff;

tests/jit/kitchen-sink.test.js

Lines changed: 89 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ function run(input, config = {}) {
99
})
1010
}
1111

12+
function css(templates) {
13+
return templates.join('')
14+
}
15+
1216
test('it works', () => {
1317
let config = {
1418
darkMode: 'class',
@@ -71,100 +75,101 @@ test('it works', () => {
7175
],
7276
}
7377

74-
let css = `
75-
@layer utilities {
76-
.custom-util {
77-
background: #abcdef;
78+
let input = css`
79+
@layer utilities {
80+
.custom-util {
81+
background: #abcdef;
82+
}
83+
*,
84+
::before,
85+
::after {
86+
margin: 10px;
87+
}
7888
}
79-
*,
80-
::before,
81-
::after {
82-
margin: 10px;
89+
@layer components {
90+
.test-apply-font-variant {
91+
@apply ordinal tabular-nums;
92+
}
93+
.custom-component {
94+
background: #123456;
95+
}
96+
*,
97+
::before,
98+
::after {
99+
padding: 5px;
100+
}
101+
.foo .bg-black {
102+
appearance: none;
103+
}
83104
}
84-
}
85-
@layer components {
86-
.test-apply-font-variant {
87-
@apply ordinal tabular-nums;
105+
@layer base {
106+
div {
107+
background: #654321;
108+
}
88109
}
89-
.custom-component {
90-
background: #123456;
110+
.theme-test {
111+
font-family: theme('fontFamily.sans');
112+
color: theme('colors.blue.500');
91113
}
92-
*,
93-
::before,
94-
::after {
95-
padding: 5px;
114+
@screen lg {
115+
.screen-test {
116+
color: purple;
117+
}
96118
}
97-
.foo .bg-black {
98-
appearance: none;
119+
.apply-1 {
120+
@apply mt-6;
99121
}
100-
}
101-
@layer base {
102-
div {
103-
background: #654321;
122+
.apply-2 {
123+
@apply mt-6;
104124
}
105-
}
106-
.theme-test {
107-
font-family: theme('fontFamily.sans');
108-
color: theme('colors.blue.500');
109-
}
110-
@screen lg {
111-
.screen-test {
112-
color: purple;
125+
.apply-test {
126+
@apply mt-6 bg-pink-500 hover:font-bold focus:hover:font-bold sm:bg-green-500 sm:focus:even:bg-pink-200;
113127
}
114-
}
115-
.apply-1 {
116-
@apply mt-6;
117-
}
118-
.apply-2 {
119-
@apply mt-6;
120-
}
121-
.apply-test {
122-
@apply mt-6 bg-pink-500 hover:font-bold focus:hover:font-bold sm:bg-green-500 sm:focus:even:bg-pink-200;
123-
}
124-
.apply-components {
125-
@apply container mx-auto;
126-
}
127-
.drop-empty-rules {
128-
@apply hover:font-bold;
129-
}
130-
.apply-group {
131-
@apply group-hover:font-bold;
132-
}
133-
.apply-dark-mode {
134-
@apply dark:font-bold;
135-
}
136-
.apply-with-existing:hover {
137-
@apply font-normal sm:bg-green-500;
138-
}
139-
.multiple, .selectors {
140-
@apply font-bold group-hover:font-normal;
141-
}
142-
.list {
143-
@apply space-x-4;
144-
}
145-
.nested {
146-
.example {
147-
@apply font-bold hover:font-normal;
128+
.apply-components {
129+
@apply container mx-auto;
148130
}
149-
}
150-
.apply-order-a {
151-
@apply m-5 mt-6;
152-
}
153-
.apply-order-b {
154-
@apply mt-6 m-5;
155-
}
156-
.apply-dark-group-example-a {
157-
@apply dark:group-hover:bg-green-500;
158-
}
159-
.crazy-example {
160-
@apply sm:motion-safe:group-active:focus:opacity-10;
161-
}
162-
@tailwind base;
163-
@tailwind components;
164-
@tailwind utilities;
165-
`
131+
.drop-empty-rules {
132+
@apply hover:font-bold;
133+
}
134+
.apply-group {
135+
@apply group-hover:font-bold;
136+
}
137+
.apply-dark-mode {
138+
@apply dark:font-bold;
139+
}
140+
.apply-with-existing:hover {
141+
@apply font-normal sm:bg-green-500;
142+
}
143+
.multiple,
144+
.selectors {
145+
@apply font-bold group-hover:font-normal;
146+
}
147+
.list {
148+
@apply space-x-4;
149+
}
150+
.nested {
151+
.example {
152+
@apply font-bold hover:font-normal;
153+
}
154+
}
155+
.apply-order-a {
156+
@apply m-5 mt-6;
157+
}
158+
.apply-order-b {
159+
@apply mt-6 m-5;
160+
}
161+
.apply-dark-group-example-a {
162+
@apply dark:group-hover:bg-green-500;
163+
}
164+
.crazy-example {
165+
@apply sm:motion-safe:group-active:focus:opacity-10;
166+
}
167+
@tailwind base;
168+
@tailwind components;
169+
@tailwind utilities;
170+
`
166171

167-
return run(css, config).then((result) => {
172+
return run(input, config).then((result) => {
168173
let expectedPath = path.resolve(__dirname, './kitchen-sink.test.css')
169174
let expected = fs.readFileSync(expectedPath, 'utf8')
170175

0 commit comments

Comments
 (0)