Skip to content

Commit de65fab

Browse files
cleanup yarn scripts (#8)
* Clarify package.json scripts The backend `test` and `lint` commands now only test/lint a single componenet. This should help clarify how to run tests or the linter only the frontend or backend. Add readme for the frontend. * Unit test result files go to the correct dir * Remove unneeded env variables from compose file * Remove the audit command * Add cross-env as a dev package This package allows cross platform setting of environment variables * Update readme Add section instructing to not switch between docker and host yarn commands without installing proper dependencies. Add section that offers help running docker on windows * Remove build files, add to gitignore * Clarify and update .env. Rename test * .env handling updated. .env is now .gitignored and the old .env renamed to .env.example. Should make understanding it's purpose a little easier. Added more to the comment explaining the .env files purpose * Test name now easier to understand for non-tech people * Format lint:CI to console and file Co-authored-by: Sarah-Jaine Szekeresh <[email protected]>
1 parent 10f3ff6 commit de65fab

16 files changed

+194
-59
lines changed

.env

-4
This file was deleted.

.env.example

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copy this file to `.env` and replace "1000:1000" with
2+
# your user id/group id. `.env` is used by docker-compose
3+
# making files created in the docker container owned by
4+
# your host user (instead of root).
5+
# Linux/OSX run `id -u` and `id -g`
6+
CURRENT_USER=1000:1000

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ reports
33
node_modules
44
coverage
55
.DS_Store
6-
.env.dev
6+
.env
7+
junit.xml
8+
frontend/build

README.md

+18-7
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,24 @@ Getting Started
99

1010
Make sure Docker is installed. To check run `docker ps`
1111

12-
Run `yarn docker:deps`. This builds the frontend and backend docker containers and install dependencies. You only need to run this step the first time you fire up the app and when dependencies are added/updated/removed. Running `yarn docker:start` starts the backend and frontend, browse to `http://localhost:3000` to hit the frontend and `http://localhost:3000/api` to hit the backend. Copying `.env` to `.env.dev`, substituting in your user id and group id will cause any files created in docker containers to be owned by your user on your host.
12+
Run `yarn docker:deps`. This builds the frontend and backend docker containers and install dependencies. You only need to run this step the first time you fire up the app and when dependencies are added/updated/removed. Running `yarn docker:start` starts the backend and frontend, browse to `http://localhost:3000` to hit the frontend and `http://localhost:3000/api` to hit the backend. Copying `.env.example` to `.env`, substituting in your user id and group id will cause any files created in docker containers to be owned by your user on your host.
13+
14+
You can also run build commands directly on your host (without docker). Make sure you install dependencies when changing execution method. You could see some odd errors if you install dependencies for docker and then run yarn commands directly on the host, especially if you are developing on windows. If you want to use the host yarn commands be sure to run `yarn deps` before any other yarn commands. Likewise if you want to use docker make sure you run `yarn docker:deps`.
1315

1416
The frontend [proxies requests](https://create-react-app.dev/docs/proxying-api-requests-in-development/) to paths it doesn't recognize to the backend.
1517

1618
Running Tests
1719
-------------
1820

19-
Run `yarn docker:deps` to install dependencies. Run `yarn docker:test` to run all tests
21+
Run `yarn docker:deps` to install dependencies. Run `yarn docker:test` to run all tests for the frontend and backend.
22+
23+
Docker on Windows
24+
-----------------
25+
26+
You may run into some issues running the docker commands on Windows:
27+
28+
* If you run into `Permission Denied` errors see [this issue](https://github.com/docker/for-win/issues/3385#issuecomment-501931980)
29+
* You can try to speed up execution time on windows with solutions posted to [this issue](https://github.com/docker/for-win/issues/1936)
2030

2131
Other Commands
2232
--------------
@@ -28,15 +38,16 @@ Other Commands
2838
| `yarn docker:stop` | Stops the backend and frontend docker containers |
2939
| `yarn docker:test` | Runs tests for the frontend and backend in docker containers |
3040
| `yarn docker:lint` | Runs the linter for the frontend and backend in docker containers |
31-
| `yarn docker:audit` | Runs `yarn audit` against frontend and backend dependencies |
3241
| `yarn deps` | Install dependencies for the frontend and backend |
3342
| `yarn start` | Starts the backend and frontend |
3443
| `yarn server` | Starts the backend |
3544
| `yarn client` | Start the frontend |
36-
| `yarn test` | Run tests for the backend and frontend |
37-
| `yarn eslint` | Run the linter for the backend and frontend |
38-
| `yarn lint:ci` | Run the linter in outputting results to the `reports` directory |
39-
| `yarn test:ci` | Run backend tests outputting results to the `reports` directory |
45+
| `yarn test` | Run tests for only the backend |
46+
| `yarn test:ci` | Run tests for the backend with coverage and output results to xml files|
47+
| `yarn test:all` | Run `yarn test:ci` for both the frontend and backend |
48+
| `yarn lint` | Run the linter only for the backend |
49+
| `yarn lint:ci` | Run the linter for the the backend with results output to xml files |
50+
| `yarn lint:all` | Run `yarn lint:ci` for both the frontend and backend |
4051

4152
Deployment
4253
----------

docker-compose.yml

-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ services:
66
dockerfile: Dockerfile.dev
77
command: yarn server
88
user: ${CURRENT_USER:-root}
9-
env_file:
10-
- .env
119
ports:
1210
- "3001:3001"
1311
volumes:
@@ -18,15 +16,11 @@ services:
1816
dockerfile: Dockerfile.dev
1917
command: yarn start
2018
user: ${CURRENT_USER:-root}
21-
env_file:
22-
- .env
2319
stdin_open: true
2420
ports:
2521
- "3000:3000"
2622
volumes:
2723
- "./frontend:/app:rw"
2824
- "./scripts:/app/scripts"
2925
environment:
30-
- JEST_JUNIT_OUTPUT_DIR=reports
31-
- JEST_JUNIT_OUTPUT_NAME=unit.xml
3226
- BACKEND_PROXY=http://backend:3001

frontend/README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# TTADP Frontend
2+
3+
A React frontend initialized with Create React App
4+
5+
## Getting Started
6+
7+
There are yarn commands for starting/testing/linting the frontend defined a directory up. `yarn start` or `yarn docker:start` a directory up will start both the backend and frontend. `yarn docker:test` or `yarn test:all` will test the frontend and the backend. However if you want to just run the frontend tests/linter you can run yarn commands in this directory. Install dependencies with `yarn install`. `yarn start` will fire up the development server. Use `yarn test` and `yarn lint` for running tests and the linter.
8+
9+
### Yarn Commands
10+
11+
| Yarn Command | Description |
12+
|-|-|
13+
| `yarn start` | Start the frontend development server |
14+
| `yarn build` | Build a production bundle |
15+
| `yarn test` | Start the test watcher |
16+
| `yarn test:ci` | Run unit tests a single time outputting results to xml files |
17+
| `yarn lint` | Run the linter |
18+
| `yarn lint:ci` | Run the linter outputting results to xml files |
19+
20+
## Create React App
21+
22+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
23+
24+
## Learn More
25+
26+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
27+
28+
To learn React, check out the [React documentation](https://reactjs.org/).
29+
30+
### Code Splitting
31+
32+
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
33+
34+
### Analyzing the Bundle Size
35+
36+
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
37+
38+
### Making a Progressive Web App
39+
40+
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
41+
42+
### Advanced Configuration
43+
44+
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
45+
46+
### Deployment
47+
48+
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
49+
50+
### `yarn build` fails to minify
51+
52+
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

frontend/build/favicon.ico

-3.08 KB
Binary file not shown.

frontend/build/logo192.png

-5.22 KB
Binary file not shown.

frontend/build/logo512.png

-9.44 KB
Binary file not shown.

frontend/build/manifest.json

-25
This file was deleted.

frontend/build/robots.txt

-3
This file was deleted.

frontend/package.json

+21-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
"scripts": {
1515
"start": "react-scripts start",
1616
"build": "react-scripts build",
17-
"test": "react-scripts test",
1817
"eject": "react-scripts eject",
19-
"test:ci": "CI=true yarn test --coverage --reporters=default --reporters=jest-junit"
18+
"test": "react-scripts test",
19+
"test:ci": "cross-env JEST_JUNIT_OUTPUT_DIR=reports JEST_JUNIT_OUTPUT_NAME=unit.xml CI=true yarn test --coverage --reporters=default --reporters=jest-junit",
20+
"lint": "eslint src",
21+
"lint:ci": "eslint -f eslint-formatter-multiple src"
2022
},
2123
"eslintConfig": {
2224
"root": true,
@@ -37,13 +39,27 @@
3739
".jsx"
3840
]
3941
}
40-
]
42+
],
43+
"linebreak-style": 0
4144
},
4245
"env": {
4346
"jest/globals": true,
4447
"browser": true
4548
}
4649
},
50+
"eslint-formatter-multiple": {
51+
"formatters": [
52+
{
53+
"name": "stylish",
54+
"output": "console"
55+
},
56+
{
57+
"name": "junit",
58+
"output": "file",
59+
"path": "reports/lint.xml"
60+
}
61+
]
62+
},
4763
"babel": {
4864
"presets": [
4965
"@babel/preset-react"
@@ -65,8 +81,10 @@
6581
"@testing-library/dom": "^7.21.7",
6682
"@testing-library/react": "^9.3.2",
6783
"@testing-library/user-event": "^7.1.2",
84+
"cross-env": "^7.0.2",
6885
"eslint": "^6.8.0",
6986
"eslint-config-airbnb": "^18.2.0",
87+
"eslint-formatter-multiple": "^1.0.0",
7088
"eslint-plugin-import": "^2.22.0",
7189
"eslint-plugin-jest": "^23.20.0",
7290
"eslint-plugin-jsx-a11y": "^6.3.1",

frontend/yarn.lock

+21
Original file line numberDiff line numberDiff line change
@@ -3405,6 +3405,13 @@ create-hmac@^1.1.0, create-hmac@^1.1.4, create-hmac@^1.1.7:
34053405
safe-buffer "^5.0.1"
34063406
sha.js "^2.4.8"
34073407

3408+
cross-env@^7.0.2:
3409+
version "7.0.2"
3410+
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.2.tgz#bd5ed31339a93a3418ac4f3ca9ca3403082ae5f9"
3411+
integrity sha512-KZP/bMEOJEDCkDQAyRhu3RL2ZO/SUVrxQVI0G3YEQ+OLbRA3c6zgixe8Mq8a/z7+HKlNEjo8oiLUs8iRijY2Rw==
3412+
dependencies:
3413+
cross-spawn "^7.0.1"
3414+
34083415
34093416
version "7.0.1"
34103417
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.1.tgz#0ab56286e0f7c24e153d04cc2aa027e43a9a5d14"
@@ -3425,6 +3432,15 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5:
34253432
shebang-command "^1.2.0"
34263433
which "^1.2.9"
34273434

3435+
cross-spawn@^7.0.1:
3436+
version "7.0.3"
3437+
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
3438+
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
3439+
dependencies:
3440+
path-key "^3.1.0"
3441+
shebang-command "^2.0.0"
3442+
which "^2.0.1"
3443+
34283444
crypto-browserify@^3.11.0:
34293445
version "3.12.0"
34303446
resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-3.12.0.tgz#396cf9f3137f03e4b8e532c58f698254e00f80ec"
@@ -4261,6 +4277,11 @@ eslint-config-react-app@^5.2.1:
42614277
dependencies:
42624278
confusing-browser-globals "^1.0.9"
42634279

4280+
eslint-formatter-multiple@^1.0.0:
4281+
version "1.0.0"
4282+
resolved "https://registry.yarnpkg.com/eslint-formatter-multiple/-/eslint-formatter-multiple-1.0.0.tgz#223db63a682038b001763c5d36d32975be4bdbb3"
4283+
integrity sha512-0Jv8gn7LmXj9c20E9BNAI1Wn3Lxw2v3nCvYRpk30kBLhc3wBees6DIXkJgaY2hoeOjvSq8n4peQ6KJstk5gmKQ==
4284+
42644285
eslint-import-resolver-node@^0.3.2, eslint-import-resolver-node@^0.3.3:
42654286
version "0.3.4"
42664287
resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.4.tgz#85ffa81942c25012d8231096ddf679c03042c717"

package.json

+27-9
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
"start": "concurrently \"yarn server\" \"yarn client\"",
99
"server": "nodemon src/index.js --ignore './frontend/' --exec babel-node",
1010
"client": "yarn --cwd frontend start",
11-
"test": "jest src && yarn --cwd frontend test --watchAll=false",
12-
"eslint": "eslint src",
13-
"lint:ci": "eslint src -f junit -o reports/lint.xml src",
14-
"test:ci": "jest src --coverage --reporters=default --reporters=jest-junit",
11+
"test": "jest src",
12+
"test:ci": "cross-env JEST_JUNIT_OUTPUT_DIR=reports JEST_JUNIT_OUTPUT_NAME=unit.xml CI=true jest src --coverage --reporters=default --reporters=jest-junit",
13+
"test:all": "yarn test:ci && yarn --cwd frontend test:ci",
14+
"lint": "eslint src",
15+
"lint:ci": "eslint -f eslint-formatter-multiple src",
16+
"lint:all": "yarn lint:ci && yarn --cwd frontend lint:ci",
1517
"clean": "rm -rf coverage reports frontend/coverage frontend/reports frontend/build",
16-
17-
"docker:shell:frontend": "docker-compose run --rm frontend /bin/bash",
18-
"docker:shell:backend": "docker-compose run --rm backend /bin/bash",
1918
"docker:deps": "docker-compose run --rm backend yarn install && docker-compose run --rm frontend yarn install",
2019
"docker:start": "docker-compose up -d",
2120
"docker:stop": "docker-compose down",
2221
"docker:test": "docker-compose run --rm backend yarn test:ci && docker-compose run --rm frontend yarn test:ci",
23-
"docker:lint": "docker-compose run --rm backend yarn lint:ci",
24-
"docker:audit": "docker-compose run --rm backend ./scripts/audit.sh && docker-compose run --rm frontend ./scripts/audit.sh"
22+
"docker:lint": "docker-compose run --rm backend yarn lint:ci && docker-compose run --rm frontend yarn lint:ci",
23+
"docker:shell:frontend": "docker-compose run --rm frontend /bin/bash",
24+
"docker:shell:backend": "docker-compose run --rm backend /bin/bash"
2525
},
2626
"repository": {
2727
"type": "git",
@@ -34,6 +34,22 @@
3434
],
3535
"ignorePatterns": [
3636
"node_modules/*"
37+
],
38+
"rules": {
39+
"linebreak-style": 0
40+
}
41+
},
42+
"eslint-formatter-multiple": {
43+
"formatters": [
44+
{
45+
"name": "stylish",
46+
"output": "console"
47+
},
48+
{
49+
"name": "junit",
50+
"output": "file",
51+
"path": "reports/lint.xml"
52+
}
3753
]
3854
},
3955
"jest": {
@@ -54,8 +70,10 @@
5470
"@babel/plugin-transform-runtime": "^7.11.0",
5571
"@babel/preset-env": "^7.11.0",
5672
"concurrently": "^5.3.0",
73+
"cross-env": "^7.0.2",
5774
"eslint": "^6.6.0",
5875
"eslint-config-airbnb-base": "^14.2.0",
76+
"eslint-formatter-multiple": "^1.0.0",
5977
"eslint-plugin-import": "^2.22.0",
6078
"eslint-plugin-jest": "^23.20.0",
6179
"eslint-plugin-jsx-a11y": "^6.3.1",

src/index.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import request from 'supertest';
22
import app from './app';
33

44
describe('Root', () => {
5-
test('Returns a 200', async () => {
5+
test('Successfully returns the page', async () => {
66
const response = await request(app).get('/');
77
expect(response.status).toBe(200);
88
});

0 commit comments

Comments
 (0)