1
1
const { execSync } = require ( 'child_process' )
2
+ const os = require ( 'os' )
3
+ const fs = require ( 'fs-extra' )
2
4
3
5
const platformMap = {
4
6
darwin : 'macos' ,
@@ -13,7 +15,13 @@ function exec(args) {
13
15
}
14
16
15
17
it ( 'works' , ( ) => {
16
- expect ( exec ( '--content tests/fixtures/basic.html' ) ) . toContain ( '.uppercase' )
18
+ let result = exec ( '--content tests/fixtures/basic.html' )
19
+ expect ( result ) . toContain ( '.uppercase' )
20
+ expect ( result ) . toContain ( '.\\[will-change\\:opacity\\]' )
21
+ expect ( result ) . toContain ( 'will-change: opacity' )
22
+
23
+ // Verify that no plugins are installed that modify the `[will-change:opacity]` class
24
+ expect ( result ) . not . toContain ( 'backface-visibility: hidden' )
17
25
} )
18
26
19
27
it ( 'supports first-party plugins' , ( ) => {
@@ -23,3 +31,54 @@ it('supports first-party plugins', () => {
23
31
expect ( result ) . toContain ( '.line-clamp-2' )
24
32
expect ( result ) . toContain ( '.prose' )
25
33
} )
34
+
35
+ it ( 'supports postcss config files' , async ( ) => {
36
+ // We have to run this test outside of any place with node_modules for it to properly test this situation
37
+ let result = await inIsolatedContext ( ( ) => {
38
+ // Emulate the user adding their own postcss plugins
39
+ execSync ( `npm install postcss-will-change` )
40
+
41
+ return exec ( '--content tests/fixtures/basic.html --postcss tests/fixtures/postcss.config.js' )
42
+ } )
43
+
44
+ expect ( result ) . toContain ( '.uppercase' )
45
+
46
+ // Ensure the custom added postcss plugin is working
47
+ expect ( result ) . toContain ( 'will-change: opacity' )
48
+ expect ( result ) . toContain ( 'backface-visibility: hidden' )
49
+ } )
50
+
51
+ /**
52
+ * @template T
53
+ * @param {() => T } fn
54
+ * @returns {T }
55
+ */
56
+ async function inIsolatedContext ( fn ) {
57
+ // Create a new directory entirely outside of the package for the test
58
+ let dest = `${ os . tmpdir ( ) } /tailwindcss-cli`
59
+
60
+ // Recursively copy the dist and tests folders
61
+ let dirs = [ 'dist' , 'tests' ]
62
+
63
+ await Promise . all (
64
+ dirs . map ( ( dir ) =>
65
+ fs . copy ( `${ __dirname } /../${ dir } ` , `${ dest } /${ dir } ` , {
66
+ overwrite : true ,
67
+ recursive : true ,
68
+ } )
69
+ )
70
+ )
71
+
72
+ // Change the working directory to the new directory
73
+ process . chdir ( dest )
74
+
75
+ try {
76
+ return await fn ( )
77
+ } finally {
78
+ // Change back to the original working directory
79
+ process . chdir ( __dirname )
80
+
81
+ // Delete the new directory
82
+ await fs . rmdir ( dest , { recursive : true } )
83
+ }
84
+ }
0 commit comments