Skip to content

Commit

Permalink
chore: replace cypress with playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
mvarendorff committed Dec 10, 2023
1 parent 9e7f44f commit f249c0f
Show file tree
Hide file tree
Showing 25 changed files with 237 additions and 775 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/ensure-integrity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}

e2e-test:
name: "Cypress E2E-Test"
name: "Playwright E2E-Test"
needs: [ docker-build-server, docker-build-web, docker-build-cms ]
runs-on: ubuntu-latest
steps:
Expand All @@ -82,10 +82,9 @@ jobs:
- name: Run e2e tests
run: |
docker-compose -f docker-compose.e2e.yml up --no-build -d server cms web
sleep 10
docker-compose -f docker-compose.e2e.yml logs cms server
docker-compose -f docker-compose.e2e.yml run cypress
docker-compose -f docker-compose.e2e.yml run playwright
docker-compose -f docker-compose.e2e.yml down
# TODO upload artifacts like videos / reports

remove-test-containers:
name: "Clean"
Expand Down
5 changes: 0 additions & 5 deletions .prettierignore

This file was deleted.

16 changes: 10 additions & 6 deletions docker-compose.e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,21 @@ services:
volumes:
- "typesense-data:/data"

cypress:
image: cypress/included:11.0.1
playwright:
image: mcr.microsoft.com/playwright:v1.40.1-focal
entrypoint: "/bin/bash"
command: "/wait-for-it.sh -t 30 --strict server:5000 -- ./cypress/install-and-run.sh"
command: "/wait-for-it.sh -t 30 --strict server:5000 -- yarn playwright test"
working_dir: /e2e
volumes:
- ./packages/web/cypress:/e2e/cypress
- ./packages/web/cypress.config.ts:/e2e/cypress.config.ts
- ./packages/web/cypress/wait-for-it.sh:/wait-for-it.sh
- ./packages/e2e:/e2e
environment:
FRONTEND_URL: http://web:3000
depends_on:
- web
- server
- cms
- postgres
- typesense

volumes:
typesense-data:
5 changes: 5 additions & 0 deletions packages/e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
1 change: 1 addition & 0 deletions packages/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# e2e
6 changes: 6 additions & 0 deletions packages/e2e/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @type {import('eslint').Linter.FlatConfig[]}
*/
module.exports = [
...require('@atmina/linting/eslint/recommended'),
];
2 changes: 2 additions & 0 deletions packages/e2e/install-and-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
yarn
yarn playwright test
20 changes: 20 additions & 0 deletions packages/e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "e2e",
"packageManager": "[email protected]",
"devDependencies": {
"@atmina/linting": "^2.0.1",
"@playwright/test": "^1.40.1",
"@types/eslint": "^8.44.8",
"@types/node": "^20.10.4",
"eslint": "^8.55.0",
"prettier": "^3.1.1"
},
"scripts": {
"lint": "yarn run lint:fix && yarn run prettier:fix",
"eslint:check": "eslint . --report-unused-disable-directives --max-warnings 0",
"eslint:fix": "eslint . --fix --report-unused-disable-directives --max-warnings 0",
"prettier:check": "prettier . --check",
"prettier:fix": "prettier . --write"
},
"prettier": "@atmina/linting/prettier"
}
50 changes: 50 additions & 0 deletions packages/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {defineConfig, devices} from '@playwright/test';

import {config} from 'dotenv';

config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
baseURL: process.env.FRONTEND_URL ?? 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},
expect: {
timeout: 5000,
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: {...devices['Desktop Chrome']},
},

{
name: 'firefox',
use: {...devices['Desktop Firefox']},
},

{
name: 'webkit',
use: {...devices['Desktop Safari']},
},
],
});
11 changes: 11 additions & 0 deletions packages/e2e/tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {test, expect} from '@playwright/test';

test('has title', async ({page}) => {
await page.goto('/');

// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/YesTheory Family/);

await page.getByRole('button', {name: 'Accept'}).click();
await expect(page.getByText('We are happy to have you')).toBeVisible();
});
10 changes: 10 additions & 0 deletions packages/e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
File renamed without changes.
3 changes: 0 additions & 3 deletions packages/web/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,3 @@ yarn-error.log*

# Generated graphql files
schema.graphql

cypress/screenshots
cypress/videos
15 changes: 0 additions & 15 deletions packages/web/cypress.config.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/web/cypress/e2e/example.cy.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/web/cypress/fixtures/example.json

This file was deleted.

2 changes: 0 additions & 2 deletions packages/web/cypress/install-and-run.sh

This file was deleted.

22 changes: 0 additions & 22 deletions packages/web/cypress/plugins/index.js

This file was deleted.

Empty file.
17 changes: 0 additions & 17 deletions packages/web/cypress/support/e2e.ts

This file was deleted.

11 changes: 0 additions & 11 deletions packages/web/cypress/tsconfig.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"chromatic": "env-cmd -f .env.local chromatic",
"codegen": "graphql-codegen",
"dev": "yarn codegen && yarn next",
"e2e:open": "cypress open --config baseUrl=http://localhost:3000",
"e2e:run": "cypress run --config baseUrl=http://localhost:3000",
"lint": "yarn run lint:fix && yarn run prettier:fix",
"start": "next start",
"test": "echo web: ok",
Expand Down Expand Up @@ -38,7 +36,6 @@
"@types/prettier": "^3.0.0",
"autoprefixer": "^10.4.16",
"chromatic": "^9.1.0",
"cypress": "11.2.0",
"env-cmd": "^10.1.0",
"eslint": "^8.55.0",
"eslint-config-next": "^14.0.3",
Expand Down
Loading

0 comments on commit f249c0f

Please sign in to comment.