Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: throw error only when child process exits with error code #41

Merged
merged 1 commit into from
Oct 10, 2020

Conversation

ramasilveyra
Copy link
Contributor

Fix #40

Throw error only when child process exits with error code. Created fixture-postcss-plugin.js postcss plugins that logs to stderr, previously this was making tests to fail, with this fix logging inside plugins works as expected.

@@ -15,7 +15,7 @@ module.exports = (css, settings) => {
encoding: 'utf8'
})

if (result.stderr) {
if (result.status !== 0) {
if (result.stderr.includes('Invalid PostCSS Plugin')) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here we can try to use result.error (iirc it should be an instance of Error)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not Error, it's undefined.

After adding:

diff --git a/index.js b/index.js
index 415fd1f..1ba9284 100644
--- a/index.js
+++ b/index.js
@@ -15,6 +15,10 @@ module.exports = (css, settings) => {
     encoding: 'utf8'
   })
 
+  console.log('result.status', result.status)
+  console.log('result.signal', result.signal)
+  console.log('result.error', result.error)
+
   if (result.status !== 0) {
     if (result.stderr.includes('Invalid PostCSS Plugin')) {
       console.error('Next.js 9 default postcss support uses a non standard postcss config schema https://err.sh/next.js/postcss-shape, you must use the interoperable object-based format instead https://nextjs.org/docs/advanced-features/customizing-postcss-config')

this was the output of running the test suite:

➜  styled-jsx-plugin-postcss git:(fix/process-exit) yarn test
yarn run v1.22.5
$ mocha test.js


  styled-jsx-plugin-postcss
result.status 0
result.signal null
result.error undefined
    ✓ applies browser list and preset-env features (1327ms)
result.status 0
result.signal null
result.error undefined
    ✓ applies plugins (659ms)
result.status 0
result.signal null
result.error undefined
    ✓ works with placeholders (685ms)
result.status 0
result.signal null
result.error undefined
    ✓ works with @import (664ms)
result.status 0
result.signal null
result.error undefined
    ✓ works with quotes and other characters (669ms)
result.status 1
result.signal null
result.error undefined
    ✓ throws with invalid css (636ms)
result.status 1
result.signal null
result.error undefined
Next.js 9 default postcss support uses a non standard postcss config schema https://err.sh/next.js/postcss-shape, you must use the interoperable object-based format instead https://nextjs.org/docs/advanced-features/customizing-postcss-config
    ✓ throws with invalid config (131ms)


  7 passing (5s)

✨  Done in 6.07s.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it. we can fix it later if needed. Thanks again for the PR!

@giuseppeg giuseppeg merged commit 220d8d6 into giuseppeg:master Oct 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v3.0.0+ fails with tailwindcss
2 participants