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

feat: improve test command, support dotenv files, add postcss #52

Merged
merged 12 commits into from
Sep 24, 2019

Conversation

amcgee
Copy link
Member

@amcgee amcgee commented Sep 20, 2019

This is an upgrade to the test command which adds support for jest config overrides, provides nice testing defaults, and adds support for --updateSnapshot, --coverage, and --watch to the test command.

This also adds support for specifying environment variables in .env files (including .env.local, .env.<mode>[.local] (mode == production, development, or test), for all three build/test/start commands

This does modify the behavior of the compiler somewhat - we now only bundle apps into a single file, not libs (this might change again in the future). We also only support CJS module loading (for now) because of an issue with CJS named exports in static dependendency resolution (see the code comment and the rollup issue)

This also adds support for postcss so that we can more easily port CRA apps to the platform. It supports import 'my.css' for global styles, as well as import styles from 'my.module.css' for CSS module support (filenames must have the extension .module.css)

Finally, I've patched up a few small issues in the shell, such as an omitted typeface-robotto and including more favicon variants

These changes were influenced by the effort to port Usage Analytics to the platform, see dhis2/usage-analytics-app#94

@netlify
Copy link

netlify bot commented Sep 20, 2019

Deploy preview for dhis2-app-platform ready!

Built with commit 1e1efbe

https://deploy-preview-52--dhis2-app-platform.netlify.com

Copy link
Contributor

@varl varl left a comment

Choose a reason for hiding this comment

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

Nice improvement. 👍

Looks good all-in-all. Very nice getting bundle analysis built-in. 🔬

I'm a bit way about misuse of .env files, though that is up to the consumer. The 12-factor app principles don't always apply to us, nor should they, though some of the points are general enough to apply where we think they make sense.

I believe the configuration parts is one such area: https://12factor.net/config

The dotenv authors discuss it a bit in their FAQ as well: https://github.com/motdotla/dotenv#faq

Having .env.development, .env.test, env.development.local etc. is an anti-pattern, and not something I want us to endorse.

shell/public/index.html Show resolved Hide resolved
@amcgee
Copy link
Member Author

amcgee commented Sep 22, 2019

I'm a bit way about misuse of .env files, though that is up to the consumer. The 12-factor app principles don't always apply to us, nor should they, though some of the points are general enough to apply where we think they make sense.

I think I agree here - it's a tradeoff, though, since .env files I think can make development (and particularly shared development) easier. I went for CRA compatibility here, to minimize the modifications necessary to i.e. usage-analytics-app.

I'm onboard with removing at least the per-environment env files, but would be curious what the "right" way to implement environment defaults/overrides should be in the platform - I know we'll be getting rid of this use of source-local HTTP requests soon, so we could omit the REACT_APP variables, but there will be different configurations of DHIS2_BASE_URL between development and production at least for the foreseeable future.

@varl what do you envision - no support for dotenv or support for only one dotenv (possibly with .local overrides)

@varl
Copy link
Contributor

varl commented Sep 22, 2019

We need to think a bit about it. For instance, what is an environment? My computer for example is a development environment, and therefore it should not be allowed to act as a production environment.

Generally I think that a .env.template with all variables committed to the repository, and an ignored .env file is enough. The .env file has the environment variables for the current environment. That's it. This doesn't really work for us since we cannot e.g. have a .env file on Travis for CI, or one on Netlify or one on the production instance that can be read by the app.

CRA does not use the environment files for environments in the strictest sense, it uses it for configuration for different modes for the intended environment, which solves the problems above in exchange for a bit of a mess of files in the app repo.

Anyway, pardon me for bringing up this topic in this PR. I think this is good for now.

@amcgee
Copy link
Member Author

amcgee commented Sep 22, 2019

@varl it's a very fair point since this adds support for .env[.mode][.local] files, should we pull that support and just allow .env for now or merge this with support for all variants?

@amcgee
Copy link
Member Author

amcgee commented Sep 22, 2019

The advantage of allowing multiple mode-targeted .env files is that you can, for instance, specify http:https://my-server.com for development and then revert to ../../../ (or whatever) in production. We could set this automatically, but I also think there might be situations where a production build would want a custom root url

@amcgee
Copy link
Member Author

amcgee commented Sep 22, 2019

(p.s. thanks for the feedback!)

@varl
Copy link
Contributor

varl commented Sep 22, 2019

@varl it's a very fair point since this adds support for .env[.mode][.local] files, should we pull that support and just allow .env for now or merge this with support for all variants?

I thought about that too, and to be pragmatic about it; .env[.mode] makes a lot of sense for configuration purposes. The case for .env[.mode][.local] is weaker as .env.local covers the most reasonable use cases.

In the end, having support for it doesn't mean we have to use it, so we can safely leave it in.

Copy link
Contributor

@HendrikThePendric HendrikThePendric left a comment

Choose a reason for hiding this comment

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

I've left one comment in the code that I think needs to be addressed before this is merged.

shell/public/manifest.json Outdated Show resolved Hide resolved
@ismay
Copy link
Member

ismay commented Sep 23, 2019

In the end, having support for it doesn't mean we have to use it, so we can safely leave it in.

Nice. I personally like using this to have a standard way to point to a dhis2 backend. I don't like the approach we used before with the dhis2 config that lives outside of the repo, on your system somewhere. The .env files make way more sense to me.

@amcgee
Copy link
Member Author

amcgee commented Sep 23, 2019

I've left one comment in the code that I think needs to be addressed before this is merged.

@HendrikThePendric removed the offending file, thanks for catching that - should be good to go now!

@amcgee
Copy link
Member Author

amcgee commented Sep 23, 2019

I'd really like to get this in - @HendrikThePendric I think your request has been addressed, let me know ASAP if it hasn't, otherwise I'd like to merge this first-thing tomorrow!

Copy link
Contributor

@HendrikThePendric HendrikThePendric left a comment

Choose a reason for hiding this comment

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

LGTM

@amcgee
Copy link
Member Author

amcgee commented Sep 24, 2019

Thanks all for the feedback!

@amcgee amcgee merged commit 210c9cc into master Sep 24, 2019
@amcgee amcgee deleted the feat/jest-improvements-postcss branch September 24, 2019 07:58
dhis2-bot added a commit that referenced this pull request Sep 24, 2019
# [1.4.0](v1.3.1...v1.4.0) (2019-09-24)

### Features

* improve test command, support dotenv files, add postcss ([#52](#52)) ([210c9cc](210c9cc))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 1.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

5 participants