Skip to content

Commit 748af10

Browse files
thibaudbraultThibaud Brault
andauthored
✅ add e2e test suite (#333)
Add an e2e test suite using playwright. This test suite bypasses authentication using the new environment variables `DISABLE_AUTH` and `REACT_APP_DISABLE_AUTH`. When authentication is bypassed, a fake user is automatically created and used. How to run the test suite is documented in `docs/src/advanced/testing.mdx`. CI is updated to run the test suite on every commit. Also upgrade prisma to 1.34. Co-authored-by: Thibaud Brault <[email protected]>
1 parent d4be336 commit 748af10

File tree

29 files changed

+6092
-61
lines changed

29 files changed

+6092
-61
lines changed

.circleci/config.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,41 @@ executors:
1010
app-builder:
1111
docker:
1212
- image: cimg/node:16.15
13+
e2e-runner:
14+
docker:
15+
- image: mcr.microsoft.com/playwright:v1.30.0-focal
16+
environment:
17+
PRISMA_URL: http://localhost:4466
18+
PRISMA_API_SECRET: secret-42
19+
PRISMA_MANAGEMENT_API_SECRET: my-secret-42
20+
SERVICE_NAME: default
21+
SERVICE_STAGE: default
22+
AUTH0_DOMAIN: auth0Domain
23+
AUTH0_CLIENT_ID: auth0ClientId
24+
ALGOLIA_APP_ID: M0NJ0PGAH1
25+
DISABLE_AUTH: true
26+
REACT_APP_DISABLE_AUTH: true
27+
REACT_APP_GRAPHQL_ENDPOINT: http://localhost:4000/gql
28+
REACT_APP_REST_ENDPOINT: http://localhost:4000/rest
29+
REACT_APP_PRISMA_SERVICE: default/default
30+
REACT_APP_FAQ_URL: faq.team
31+
- image: postgres
32+
environment:
33+
POSTGRES_USER: prisma
34+
POSTGRES_PASSWORD: prisma
35+
- image: prismagraphql/prisma:1.34.10
36+
environment:
37+
PRISMA_CONFIG: |
38+
port: 4466
39+
managementApiSecret: my-secret-42
40+
databases:
41+
default:
42+
connector: postgres
43+
host: localhost
44+
port: 5432
45+
user: prisma
46+
password: prisma
47+
migrations: true
1348
1449
jobs:
1550
server-lint:
@@ -37,6 +72,58 @@ jobs:
3772
- run:
3873
command: npm run prettier:check
3974
working_directory: client
75+
e2e-lint:
76+
executor: app-builder
77+
steps:
78+
- checkout
79+
- node/install-packages:
80+
app-dir: e2e
81+
- run:
82+
command: npm run lint
83+
working_directory: e2e
84+
- run:
85+
command: npm run prettier:check
86+
working_directory: e2e
87+
test:
88+
executor: e2e-runner
89+
steps:
90+
- checkout
91+
- node/install-packages:
92+
app-dir: e2e
93+
- node/install-packages:
94+
app-dir: server
95+
- node/install-packages:
96+
app-dir: client
97+
- run:
98+
name: Install wait-on
99+
command: npm install -g wait-on
100+
- run:
101+
name: Start client
102+
command: npm start
103+
working_directory: client
104+
background: true
105+
- run:
106+
name: Start server
107+
command: npm start
108+
working_directory: server
109+
background: true
110+
- run:
111+
name: Create new prisma service
112+
command: |
113+
wait-on http://localhost:4466
114+
npm run new_service default/default
115+
working_directory: server
116+
- run:
117+
name: Run tests
118+
command: |
119+
wait-on http://localhost:3000
120+
wait-on http://localhost:4466
121+
npm run test
122+
working_directory: e2e
123+
- store_test_results:
124+
path: ./e2e/results.xml
125+
- store_artifacts:
126+
path: ./e2e/test-results
40127

41128
client-build:
42129
executor: app-builder
@@ -125,6 +212,8 @@ workflows:
125212
jobs:
126213
- server-lint
127214
- client-lint
215+
- e2e-lint
216+
- test
128217
- client-build
129218
- app-deploy:
130219
clever-app-id: app_c61407ae-b417-4406-86ed-cfd1acf84466

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ node_modules
55

66
# testing
77
/coverage
8+
/e2e/test-results
89

910
# production
1011
.build

client/.env.local.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ REACT_APP_FAQ_URL=faq.zenika.com
22

33
REACT_APP_GRAPHQL_ENDPOINT=http://localhost:4000/gql
44
REACT_APP_REST_ENDPOINT=http://localhost:4000/rest
5+
REACT_APP_PRISMA_SERVICE=default/default
6+
7+
REACT_APP_DISABLE_AUTH=

client/jsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"compilerOptions": {
33
"baseUrl": "src"
44
}
5-
}
5+
}

client/package-lock.json

Lines changed: 50 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
}
5454
},
5555
"devDependencies": {
56+
"@playwright/test": "^1.31.2",
5657
"dotenv": "^5.0.0",
5758
"dotenv-cli": "^1.4.0",
5859
"eslint-config-prettier": "^4.3.0",

client/src/components/Authenticated/Authenticated.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import { useAuth } from 'contexts'
77

88
const Authenticated = ({ location, reverse, redirect, children, admin }) => {
99
const { isAuth, isAdmin } = useAuth()
10+
11+
if (process.env.REACT_APP_DISABLE_AUTH === 'true') {
12+
return children
13+
}
14+
1015
const currentURL = location.pathname + location.search
1116

1217
if (admin) {

client/src/components/TagPicker/TagPicker.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
height: 240px;
6060
border-radius: 3px;
6161
padding: 0.1rem 0;
62-
z-index: 10;
62+
z-index: 9;
6363
}
6464

6565
.tagpicker .picker::after,

client/src/scenes/App/components/Navbar/Navbar.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ const Navbar = () => {
5050
}
5151

5252
Navbar.translations = {
53-
en: { report_bug: 'report a bug', new_question: 'New question' },
54-
fr: { report_bug: 'signaler un bug', new_question: 'Nouvelle question' }
53+
en: { report_bug: 'Report a bug', new_question: 'New question' },
54+
fr: { report_bug: 'Signaler un bug', new_question: 'Nouvelle question' }
5555
}
5656

5757
export default Navbar

client/src/scenes/Auth/Login.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const Login = ({ location }) => {
1515

1616
const { login, renewAuth, isAuth, wasAuth } = useAuth()
1717

18-
if (isAuth) {
18+
if (isAuth || process.env.REACT_APP_DISABLE_AUTH === 'true') {
1919
return <Redirect to="/" />
2020
}
2121

0 commit comments

Comments
 (0)