Skip to content
This repository was archived by the owner on Apr 17, 2024. It is now read-only.

Commit f559f62

Browse files
authored
Feature/add-e2e-test (#2)
* add e2e test * use workspaces to separate dependencies * add circleci config * change wait strategy * add health check for docker compose, automate playwright config * update circle ci config * update circle ci config * update circle ci config * update circle ci config * update circle ci config * update circle ci config * update circle ci config * update circle ci config * update circle ci config * update circle ci config * update circle ci config * update circle ci config * update circle ci config * update circle ci config * update circle ci config * add more test case * update circle ci config * update circle ci config * update compose config to use localhost * update circle ci config * update e2e reports * add html report * cache docker in e2e test * fix caching and debug docker compose * deploy a simpler e2e test * set timeout to two minutes * rewrite tests * create docker based e2e test * use exec form in dockerfile
1 parent 009112c commit f559f62

14 files changed

+4747
-3902
lines changed

.circleci/config.yml

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
version: 2
22
jobs:
3+
lint:
4+
working_directory: ~/project
5+
docker:
6+
- image: circleci/node:16
7+
steps:
8+
- checkout
9+
- restore_cache:
10+
keys:
11+
- v2-dependencies-{{ .Branch }}-{{ checksum "package-lock.json" }}
12+
- v2-dependencies-
13+
- run:
14+
name: Install local dependencies
15+
command: npm clean-install
16+
- save_cache:
17+
key: v2-dependencies-{{ .Branch }}-{{ checksum "package-lock.json" }}
18+
paths:
19+
- node_modules
20+
- run:
21+
name: Lint project
22+
command: npm run lint
323
build:
424
working_directory: ~/project
525
docker:
@@ -38,13 +58,13 @@ jobs:
3858
- checkout
3959
- restore_cache:
4060
keys:
41-
- v1-dependencies-{{ checksum "package-lock.json" }}
42-
- v1-dependencies-
61+
- v3-dependencies-{{ .Branch }}-{{ checksum "package-lock.json" }}
62+
- v3-dependencies-
4363
- run:
4464
name: Install local dependencies
4565
command: npm clean-install
4666
- save_cache:
47-
key: v1-dependencies-{{ checksum "package-lock.json" }}
67+
key: v3-dependencies-{{ .Branch }}-{{ checksum "package-lock.json" }}
4868
paths:
4969
- node_modules
5070
- run:
@@ -53,30 +73,41 @@ jobs:
5373
- store_test_results:
5474
name: Store test results
5575
path: ~/project/reports
56-
lint:
76+
e2e:
5777
working_directory: ~/project
5878
docker:
59-
- image: circleci/node:16-browsers
79+
- image: mcr.microsoft.com/playwright:focal
6080
steps:
6181
- checkout
6282
- restore_cache:
6383
keys:
64-
- v1-dependencies-{{ checksum "package-lock.json" }}
65-
- v1-dependencies-
84+
- v5-dependencies-{{ .Branch }}-{{ checksum "package-lock.json" }}
85+
- v5-dependencies-
6686
- run:
67-
name: Install local dependencies
87+
name: Install dependencies
6888
command: npm clean-install
6989
- save_cache:
70-
key: v1-dependencies-{{ checksum "package-lock.json" }}
90+
key: v5-dependencies-{{ .Branch }}-{{ checksum "package-lock.json" }}
7191
paths:
7292
- node_modules
7393
- run:
74-
name: Lint project
75-
command: npm run lint
94+
name: Install browsers
95+
command: npx playwright install
96+
- run:
97+
name: Run e2e test
98+
command: npm run test --workspace=e2e -- --reporter=junit,html
99+
environment:
100+
PLAYWRIGHT_JUNIT_OUTPUT_NAME: reports/results.xml
101+
- store_test_results:
102+
name: Store test results
103+
path: ~/project/e2e/reports
104+
- store_artifacts:
105+
path: ~/project/e2e/playwright-report
76106
workflows:
77107
version: 2
78108
build_and_test_and_lint:
79109
jobs:
110+
- lint
80111
- build
81112
- test
82-
- lint
113+
- e2e

.dockerignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
.angular/cache/
22
.circleci/
3-
node_modules/
4-
dist/
5-
.idea/
63
.git/
4+
.idea/
5+
dist/
6+
e2e/
7+
node_modules/
78
reports/

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ RUN npm run build:ssr
1717

1818
FROM base as app
1919
COPY --from=build --chown=node /home/node/app/dist ./dist
20+
HEALTHCHECK --interval=5s --timeout=5s --retries=3 \
21+
CMD wget -nv -t1 --spider 'http://localhost:4000/health' || exit 1
2022
EXPOSE 4000
21-
ENTRYPOINT npm run serve:ssr
23+
ENTRYPOINT ["npm", "run", "serve:ssr"]

e2e/.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
playwright-report/
2+
reports/
3+
4+
docker-compose.yaml
5+
Dockerfile
6+
.dockerignore

e2e/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/playwright-report
2+
/reports

e2e/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM mcr.microsoft.com/playwright:focal
2+
3+
USER pwuser
4+
RUN mkdir /home/pwuser/app
5+
RUN chown pwuser /home/pwuser/app
6+
WORKDIR /home/pwuser/app
7+
8+
COPY --chown=pwuser package*.json ./
9+
10+
RUN npm install --no-fund --no-audit
11+
12+
COPY --chown=pwuser ./ ./
13+
14+
CMD ["npm", "test", "--", "--config=playwright.ci.config.ts"]

e2e/docker-compose.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: "3.9"
2+
services:
3+
frontend:
4+
build:
5+
context: '../'
6+
ports:
7+
- '127.0.0.1:4100:4000'
8+
healthcheck:
9+
test: "wget -nv -t1 --spider 'http://localhost:4000/health' || exit 1"
10+
start_period: 2s
11+
interval: 5s
12+
timeout: 5s
13+
retries: 3
14+
e2e:
15+
build:
16+
context: './'
17+
volumes:
18+
- './reports:/home/pwuser/app/reports:w'
19+
- './playwright-report:/home/pwuser/app/playwright-report:w'

e2e/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "e2e",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"test": "playwright test"
6+
},
7+
"private": true,
8+
"dependencies": {
9+
"@playwright/test": "^1.17.1"
10+
}
11+
}

e2e/playwright.ci.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { PlaywrightTestConfig } from '@playwright/test';
2+
import defaultConfig from './playwright.config';
3+
4+
const config: PlaywrightTestConfig = {
5+
use: {
6+
baseURL: 'http://frontend:4000',
7+
},
8+
reporter: [
9+
['dot'],
10+
['html', { open: 'never' }],
11+
['junit', { outputFile: 'reports/results.xml' }],
12+
],
13+
projects: defaultConfig.projects,
14+
};
15+
export default config;

e2e/playwright.config.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { PlaywrightTestConfig } from '@playwright/test';
2+
3+
const config: PlaywrightTestConfig = {
4+
webServer: {
5+
command: 'npm run build:ssr && npm run serve:ssr',
6+
cwd: '../',
7+
port: 4000,
8+
timeout: 2 * 60 * 1000,
9+
reuseExistingServer: true,
10+
},
11+
use: {
12+
baseURL: 'http://localhost:4000',
13+
},
14+
projects: [
15+
{
16+
name: 'Chrome Stable',
17+
use: { browserName: 'chromium' },
18+
},
19+
{
20+
name: 'Desktop Safari',
21+
use: { browserName: 'webkit' },
22+
},
23+
{
24+
name: 'Desktop Firefox',
25+
use: { browserName: 'firefox' },
26+
},
27+
],
28+
};
29+
export default config;

0 commit comments

Comments
 (0)