1
+ import { __unstable__loadDesignSystem } from '@tailwindcss/node'
1
2
import dedent from 'dedent'
2
3
import postcss from 'postcss'
3
4
import { expect , it } from 'vitest'
4
5
import { migrateAtApply } from './migrate-at-apply'
5
6
6
7
const css = dedent
7
8
8
- function migrate ( input : string ) {
9
+ function migrateWithoutConfig ( input : string ) {
9
10
return postcss ( )
10
11
. use ( migrateAtApply ( ) )
11
12
. process ( input , { from : expect . getState ( ) . testPath } )
@@ -14,7 +15,7 @@ function migrate(input: string) {
14
15
15
16
it ( 'should not migrate `@apply`, when there are no issues' , async ( ) => {
16
17
expect (
17
- await migrate ( css `
18
+ await migrateWithoutConfig ( css `
18
19
.foo {
19
20
@apply flex flex-col items-center;
20
21
}
@@ -28,7 +29,7 @@ it('should not migrate `@apply`, when there are no issues', async () => {
28
29
29
30
it ( 'should append `!` to each utility, when using `!important`' , async ( ) => {
30
31
expect (
31
- await migrate ( css `
32
+ await migrateWithoutConfig ( css `
32
33
.foo {
33
34
@apply flex flex-col !important ;
34
35
}
@@ -43,7 +44,7 @@ it('should append `!` to each utility, when using `!important`', async () => {
43
44
// TODO: Handle SCSS syntax
44
45
it . skip ( 'should append `!` to each utility, when using `#{!important}`' , async ( ) => {
45
46
expect (
46
- await migrate ( css `
47
+ await migrateWithoutConfig ( css `
47
48
.foo {
48
49
@apply flex flex-col # {!important };
49
50
}
@@ -57,7 +58,7 @@ it.skip('should append `!` to each utility, when using `#{!important}`', async (
57
58
58
59
it ( 'should move the legacy `!` prefix, to the new `!` postfix notation' , async ( ) => {
59
60
expect (
60
- await migrate ( css `
61
+ await migrateWithoutConfig ( css `
61
62
.foo {
62
63
@apply !flex flex- col! hover: !items- start items- center;
63
64
}
@@ -68,3 +69,36 @@ it('should move the legacy `!` prefix, to the new `!` postfix notation', async (
68
69
}"
69
70
` )
70
71
} )
72
+
73
+ it ( 'should apply all candidate migration when migrating with a config' , async ( ) => {
74
+ async function migrateWithConfig ( input : string ) {
75
+ return postcss ( )
76
+ . use (
77
+ migrateAtApply ( {
78
+ designSystem : await __unstable__loadDesignSystem (
79
+ css `
80
+ @import 'tailwindcss' prefix(tw);
81
+ ` ,
82
+ { base : __dirname } ,
83
+ ) ,
84
+ userConfig : {
85
+ prefix : 'tw_' ,
86
+ } ,
87
+ } ) ,
88
+ )
89
+ . process ( input , { from : expect . getState ( ) . testPath } )
90
+ . then ( ( result ) => result . css )
91
+ }
92
+
93
+ expect (
94
+ await migrateWithConfig ( css `
95
+ .foo {
96
+ @apply !tw_flex [color : - - my- color ] tw_bg-gradient-to-t ;
97
+ }
98
+ ` ) ,
99
+ ) . toMatchInlineSnapshot ( `
100
+ ".foo {
101
+ @apply tw:flex! tw:[color:var(--my-color)] tw:bg-linear-to-t;
102
+ }"
103
+ ` )
104
+ } )
0 commit comments