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(env): do not override NODE_ENV if already set #474

Merged

Conversation

aversini
Copy link
Contributor

@aversini aversini commented Jun 7, 2017

This recent styleguidist update to support Create React App is overriding NODE_ENV, even if it's already set by the user.

This PR is an attempt to fix this and still support Create React App:

  • If NODE_ENV is set, use it
  • In ReactComponent, instead of checking for development, check for not production, allowing the use of debug for example and treat it the same as development

This is allowing a user to do this:

NODE_ENV=debug styleguidist server

and configure their webpack/styleguidist configuration to act accordingly on 'debug'

- If NODE_ENV is set, use it
- In ReactComponent, instead of checking for `development`, check for `not production`, allowing to use `debug` for example and treat it the same as `development`
Copy link
Member

@sapegin sapegin left a comment

Choose a reason for hiding this comment

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

Cool, thanks! Could you please check CI?

@@ -5,7 +5,7 @@ import Methods from 'rsg-components/Methods';
import Examples from 'rsg-components/Examples';
import ReactComponentRenderer from 'rsg-components/ReactComponent/ReactComponentRenderer';

const ExamplePlaceholder = process.env.NODE_ENV === 'development'
const ExamplePlaceholder = process.env.NODE_ENV !== 'production'
Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually that is what causing CI to fail.

I'm assuming Jest snapshots have been taken with NODE_ENV set to 'production'. In CI, the test runs with NODE_ENV=test, so it makes my test (process.env.NODE_ENV !== 'production') truthy. That means that in test mode, component are not rendered in 'production' mode, and therefore the snapshots do not match.

Before my change, with NODE_ENV set to 'test' would render the component in production mode... quite a conundrum here. I have a feeling that it would make more sense to revert this change and keep snapshots 'production'. It means that ONLY when specifically set to 'development', component are rendered that special way? Let me know what you think @sapegin

Copy link
Member

Choose a reason for hiding this comment

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

I thinks != production is more common way to check that but we’ll probably need to grep the code for development and update checks in other places too ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. So I grep'd around and didn't find any places that looked like they should be updated, beside that one line. So my suggestion is to consider the 'test' path by updating the condition to:

const ExamplePlaceholder = process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test'
  ? require('rsg-components/ExamplePlaceholder').default
  : () => <div />;

This has no impact for production code and it should allow CI to pass.

Copy link
Member

Choose a reason for hiding this comment

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

I think we can just update snapshots because it doesn’t really matter if it renders placeholder or not if it does the right thing ;-)

@codecov-io
Copy link

codecov-io commented Jul 1, 2017

Codecov Report

Merging #474 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #474   +/-   ##
=======================================
  Coverage   95.23%   95.23%           
=======================================
  Files          98       98           
  Lines        1280     1280           
  Branches      264      264           
=======================================
  Hits         1219     1219           
  Misses         59       59           
  Partials        2        2
Impacted Files Coverage Δ
...rc/rsg-components/ReactComponent/ReactComponent.js 83.33% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b1be52...9055d4b. Read the comment docs.

@aversini
Copy link
Contributor Author

aversini commented Jul 1, 2017

@sapegin I finally got around this PR and by virtue of synchronizing it with the latest from master, CI tests are all passing 😄 Let me know if you need anything else. Thanks!

@sapegin sapegin merged commit 967eb0f into styleguidist:master Jul 2, 2017
@sapegin
Copy link
Member

sapegin commented Jul 2, 2017

Awesome, thanks!

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.

3 participants