Skip to content

Commit f342edf

Browse files
committed
add integration test
- One test reads from stdin (added for completeness) - One test writes to stdout
1 parent cbc9b75 commit f342edf

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed

integrations/cli/index.test.ts

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,149 @@ describe.each([
9595
},
9696
)
9797

98+
test(
99+
'production build — read input from stdin',
100+
{
101+
fs: {
102+
'package.json': json`{}`,
103+
'pnpm-workspace.yaml': yaml`
104+
#
105+
packages:
106+
- project-a
107+
`,
108+
'project-a/package.json': json`
109+
{
110+
"dependencies": {
111+
"tailwindcss": "workspace:^",
112+
"@tailwindcss/cli": "workspace:^"
113+
}
114+
}
115+
`,
116+
'project-a/index.html': html`
117+
<div
118+
class="underline 2xl:font-bold hocus:underline inverted:flex *:flex **:flex"
119+
></div>
120+
`,
121+
'project-a/plugin.js': js`
122+
module.exports = function ({ addVariant }) {
123+
addVariant('inverted', '@media (inverted-colors: inverted)')
124+
addVariant('hocus', ['&:focus', '&:hover'])
125+
}
126+
`,
127+
'project-a/tailwind.config.js': js`
128+
module.exports = {
129+
content: ['../project-b/src/**/*.js'],
130+
}
131+
`,
132+
'project-a/src/index.js': js`
133+
const className = "content-['project-a/src/index.js']"
134+
module.exports = { className }
135+
`,
136+
'project-b/src/index.html': html`
137+
<div class="flex" />
138+
`,
139+
'project-b/src/index.js': js`
140+
const className = "content-['project-b/src/index.js']"
141+
module.exports = { className }
142+
`,
143+
},
144+
},
145+
async ({ root, fs, exec }) => {
146+
await exec(
147+
`${command} --input - --output dist/out.css`,
148+
{ cwd: path.join(root, 'project-a') },
149+
{
150+
stdin: css`
151+
@import 'tailwindcss/utilities';
152+
@config './tailwind.config.js';
153+
@source '../project-b/src/**/*.html';
154+
@plugin './plugin.js';
155+
`,
156+
},
157+
)
158+
159+
await fs.expectFileToContain('project-a/dist/out.css', [
160+
candidate`underline`,
161+
candidate`flex`,
162+
candidate`content-['project-a/src/index.js']`,
163+
candidate`content-['project-b/src/index.js']`,
164+
candidate`inverted:flex`,
165+
candidate`hocus:underline`,
166+
candidate`*:flex`,
167+
candidate`**:flex`,
168+
])
169+
},
170+
)
171+
172+
test(
173+
'production build — (write to stdout)',
174+
{
175+
fs: {
176+
'package.json': json`{}`,
177+
'pnpm-workspace.yaml': yaml`
178+
#
179+
packages:
180+
- project-a
181+
`,
182+
'project-a/package.json': json`
183+
{
184+
"dependencies": {
185+
"tailwindcss": "workspace:^",
186+
"@tailwindcss/cli": "workspace:^"
187+
}
188+
}
189+
`,
190+
'project-a/index.html': html`
191+
<div
192+
class="underline 2xl:font-bold hocus:underline inverted:flex *:flex **:flex"
193+
></div>
194+
`,
195+
'project-a/plugin.js': js`
196+
module.exports = function ({ addVariant }) {
197+
addVariant('inverted', '@media (inverted-colors: inverted)')
198+
addVariant('hocus', ['&:focus', '&:hover'])
199+
}
200+
`,
201+
'project-a/tailwind.config.js': js`
202+
module.exports = {
203+
content: ['../project-b/src/**/*.js'],
204+
}
205+
`,
206+
'project-a/src/index.css': css`
207+
@import 'tailwindcss/utilities';
208+
@config '../tailwind.config.js';
209+
@source '../../project-b/src/**/*.html';
210+
@plugin '../plugin.js';
211+
`,
212+
'project-a/src/index.js': js`
213+
const className = "content-['project-a/src/index.js']"
214+
module.exports = { className }
215+
`,
216+
'project-b/src/index.html': html`
217+
<div class="flex" />
218+
`,
219+
'project-b/src/index.js': js`
220+
const className = "content-['project-b/src/index.js']"
221+
module.exports = { className }
222+
`,
223+
},
224+
},
225+
async ({ root, expect, exec }) => {
226+
let stdout = await exec(`${command} --input src/index.css --output -`, {
227+
cwd: path.join(root, 'project-a'),
228+
})
229+
230+
expect(stdout).toContain(candidate`underline`)
231+
expect(stdout).toContain(candidate`flex`)
232+
expect(stdout).toContain(candidate`content-['project-a/src/index.js']`)
233+
expect(stdout).toContain(candidate`content-['project-b/src/index.js']`)
234+
expect(stdout).toContain(candidate`inverted:flex`)
235+
expect(stdout).toContain(candidate`hocus:underline`)
236+
expect(stdout).toContain(candidate`*:flex`)
237+
expect(stdout).toContain(candidate`**:flex`)
238+
},
239+
)
240+
98241
test(
99242
'watch mode',
100243
{

0 commit comments

Comments
 (0)