Skip to content

Commit 9c8527e

Browse files
feat(#1304624): Add e2e tests and add the service that lauches them in docker compose
1 parent 028f4c3 commit 9c8527e

File tree

17 files changed

+623
-6
lines changed

17 files changed

+623
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- master
77
- '[1-9].[0-9]+.x'
88
- 'feature-[a-z]+'
9+
- 'feat-1304624-tests-e2e-playwright'
910
pull_request:
1011
branches:
1112
- master

.github/workflows/tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ jobs:
145145
- name: Jest
146146
run: ${{env.docker_compose_cmd}} exec -T pwa yarn test:ci
147147

148+
- name: e2e
149+
run: ${{env.docker_compose_cmd}} exec -T e2e yarn test:ci
150+
148151
- name: Frontend Coverage Report
149152
uses: 5monkeys/cobertura-action@v12
150153
if: ${{ github.event_name == 'pull_request' }}

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ phpunit: ## Run php unit tests, pass the parameter "p=" to launch tests on a spe
143143
jest: ## Run jest unit tests
144144
@$(DOCKER_COMP) exec pwa yarn test
145145

146+
e2e: ## Run e2e tests
147+
@$(DOCKER_COMP) exec e2e yarn test
148+
146149
jest_update: ## Run jest unit tests
147150
@$(DOCKER_COMP) exec pwa yarn test:update
148151

compose.ci.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include:
2+
- compose.e2e.yml
13
services:
24

35
certbot:
@@ -13,17 +15,25 @@ services:
1315
environment:
1416
- APP_ENV=dev
1517
- XDEBUG_MODE=off
18+
- TRUSTED_HOSTS=${TRUSTED_HOSTS:-^${SERVER_NAME:-|gally.localhost}|localhost|${E2E_SERVER_NAME:-gally.e2e}|php$$}
1619

1720
pwa:
1821
build:
1922
target: gally_pwa_ci
2023
volumes:
2124
- ./front/example-app/coverage:/usr/src/front/example-app/coverage:rw,cached,z
2225
- ./front/pwa/coverage:/usr/src/front/pwa/coverage:rw,cached,z
23-
26+
environment:
27+
- NEXT_PUBLIC_ENTRYPOINT=
28+
- NEXT_PUBLIC_API_URL=
29+
- REACT_APP_API_URL=
2430
example:
2531
build:
2632
context: ./docker/front
2733
target: gally_example_ci
2834
additional_contexts:
2935
front_src: ./front
36+
37+
e2e:
38+
environment:
39+
- CI=true

compose.e2e.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# E2E environment override
2+
services:
3+
e2e:
4+
build:
5+
context: .
6+
dockerfile: ./docker/front/Dockerfile.e2e
7+
environment:
8+
- SERVER_BASE_URL=https://${E2E_SERVER_NAME:-gally.e2e}
9+
- API_SERVER_BASE_URL=https://${E2E_SERVER_NAME:-gally.e2e}/${API_ROUTE_PREFIX:-api}
10+
depends_on:
11+
- proxy
12+
extra_hosts:
13+
- ${E2E_SERVER_NAME:-gally.e2e}:host-gateway
14+
volumes:
15+
- ./front/e2e/:/usr/src/app:rw,cached,z

compose.override.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Development environment override
2+
include:
3+
- compose.e2e.yml
24
services:
35

46
certbot:
@@ -21,6 +23,7 @@ services:
2123
- ./docker/php/conf.d/app.dev.ini:/usr/local/etc/php/conf.d/app.dev.ini:ro,z
2224
environment:
2325
- APP_ENV=${APP_ENV:-dev}
26+
- TRUSTED_HOSTS=${TRUSTED_HOSTS:-^${SERVER_NAME:-|gally.localhost}|localhost|${E2E_SERVER_NAME:-gally.e2e}|php$$}
2427
# See https://xdebug.org/docs/all_settings#mode
2528
- XDEBUG_MODE=${XDEBUG_MODE:-off}
2629
- PHP_IDE_CONFIG=serverName=gally
@@ -41,6 +44,9 @@ services:
4144
environment:
4245
# On Linux, you may want to comment the following line for improved performance
4346
- WATCHPACK_POLLING="true"
47+
- NEXT_PUBLIC_ENTRYPOINT=
48+
- NEXT_PUBLIC_API_URL=
49+
- REACT_APP_API_URL=
4450

4551
example:
4652
user: ${UUID?You must set UUID env var}:${GUID?You must set GUID env var}

docker/front/Dockerfile.e2e

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM mcr.microsoft.com/playwright:v1.39.0
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY ./front/e2e/ .
6+
7+
RUN yarn install
8+
9+
RUN npx playwright install chromium
10+
RUN npx playwright install-deps chromium
11+
12+
# CMD ["yarn", "test"]
13+
# CMD ["tail", "-f", "/dev/null"]
14+
CMD ["sleep", "infinity"]

front/e2e/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
/test-results/
3+
/playwright-report/
4+
/blob-report/
5+
/playwright/.cache/

front/e2e/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "e2e",
3+
"private": "false",
4+
"version": "1.0.0",
5+
"main": "index.js",
6+
"license": "MIT",
7+
"devDependencies": {
8+
"@playwright/test": "^1.47.2",
9+
"@types/node": "^22.6.1"
10+
},
11+
"scripts": {
12+
"test": "yarn playwright test",
13+
"test:ci": "yarn playwright test",
14+
"test:standard": "yarn playwright test --grep @standard",
15+
"test:premium": "yarn playwright test --grep @premium"
16+
},
17+
"dependencies": {}
18+
}

front/e2e/playwright.config.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
// import dotenv from 'dotenv'
3+
// import path from 'path'
4+
5+
// Read from ".env" file.
6+
// dotenv.config({ path: path.resolve(__dirname, '.env') })
7+
8+
/**
9+
* Read environment variables from file.
10+
* https://github.com/motdotla/dotenv
11+
*/
12+
// import dotenv from 'dotenv';
13+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
14+
15+
/**
16+
* See https://playwright.dev/docs/test-configuration.
17+
*/
18+
export default defineConfig({
19+
testDir: './tests',
20+
/* Run tests in files in parallel */
21+
fullyParallel: false,
22+
/* Fail the build on CI if you accidentally left test.only in the source code. */
23+
forbidOnly: !!process.env.CI,
24+
/* Retry on CI only */
25+
retries: process.env.CI ? 2 : 0,
26+
/* Opt out of parallel tests on CI. */
27+
workers: process.env.CI ? 1 : undefined,
28+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
29+
reporter: 'html',
30+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
31+
use: {
32+
baseURL: process.env.SERVER_BASE_URL,
33+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
34+
trace: 'on-first-retry',
35+
headless: true, // Exécuter tous les tests en mode headless
36+
ignoreHTTPSErrors: true, // Ignorer les erreurs HTTPS
37+
},
38+
projects: [
39+
{
40+
name: 'chromium',
41+
use: { ...devices['Desktop Chrome'] },
42+
},
43+
],
44+
45+
/* Run your local dev server before starting the tests */
46+
// webServer: {
47+
// command: 'npm run start',
48+
// url: 'http://127.0.0.1:3000',
49+
// reuseExistingServer: !process.env.CI,
50+
// },
51+
})

0 commit comments

Comments
 (0)