Skip to content

Commit a5cc4d0

Browse files
authored
End 2 end tests (jsperf#134)
* move unit test to unit direcotry * fix failing health check responding 200 instead of 500 * add end to end test structure
1 parent e765f28 commit a5cc4d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2312
-3831
lines changed

Diff for: .dockerignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ node_modules
33
.dockerignore
44
.editorconfig
55
.env
6-
.eslintignore
7-
.eslintrc
86
.gitattributes
97
.gitignore
108
.nvmrc
119
*.md
1210
docker-compose.yml
11+
docker-compose.e2e.yml
1312
Dockerfile

Diff for: .eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
public/_js
3+
tmp*

Diff for: Dockerfile

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
FROM node:5.11.1
22

3-
ADD ./package.json /code/package.json
43
WORKDIR /code
4+
5+
COPY ./package.json /code/package.json
6+
57
RUN npm install
68

7-
ADD . /code
9+
COPY . /code
810

911
EXPOSE 3000
1012

Diff for: Dockerfile-e2e-runner

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM mhart/alpine-node:5.11.1
2+
3+
WORKDIR /code
4+
5+
COPY ./package.json /code/package.json
6+
7+
RUN npm install --only=dev
8+
9+
COPY .eslint* /code/
10+
COPY ./test/e2e /code/test/e2e
11+
12+
# CMD ["npm", "run", "test-e2e"]
13+
CMD ["/bin/true"]

Diff for: README.md

+24-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
2. Install dependencies: `npm install`
1414
3. Get a [Browserscope.org](http://www.browserscope.org/) API key by signing in and going to [the settings page](http://www.browserscope.org/user/settings). (You'll need this in the last step)
1515
4. Register a new OAuth GitHub development application by going to [your settings page in github](https://github.com/settings/applications/new). Take note to copy the "Client ID" and "Client Secret". The callback URL is simply the root url of the application, e.g., `http://localhost:3000`
16-
5. Setup environment configuration: `npm run setup`
16+
5. Setup environment configuration: `node setup`
1717

1818
### Running the server
1919

@@ -23,9 +23,13 @@ jsPerf is available at `localhost` and changes to the codebase can be applied by
2323

2424
##### One-time Setup
2525

26+
_`$MYSQL_PASSWORD` is whatever you chose or generated during `node setup`_
27+
2628
1. Install [Docker Toolbox](https://docs.docker.com/engine/installation/) so you have `docker` and `docker-compose`
2729
2. Create a Data Volume Container to persist data: `docker create -v /var/lib/mysql --name data-jsperf-mysql mysql /bin/true`
28-
3. After completing the "Compose" steps below, setup database tables with: `docker-compose run web node /code/setup/tables`
30+
3. Start Docker Compose in detached mode: `MYSQL_PASSWORD=$MYSQL_PASSWORD docker-compose up`
31+
4. Setup database tables with: `MYSQL_PASSWORD=$MYSQL_PASSWORD docker-compose run web node /code/setup/tables`
32+
5. Verify everything is working: `open http://$(docker-machine ip)`
2933

3034
##### Compose
3135

@@ -89,19 +93,34 @@ _If you'd just like to lint and save a little time, you can run `npm run lint` w
8993

9094
_If you're missing code coverage, open `coverage.html` in the root of the project for a detailed visual report._
9195

96+
### End to End
97+
98+
End to end (e2e) testing is done with Selenium. There is a separate Docker Compose file to define the Selenium Grid Hub, Selenium Nodes, and the test runner. Running the e2e test suite is a three step process:
99+
100+
1. Build containers: `docker-compose -f docker-compose.yml -f docker-compose.e2e.yml build`
101+
2. Start the app along with Selenium: `MYSQL_PASSWORD=$MYSQL_PASSWORD docker-compose -f docker-compose.yml -f docker-compose.e2e.yml up -d`
102+
- To scale up available Selenium Nodes to make testing faster, run: `docker-compose -f docker-compose.yml -f docker-compose.e2e.yml scale firefox=5` (_5 is the number of VMs Sauce Labs gives open source projects_)
103+
3. Run the test suite: `docker-compose -f docker-compose.yml -f docker-compose.e2e.yml run --rm runner npm run test-e2e`
104+
105+
When you're done, you can safely stop and remove all of the containers by running:
106+
107+
```
108+
docker-compose -f docker-compose.yml -f docker-compose.e2e.yml down
109+
```
110+
92111
## Gotchas
93112

94113
- ES6 Template Strings are not supported by esprima which means you can't generate coverage reports which means `npm test` won't pass.
95114

96115
### Adding new dependencies
97116

98117
1. Install using `npm` and either `--save` or `--save-dev`. Do not edit `package.json` manually.
99-
2. Run `npm run shrinkwrap` to update `npm-shrinkwrap.json`
118+
2. Run `npm shrinkwrap --dev` to update `npm-shrinkwrap.json`
100119

101-
If you get an error while shrinkwrapping, try removing what you have installed currently, reinstalling based on `package.json` instead of `npm-shrinkwrap.json`, and then shrinkwrap again.
120+
If you get an error while shrinkwrapping, try pruning your `node_modules` directory by running `npm prune`. If that doesn't work, try removing what you have installed currently, reinstalling based on `package.json` instead of `npm-shrinkwrap.json`, and then shrinkwrap again.
102121

103122
```
104-
rm -r node_modules/ && npm install --ignore-shrinkwrap && npm run shrinkwrap
123+
rm -r node_modules/ && npm install --no-shrinkwrap && npm shrinkwrap --dev
105124
```
106125

107126
## Debugging

Diff for: docker-compose.e2e.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
hub:
2+
image: selenium/hub:2.46.0
3+
ports:
4+
- '4444:4444'
5+
6+
firefox:
7+
image: selenium/node-firefox:2.46.0
8+
restart: on-failure
9+
links:
10+
- hub
11+
- lb # from main docker-compose.yml
12+
13+
runner:
14+
build: .
15+
dockerfile: Dockerfile-e2e-runner
16+
environment:
17+
SELENIUM_REMOTE_URL: http://hub:4444/wd/hub
18+
JSPERF_REMOTE_URL: http://lb
19+
links:
20+
- hub

Diff for: docker-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ web:
1212
SERVICE_3000_CHECK_HTTP: '/health'
1313
SERVICE_3000_CHECK_INTERVAL: '1s'
1414
db:
15-
image: mysql
15+
image: mysql:5.7
1616
volumes_from:
1717
- data-jsperf-mysql
1818
env_file: .env
1919
environment:
20-
MYSQL_RANDOM_ROOT_PASSWORD: 'True'
20+
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
2121
MYSQL_PASSWORD: $MYSQL_PASSWORD
2222
MYSQL_DATABASE: jsperf
2323
MYSQL_USER: jsperf

0 commit comments

Comments
 (0)