Skip to content

Commit 3693a71

Browse files
authored
Test @import "tailwindcss" prefix(tw) explicitly + move prefix tests (#14566)
I noticed our prefix tests were missing an explicit test for `@import "tailwindcss" prefix(tw)` so this PR tweaks an existing test to test that case. Also noticed that `prefix.test.ts` was in the `compat` folder even though this is a v4 feature, so moved it out to the root. --------- Co-authored-by: Adam Wathan <[email protected]>
1 parent 65240c9 commit 3693a71

File tree

1 file changed

+54
-16
lines changed

1 file changed

+54
-16
lines changed

packages/tailwindcss/src/compat/prefix.test.ts renamed to packages/tailwindcss/src/prefix.test.ts

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from 'vitest'
2-
import { compile } from '..'
3-
import plugin from '../plugin'
2+
import { compile } from '.'
3+
import plugin from './plugin'
44

55
const css = String.raw
66

@@ -198,15 +198,30 @@ test('a prefix can be configured via @import theme(…)', async () => {
198198
async loadStylesheet(id, base) {
199199
return {
200200
base,
201-
content: '@theme {}',
201+
content: css`
202+
@theme {
203+
--color-potato: #7a4724;
204+
}
205+
`,
202206
}
203207
},
204208
})
205209

206210
// Prefixed utilities are generated
207-
expect(compiler.build(['tw:underline', 'tw:hover:line-through', 'tw:custom']))
208-
.toMatchInlineSnapshot(`
209-
".tw\\:custom {
211+
expect(
212+
compiler.build([
213+
'tw:underline',
214+
'tw:bg-potato',
215+
'tw:hover:line-through',
216+
'tw:custom',
217+
'flex',
218+
'text-potato',
219+
]),
220+
).toMatchInlineSnapshot(`
221+
".tw\\:bg-potato {
222+
background-color: var(--tw-color-potato, #7a4724);
223+
}
224+
.tw\\:custom {
210225
color: red;
211226
}
212227
.tw\\:underline {
@@ -227,18 +242,21 @@ test('a prefix can be configured via @import theme(…)', async () => {
227242
async loadStylesheet(id, base) {
228243
return {
229244
base,
230-
content: '@theme {}',
245+
content: css`
246+
@theme {
247+
--color-potato: #7a4724;
248+
}
249+
`,
231250
}
232251
},
233252
})
234253

235-
expect(compiler.build(['underline', 'hover:line-through', 'custom'])).toEqual('')
254+
expect(compiler.build(['underline', 'hover:line-through', 'custom'])).toMatchInlineSnapshot(`""`)
236255
})
237256

238257
test('a prefix can be configured via @import prefix(…)', async () => {
239258
let input = css`
240-
@import 'tailwindcss/theme' prefix(tw);
241-
@tailwind utilities;
259+
@import 'tailwindcss' prefix(tw);
242260
243261
@utility custom {
244262
color: red;
@@ -249,15 +267,25 @@ test('a prefix can be configured via @import prefix(…)', async () => {
249267
async loadStylesheet(id, base) {
250268
return {
251269
base,
252-
content: '@theme reference {}',
270+
content: css`
271+
@theme {
272+
--color-potato: #7a4724;
273+
}
274+
@tailwind utilities;
275+
`,
253276
}
254277
},
255278
})
256279

257-
// Prefixed utilities are generated
258-
expect(compiler.build(['tw:underline', 'tw:hover:line-through', 'tw:custom']))
280+
expect(compiler.build(['tw:underline', 'tw:bg-potato', 'tw:hover:line-through', 'tw:custom']))
259281
.toMatchInlineSnapshot(`
260-
".tw\\:custom {
282+
":root {
283+
--tw-color-potato: #7a4724;
284+
}
285+
.tw\\:bg-potato {
286+
background-color: var(--tw-color-potato, #7a4724);
287+
}
288+
.tw\\:custom {
261289
color: red;
262290
}
263291
.tw\\:underline {
@@ -278,12 +306,22 @@ test('a prefix can be configured via @import prefix(…)', async () => {
278306
async loadStylesheet(id, base) {
279307
return {
280308
base,
281-
content: '@theme reference {}',
309+
content: css`
310+
@theme {
311+
--color-potato: #7a4724;
312+
}
313+
@tailwind utilities;
314+
`,
282315
}
283316
},
284317
})
285318

286-
expect(compiler.build(['underline', 'hover:line-through', 'custom'])).toEqual('')
319+
expect(compiler.build(['underline', 'hover:line-through', 'custom'])).toMatchInlineSnapshot(`
320+
":root {
321+
--tw-color-potato: #7a4724;
322+
}
323+
"
324+
`)
287325
})
288326

289327
test('a prefix must be letters only', async () => {

0 commit comments

Comments
 (0)