@@ -7,7 +7,10 @@ const configPath = path.resolve(__dirname, './context-reuse.tailwind.config.js')
7
7
const { css } = require ( './util/run.js' )
8
8
9
9
function run ( input , config = { } , from = null ) {
10
- from = from || path . resolve ( __filename )
10
+ from = [
11
+ `${ path . resolve ( __filename ) } ?test=${ expect . getState ( ) . currentTestName } ` ,
12
+ from
13
+ ] . join ( '&' )
11
14
12
15
return postcss ( tailwind ( config ) ) . process ( input , { from } )
13
16
}
@@ -26,16 +29,14 @@ afterEach(async () => {
26
29
} )
27
30
28
31
it ( 're-uses the context across multiple files with the same config' , async ( ) => {
29
- let from = path . resolve ( __filename )
30
-
31
32
let results = [
32
- await run ( `@tailwind utilities;` , configPath , `${ from } ? id=1` ) ,
33
+ await run ( `@tailwind utilities;` , configPath , `id=1` ) ,
33
34
34
35
// Using @apply directives should still re-use the context
35
36
// They depend on the config but do not the other way around
36
- await run ( `body { @apply bg-blue-400; }` , configPath , `${ from } ? id=2` ) ,
37
- await run ( `body { @apply text-red-400; }` , configPath , `${ from } ? id=3` ) ,
38
- await run ( `body { @apply mb-4; }` , configPath , `${ from } ? id=4` ) ,
37
+ await run ( `body { @apply bg-blue-400; }` , configPath , `id=2` ) ,
38
+ await run ( `body { @apply text-red-400; }` , configPath , `id=3` ) ,
39
+ await run ( `body { @apply mb-4; }` , configPath , `id=4` ) ,
39
40
]
40
41
41
42
let dependencies = results . map ( ( result ) => {
@@ -88,36 +89,35 @@ it('re-uses the context across multiple files with the same config', async () =>
88
89
89
90
it ( 'invalidates the context when any CSS containing @tailwind directives changes' , async ( ) => {
90
91
sharedState . contextInvalidationCount = 0
91
-
92
- let from = path . resolve ( __filename )
92
+ sharedState . sourceHashMap . clear ( )
93
93
94
94
// Save the file a handful of times with no changes
95
95
// This builds the context at most once
96
96
for ( let n = 0 ; n < 5 ; n ++ ) {
97
- await run ( `@tailwind utilities;` , configPath , `${ from } ? id=1` )
97
+ await run ( `@tailwind utilities;` , configPath , `id=1` )
98
98
}
99
99
100
100
expect ( sharedState . contextInvalidationCount ) . toBe ( 1 )
101
101
102
102
// Save the file twice with a change
103
103
// This should rebuild the context again but only once
104
- await run ( `@tailwind utilities; .foo {}` , configPath , `${ from } ? id=1` )
105
- await run ( `@tailwind utilities; .foo {}` , configPath , `${ from } ? id=1` )
104
+ await run ( `@tailwind utilities; .foo {}` , configPath , `id=1` )
105
+ await run ( `@tailwind utilities; .foo {}` , configPath , `id=1` )
106
106
107
107
expect ( sharedState . contextInvalidationCount ) . toBe ( 2 )
108
108
109
109
// Save the file twice with a content but not length change
110
110
// This should rebuild the context two more times
111
- await run ( `@tailwind utilities; .bar {}` , configPath , `${ from } ? id=1` )
112
- await run ( `@tailwind utilities; .baz {}` , configPath , `${ from } ? id=1` )
111
+ await run ( `@tailwind utilities; .bar {}` , configPath , `id=1` )
112
+ await run ( `@tailwind utilities; .baz {}` , configPath , `id=1` )
113
113
114
114
expect ( sharedState . contextInvalidationCount ) . toBe ( 4 )
115
115
116
116
// Save a file with a change that does not affect the context
117
117
// No invalidation should occur
118
- await run ( `.foo { @apply mb-1; }` , configPath , `${ from } ? id=2` )
119
- await run ( `.foo { @apply mb-1; }` , configPath , `${ from } ? id=2` )
120
- await run ( `.foo { @apply mb-1; }` , configPath , `${ from } ? id=2` )
118
+ await run ( `.foo { @apply mb-1; }` , configPath , `id=2` )
119
+ await run ( `.foo { @apply mb-1; }` , configPath , `id=2` )
120
+ await run ( `.foo { @apply mb-1; }` , configPath , `id=2` )
121
121
122
122
expect ( sharedState . contextInvalidationCount ) . toBe ( 4 )
123
123
} )
0 commit comments