Re-throw errors from PostCSS nodes (#18373)

Fixes #18370

---------

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
This commit is contained in:
Jordan Pittman 2025-09-18 12:03:19 -04:00 • committed by GitHub
parent c2aab49c77
commit 5b8136e838
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 87 additions and 35 deletions

View file

@ -1,5 +1,5 @@
import path from 'node:path'
import { candidate, css, html, js, json, retryAssertion, test, ts, yaml } from '../utils'
import { candidate, css, html, js, json, test, ts, yaml } from '../utils'
test(
'production build (string)',
@ -662,23 +662,56 @@ test(
`,
'src/index.css': css` @import './tailwind.css'; `,
'src/tailwind.css': css`
@reference 'tailwindcss/does-not-exist';
@reference 'tailwindcss/theme';
@import 'tailwindcss/utilities';
`,
},
},
async ({ fs, expect, spawn }) => {
// 1. Start the watcher
//
// It must have valid CSS for the initial build
let process = await spawn('pnpm postcss src/index.css --output dist/out.css --watch --verbose')
await process.onStderr((message) => message.includes('Waiting for file changes...'))
expect(await fs.dumpFiles('dist/*.css')).toMatchInlineSnapshot(`
"
--- dist/out.css ---
.underline {
text-decoration-line: underline;
}
"
`)
// 2. Cause an error
await fs.write(
'src/tailwind.css',
css`
@reference 'tailwindcss/does-not-exist';
@import 'tailwindcss/utilities';
`,
)
// 2.5 Write to a content file
await fs.write('src/index.html', html`
<div class="flex underline"></div>
`)
await process.onStderr((message) =>
message.includes('does-not-exist is not exported from package'),
)
await retryAssertion(async () => expect(await fs.read('dist/out.css')).toEqual(''))
expect(await fs.dumpFiles('dist/*.css')).toMatchInlineSnapshot(`
"
--- dist/out.css ---
.underline {
text-decoration-line: underline;
}
"
`)
await process.onStderr((message) => message.includes('Waiting for file changes...'))
// Fix the CSS file
// 3. Fix the CSS file
await fs.write(
'src/tailwind.css',
css`
@ -686,11 +719,15 @@ test(
@import 'tailwindcss/utilities';
`,
)
await process.onStderr((message) => message.includes('Finished'))
await process.onStderr((message) => message.includes('Waiting for file changes...'))
expect(await fs.dumpFiles('dist/*.css')).toMatchInlineSnapshot(`
"
--- dist/out.css ---
.flex {
display: flex;
}
.underline {
text-decoration-line: underline;
}
@ -705,11 +742,22 @@ test(
@import 'tailwindcss/utilities';
`,
)
await process.onStderr((message) =>
message.includes('does-not-exist is not exported from package'),
)
await retryAssertion(async () => expect(await fs.read('dist/out.css')).toEqual(''))
expect(await fs.dumpFiles('dist/*.css')).toMatchInlineSnapshot(`
"
--- dist/out.css ---
.flex {
display: flex;
}
.underline {
text-decoration-line: underline;
}
"
`)
},
)