Skip to content

Commit

Permalink
Fix/node server refactor (#15)
Browse files Browse the repository at this point in the history
* Add refactored node server with seperate routes

- Move routes to /routes/...
- Do node config in index.js
- Use proper session management

* Refactor react code to integrate with new server

- For checkToken, put the token in an Authorization header

* Remove npm-run-script from package.json

* Fix README to include new running details

* Remove use of npm run script from Jenkinsfile

* Change server test config

- When you run npm run test-server, it will run the test that builds the project first, before running the other tests recursively in /server-test-spec

* Use test:type rathe than test-type

* Fix server tests, use seperate files

- The test:server runs the server.test.js first, which tests the npm run build command and the serving of static assets, the api/auth functionality are then tested, by recursively testing all files in /test/server-test-spec/*

* Remove unused component tests, unused dependancies

- Remove unused component tests + package.json test script
- Refactor dependancies in package.json, move test ones to devDeps

* Change order of routes import in node server

- Fix /version

* Fix static files path

- Fix start command in package.json
  • Loading branch information
ONS-Tom authored and ONS-Anthony committed Dec 6, 2017
1 parent 1c7b12f commit 9aad1a2
Show file tree
Hide file tree
Showing 19 changed files with 621 additions and 490 deletions.
10 changes: 5 additions & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ pipeline {
parallel (
"Unit" : {
colourText("info","Running unit tests...")
sh 'npm run-script test-unit'
sh 'npm run test:unit'
},
"Stress" : {
colourText("info","Running stress tests...")
sh 'ENV=local node server/ & HOST=http://localhost:3001 REQUEST=5000 REQ_PER_SECOND=50 npm run-script test-load'
sh 'ENV=local node server/ & HOST=http://localhost:3001 REQUEST=5000 REQ_PER_SECOND=50 npm run test:load'
// sh 'killall node'
// The above command will leave node running, will this be closed along with the workspace?
},
"Server" : {
colourText("info","Running server tests...")
sh "npm run-script test-server"
sh "npm run test:server"
}
)
}
Expand All @@ -124,11 +124,11 @@ pipeline {
parallel (
"Coverage Report" : {
colourText("info","Generating coverage report...")
sh "npm run-script cover"
sh "npm run cover"
},
"Style Report" : {
colourText("info","Generating style report...")
sh 'npm run-script lint-report-xml'
sh 'npm run lint-report-xml'
}
)
}
Expand Down
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,29 @@ export BI_UI_TEST_ADMIN_USERNAME=admin
export BI_UI_TEST_ADMIN_PASSWORD=admin
export BI_UI_TEST_USER_USERNAME=test
export BI_UI_TEST_USER_PASSWORD=test
export JWT_SECRET=SECRET
```

## Running the UI:

1. Clone this repo, install dependencies and start NPM
1. Clone this repo and install dependencies

```shell
git clone https://github.com/ONSdigital/bi-ui.git
cd bi-ui
npm install
npm start
```

The NPM start command uses the following commands:
2. Start the `Node.js` server

```shell
npm run build
SERVE_HTML=true ENV=local node server
npm run start:server
```

This will run Node and React on localhost:3001, since Node is serving
`index.html`, hot-reloading will not work.
3. Start the `React.js` development server (with hot reloading)

To use hot-reloading, use `npm restart` which runs `react-scripts start`, this
will start React on port 3000. To start the server, use `ENV=local node server/index.js`.
```shell
npm run start:react
```

## Running the API

Expand Down
55 changes: 15 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,71 +15,47 @@
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"chai": "^3.5.0",
"enzyme": "^2.9.0",
"enzyme-redux": "^0.1.6",
"eslint": "^3.0.0",
"eslint-config-airbnb": "^15.0.1",
"eslint-plugin-flowtype": "^2.34.1",
"eslint-plugin-import": "^2.3.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^7.1.0",
"flow-bin": "^0.48.0",
"eslint-html-reporter": "^0.5.2",
"jasmine": "^2.5.3",
"jasmine-enzyme": "^3.3.0",
"jasmine-es6": "^0.4.0",
"jasmine-node": "^1.14.5",
"jsdom": "11.0.0",
"jsdom-global": "3.0.2",
"jasmine-es6": "^0.4.0",
"coveralls": "^2.13.1",
"flow-bin": "^0.48.0",
"mocha": "^3.0.2",
"istanbul": "^0.4.5",
"morgan": "^1.7.0",
"mz": "^2.4.0",
"react-scripts": "0.2.3",
"react-test-renderer": "^15.6.1",
"redux-mock-store": "^1.2.3",
"redux-test-utils": "^0.1.2",
"selenium-webdriver": "^3.3.0",
"loadtest": "^2.3.0",
"supertest": "^3.0.0",
"supertest-as-promised": "^4.0.0"
},
"dependencies": {
"base-64": "^0.1.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.17.2",
"compression": "^1.7.0",
"coveralls": "^2.13.1",
"d3": "^4.10.0",
"eslint-html-reporter": "^0.5.2",
"express": "^4.14.0",
"halogen": "^0.2.0",
"ie-version": "^0.1.0",
"istanbul": "^0.4.5",
"jasmine": "^2.5.3",
"jasmine-node": "^1.14.5",
"jquery": "^3.2.1",
"loadtest": "^2.3.0",
"memory-cache": "^0.2.0",
"morgan": "^1.7.0",
"npm-run-script": "0.0.4",
"object.assign": "^4.0.4",
"prop-types": "^15.5.10",
"rc-pagination": "^1.7.3",
"react": "^15.6.2",
"react-a11y": "^0.3.4",
"react-bootstrap": "^0.30.7",
"react-bootstrap-button-loader": "1.0.8",
"react-bootstrap-table": "^3.4.5",
"react-confetti": "^2.0.1",
"react-copy-to-clipboard": "^5.0.1",
"react-d3-tree": "^1.4.0",
"react-dom": "^15.5.4",
"react-modal-dialog": "^4.0.7",
"react-redux": "^5.0.5",
"react-router": "^2.6.1",
"react-router-bootstrap": "^0.23.1",
"react-select": "^1.0.0-rc.10",
"react-stepper-horizontal": "^1.0.9",
"react-table": "^6.5.3",
"react-toggle": "^4.0.1",
"react-tooltip": "^3.3.0",
"redux": "^3.6.0",
"redux-thunk": "^2.2.0",
"registers-react-library": "^1.0.0",
Expand All @@ -93,18 +69,17 @@
"npm": "3.8.3"
},
"scripts": {
"start:server": "ENV=local SERVER_AUTH_URL=http://localhost:3002/auth SERVER_API_GW_URL=http://localhost:3002 node server",
"start": "npm run build; SERVE_HTML=true ENV=local SERVER_AUTH_URL=http://localhost:3002/auth SERVER_API_GW_URL=http://localhost:3002 node server",
"restart": "REACT_APP_ENV=local REACT_APP_AUTH_URL=http://localhost:3001 REACT_APP_API_URL=http://localhost:3001/api react-scripts start",
"start": "REACT_APP_ENV=local REACT_APP_AUTH_URL=http://localhost:3001 REACT_APP_API_URL=http://localhost:3001/api npm run build; SERVE_HTML=true NODE_ENV=development SERVER_AUTH_URL=http://localhost:3002/auth SERVER_API_GW_URL=http://localhost:3002 node server",
"start:server": "NODE_ENV=development SERVER_AUTH_URL=http://localhost:3002/auth SERVER_API_GW_URL=http://localhost:3002 node server",
"start:react": "REACT_APP_ENV=local REACT_APP_AUTH_URL=http://localhost:3001 REACT_APP_API_URL=http://localhost:3001/api react-scripts start",
"build": "react-scripts build",
"eject": "react-scripts eject",
"cover": "NODE_ENV=test SERVE_HTML=true ENV=local ./node_modules/istanbul/lib/cli.js cover --report cobertura ./node_modules/mocha/bin/_mocha -- -R spec test/server.test.js",
"test": "npm run-script test-unit; npm run-script test-components; npm run-script test-server; npm run-script test-server",
"test-components": "./node_modules/babel-cli/bin/babel-node.js test/component-tests.js",
"test-unit": "./node_modules/babel-cli/bin/babel-node.js test/utils-unit-tests.js",
"test-load": "./node_modules/babel-cli/bin/babel-node.js test/loadtest-unit-tests.js",
"test-server": "ENV=local SERVE_HTML=true ./node_modules/mocha/bin/mocha test/server.test.js",
"test-selenium": "NODE_ENV=test UI_URL=http://localhost:3000 ./node_modules/jasmine/bin/jasmine.js test/integration-test.js",
"test": "npm run test:unit; npm run test:server; npm run test:server",
"test:unit": "./node_modules/babel-cli/bin/babel-node.js test/utils-unit-tests.js",
"test:load": "./node_modules/babel-cli/bin/babel-node.js test/loadtest-unit-tests.js",
"test:server": "./node_modules/mocha/bin/mocha test/server.test.js; ./node_modules/mocha/bin/mocha test/server-test-spec --recursive",
"test:selenium": "NODE_ENV=test UI_URL=http://localhost:3000 ./node_modules/jasmine/bin/jasmine.js test/integration-test.js",
"lint": "./node_modules/eslint/bin/eslint.js **/*.js --ignore-pattern /test/*.js",
"lint-report-xml": "./node_modules/eslint/bin/eslint.js . -f checkstyle -o ./coverage/eslint-report-checkstyle.xml; exit 0",
"flow": "flow"
Expand Down
Loading

0 comments on commit 9aad1a2

Please sign in to comment.