Skip to content

Commit 4db338a

Browse files
committed
add postcss integration test
1 parent 8844246 commit 4db338a

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed

integrations/postcss/index.test.ts

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import path from 'node:path'
2+
import { candidate, css, html, js, json, test, yaml } from '../utils'
3+
4+
test(
5+
'production build',
6+
{
7+
fs: {
8+
'package.json': json`{}`,
9+
'pnpm-workspace.yaml': yaml`
10+
#
11+
packages:
12+
- project-a
13+
`,
14+
'project-a/package.json': json`
15+
{
16+
"dependencies": {
17+
"postcss": "^8",
18+
"postcss-cli": "^10",
19+
"tailwindcss": "workspace:^",
20+
"@tailwindcss/postcss": "workspace:^"
21+
}
22+
}
23+
`,
24+
'project-a/postcss.config.js': js`
25+
module.exports = {
26+
plugins: {
27+
'@tailwindcss/postcss': {},
28+
},
29+
}
30+
`,
31+
'project-a/index.html': html`
32+
<div
33+
class="underline 2xl:font-bold hocus:underline inverted:flex"
34+
></div>
35+
`,
36+
'project-a/plugin.js': js`
37+
module.exports = function ({ addVariant }) {
38+
addVariant('inverted', '@media (inverted-colors: inverted)')
39+
addVariant('hocus', ['&:focus', '&:hover'])
40+
}
41+
`,
42+
'project-a/src/index.css': css`
43+
@import 'tailwindcss/utilities';
44+
@content '../../project-b/src/**/*.js';
45+
@plugin '../plugin.js';
46+
`,
47+
'project-a/src/index.js': js`
48+
const className = "content-['a/src/index.js']"
49+
module.exports = { className }
50+
`,
51+
'project-b/src/index.js': js`
52+
const className = "content-['b/src/index.js']"
53+
module.exports = { className }
54+
`,
55+
},
56+
},
57+
async ({ root, fs, exec }) => {
58+
await exec('pnpm postcss src/index.css --output dist/out.css', {
59+
cwd: path.join(root, 'project-a'),
60+
})
61+
62+
await fs.expectFileToContain('project-a/dist/out.css', [
63+
candidate`underline`,
64+
candidate`content-['a/src/index.js']`,
65+
candidate`content-['b/src/index.js']`,
66+
candidate`inverted:flex`,
67+
candidate`hocus:underline`,
68+
])
69+
},
70+
)
71+
72+
test(
73+
'watch mode',
74+
{
75+
fs: {
76+
'package.json': json`{}`,
77+
'pnpm-workspace.yaml': yaml`
78+
#
79+
packages:
80+
- project-a
81+
`,
82+
'project-a/package.json': json`
83+
{
84+
"dependencies": {
85+
"postcss": "^8",
86+
"postcss-cli": "^10",
87+
"tailwindcss": "workspace:^",
88+
"@tailwindcss/postcss": "workspace:^"
89+
}
90+
}
91+
`,
92+
'project-a/postcss.config.js': js`
93+
module.exports = {
94+
plugins: {
95+
'@tailwindcss/postcss': {},
96+
},
97+
}
98+
`,
99+
'project-a/index.html': html`
100+
<div
101+
class="underline 2xl:font-bold hocus:underline inverted:flex"
102+
></div>
103+
`,
104+
'project-a/plugin.js': js`
105+
module.exports = function ({ addVariant }) {
106+
addVariant('inverted', '@media (inverted-colors: inverted)')
107+
addVariant('hocus', ['&:focus', '&:hover'])
108+
}
109+
`,
110+
'project-a/src/index.css': css`
111+
@import 'tailwindcss/utilities';
112+
@content '../../project-b/src/**/*.js';
113+
@plugin '../plugin.js';
114+
`,
115+
'project-a/src/index.js': js`
116+
const className = "content-['a/src/index.js']"
117+
module.exports = { className }
118+
`,
119+
'project-b/src/index.js': js`
120+
const className = "content-['b/src/index.js']"
121+
module.exports = { className }
122+
`,
123+
},
124+
},
125+
async ({ root, fs, spawn }) => {
126+
await spawn('pnpm postcss src/index.css --output dist/out.css --watch', {
127+
cwd: path.join(root, 'project-a'),
128+
})
129+
130+
await fs.expectFileToContain('project-a/dist/out.css', [
131+
candidate`underline`,
132+
candidate`content-['a/src/index.js']`,
133+
candidate`content-['b/src/index.js']`,
134+
candidate`inverted:flex`,
135+
candidate`hocus:underline`,
136+
])
137+
138+
await fs.write(
139+
'project-a/src/index.js',
140+
js`
141+
const className = "[.changed_&]:content-['project-a/src/index.js']"
142+
module.exports = { className }
143+
`,
144+
)
145+
await fs.expectFileToContain('project-a/dist/out.css', [
146+
candidate`[.changed_&]:content-['project-a/src/index.js']`,
147+
])
148+
149+
await fs.write(
150+
'project-b/src/index.js',
151+
js`
152+
const className = "[.changed_&]:content-['project-b/src/index.js']"
153+
module.exports = { className }
154+
`,
155+
)
156+
await fs.expectFileToContain('project-a/dist/out.css', [
157+
candidate`[.changed_&]:content-['project-b/src/index.js']`,
158+
])
159+
},
160+
)

0 commit comments

Comments
 (0)