Skip to content

Commit 23c044a

Browse files
Add a working regression test
1 parent bb19eeb commit 23c044a

File tree

3 files changed

+64
-93
lines changed

3 files changed

+64
-93
lines changed

integrations/postcss/next.test.ts

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -356,94 +356,3 @@ test(
356356
})
357357
},
358358
)
359-
360-
test(
361-
'changes to CSS file should immediately reflect with HMR using `--turbopack`',
362-
{
363-
fs: {
364-
'package.json': json`
365-
{
366-
"dependencies": {
367-
"react": "^18",
368-
"react-dom": "^18",
369-
"next": "^15"
370-
},
371-
"devDependencies": {
372-
"@tailwindcss/postcss": "workspace:^",
373-
"tailwindcss": "workspace:^"
374-
}
375-
}
376-
`,
377-
'.gitignore': `
378-
node_modules
379-
.next/
380-
`,
381-
'postcss.config.mjs': js`
382-
export default {
383-
plugins: {
384-
'@tailwindcss/postcss': {},
385-
},
386-
}
387-
`,
388-
'next.config.mjs': js`export default {}`,
389-
'app/layout.js': js`
390-
import './globals.css'
391-
392-
export default function RootLayout({ children }) {
393-
return (
394-
<html>
395-
<body>{children}</body>
396-
</html>
397-
)
398-
}
399-
`,
400-
'app/page.js': js`
401-
export default function Page() {
402-
return <div className="flex"></div>
403-
}
404-
`,
405-
'app/globals.css': css`
406-
@import 'tailwindcss/utilities' source(none);
407-
408-
body {
409-
--value: 'before change';
410-
}
411-
`,
412-
},
413-
},
414-
async ({ spawn, fs, expect }) => {
415-
let process = await spawn(`pnpm next dev --turbopack`)
416-
417-
let url = ''
418-
await process.onStdout((m) => {
419-
let match = /Local:\s*(http.*)/.exec(m)
420-
if (match) url = match[1]
421-
return Boolean(url)
422-
})
423-
424-
await process.onStdout((m) => m.includes('Ready in'))
425-
await retryAssertion(async () => {
426-
let css = await fetchStyles(url)
427-
expect(css).toContain('before change')
428-
})
429-
430-
await fs.write(
431-
'app/globals.css',
432-
css`
433-
@import 'tailwindcss/utilities' source(none);
434-
435-
body {
436-
--value: 'after change';
437-
}
438-
`,
439-
)
440-
441-
await process.onStdout((m) => m.includes('Compiled / in'))
442-
443-
await retryAssertion(async () => {
444-
let css = await fetchStyles(url)
445-
expect(css).not.toContain('before change')
446-
expect(css).toContain('after change')
447-
})
448-
},
449-
)

packages/@tailwindcss-postcss/src/index.test.ts

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import dedent from 'dedent'
2-
import { mkdir, mkdtemp, unlink, writeFile } from 'node:fs/promises'
2+
import { mkdir, mkdtemp, readFile, rm, unlink, writeFile } from 'node:fs/promises'
33
import { tmpdir } from 'node:os'
44
import path from 'path'
55
import postcss from 'postcss'
@@ -357,3 +357,64 @@ test('runs `Once` plugins in the right order', async () => {
357357
}"
358358
`)
359359
})
360+
361+
describe('concurrent builds', () => {
362+
let dir: string
363+
beforeEach(async () => {
364+
dir = await mkdtemp(path.join(tmpdir(), 'tw-postcss'))
365+
await writeFile(path.join(dir, 'index.html'), `<div class="underline"></div>`)
366+
await writeFile(
367+
path.join(dir, 'index.css'),
368+
css`
369+
@import './dependency.css';
370+
`,
371+
)
372+
await writeFile(
373+
path.join(dir, 'dependency.css'),
374+
css`
375+
@tailwind utilities;
376+
`,
377+
)
378+
})
379+
afterEach(() => rm(dir, { recursive: true, force: true }))
380+
381+
test('the current working directory is used by default', async () => {
382+
const spy = vi.spyOn(process, 'cwd')
383+
spy.mockReturnValue(dir)
384+
385+
let from = path.join(dir, 'index.css')
386+
let input = (await readFile(path.join(dir, 'index.css'))).toString()
387+
388+
let plugin = tailwindcss({ optimize: { minify: false } })
389+
390+
async function run(input: string): Promise<string> {
391+
let ast = postcss.parse(input)
392+
for (let runner of (plugin as any).plugins) {
393+
if (runner.Once) {
394+
await runner.Once(ast, { result: { opts: { from }, messages: [] } })
395+
}
396+
}
397+
return ast.toString()
398+
}
399+
400+
let result = await run(input)
401+
402+
expect(result).toContain('.underline')
403+
404+
await writeFile(
405+
path.join(dir, 'dependency.css'),
406+
css`
407+
@tailwind utilities;
408+
.red {
409+
color: red;
410+
}
411+
`,
412+
)
413+
414+
let promise1 = run(input)
415+
let promise2 = run(input)
416+
417+
expect(await promise1).toContain('.red')
418+
expect(await promise2).toContain('.red')
419+
})
420+
})

packages/@tailwindcss-postcss/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin {
8989
node.name === 'variant' ||
9090
node.name === 'config' ||
9191
node.name === 'plugin' ||
92-
node.name === 'apply'
92+
node.name === 'apply' ||
93+
node.name === 'tailwind'
9394
) {
9495
canBail = false
9596
return false

0 commit comments

Comments
 (0)