Skip to content
This repository was archived by the owner on Jun 11, 2022. It is now read-only.

Commit 4efaba7

Browse files
authored
Testpack API support (#57)
* Testpack API support including NODE_ENV=test override. * Hint to the test runner to exit when complete instead of watching. * 📚 testing and support for Heroku CI * Format build log * 📚 minimal `app.json` for CI
1 parent d72583f commit 4efaba7

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Deploy React.js web apps generated with [create-react-app](https://github.com/fa
1212
1. [Create the Heroku app](#user-content-create-the-heroku-app)
1313
1. [Commit & deploy ♻️](#user-content-commit--deploy-️)
1414
1. [Continue Development](#user-content-continue-development)
15+
1. [Push to Github](#user-content-push-to-github)
16+
1. [Testing](#user-content-testing)
1517
* 👓 [Customization](#user-content-customization)
1618
* [Procfile](#user-content-procfile)
1719
* [Web server](#user-content-web-server)
@@ -138,6 +140,25 @@ Then, commit & deploy ♻️
138140

139141
Eventually, to share, collaborate, or simply back-up your code, [create an empty repo at Github](https://github.com/new), and then follow the instructions shown on the repo to **push an existing repository from the command line**.
140142

143+
### Testing
144+
145+
Use [create-react-app's built-in Jest testing](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#user-content-running-tests) or whatever testing library you prefer.
146+
147+
As long as tests can be run with `npm test` (like the built-in Jest testing) then it will work effortlessly with [Heroku CI](https://devcenter.heroku.com/articles/heroku-ci).
148+
149+
#### Minimal `app.json`
150+
151+
Heroku CI uses [`app.json`](https://devcenter.heroku.com/articles/app-json-schema) to provision test apps. To enable Heroku CI, commit this minimal example `app.json`:
152+
153+
```json
154+
{
155+
"buildpacks": [
156+
{
157+
"url": "https://github.com/mars/create-react-app-buildpack"
158+
}
159+
]
160+
}
161+
```
141162

142163
Customization
143164
-------------

bin/compile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,20 @@ branch=""
3131
dir=$(mktemp -t buildpackXXXXX)
3232
rm -rf $dir
3333

34+
echo "-----> Configure create-react-app build environment"
3435
# Set env vars for the inner buildpacks in `.buildpacks`
35-
# * install build tooling (devDependencies) with npm & Yarn
36-
# * used only during compile, as the runtime is a static web server
36+
# * during compile, install build tooling (devDependencies) with npm & Yarn
37+
# * in runtime, NODE_ENV is not used (this buildpack launches a static web server)
3738
export NPM_CONFIG_PRODUCTION=false
38-
export NODE_ENV=development
39+
INHERITED_NODE_ENV="${NODE_ENV:-development}"
40+
if [ "$INHERITED_NODE_ENV" = "production" ]
41+
then
42+
echo ' Setting `NODE_ENV=development` to install dependencies for `npm build`'
43+
export NODE_ENV=development
44+
else
45+
echo " Using \`NODE_ENV=${INHERITED_NODE_ENV}\`"
46+
export NODE_ENV="${INHERITED_NODE_ENV}"
47+
fi
3948

4049
echo "=====> Downloading Buildpack: $url"
4150

bin/test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
# bin/test-compile BUILD_DIR CACHE_DIR ENV_DIR
3+
4+
# Hint to the test runner to exit when complete instead of watching.
5+
export CI=true
6+
7+
# Test runner copied from Node buildpack:
8+
# https://github.com/heroku/heroku-buildpack-nodejs/blob/master/bin/test
9+
10+
BUILD_DIR=${1:-}
11+
if yarn --version > /dev/null 2>&1; then
12+
cd "$BUILD_DIR" && yarn test
13+
else
14+
cd "$BUILD_DIR" && npm test
15+
fi

bin/test-compile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
# bin/test-compile BUILD_DIR CACHE_DIR ENV_DIR
3+
4+
# Test compiler copied from Node buildpack:
5+
# https://github.com/heroku/heroku-buildpack-nodejs/blob/master/bin/test-compile
6+
7+
NODE_ENV=test "$(dirname ${0:-})/compile" "$1" "$2" "$3"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy