Skip to content

Commit ea76ecd

Browse files
committed
add e2e tests and its workflow
1 parent 826d508 commit ea76ecd

File tree

6 files changed

+189
-11
lines changed

6 files changed

+189
-11
lines changed

.github/workflows/pipeline.yml

+10-8
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ jobs:
1414
with:
1515
node-version: '20'
1616
# - uses: superfly/flyctl-actions/setup-flyctl@master
17-
- name: Install dependencies for frontend
18-
working-directory: ./frontend
17+
- name: Install dependencies
1918
run: npm ci
19+
- name: Install dependencies for frontend
20+
run: npm run install:frontend
2021
- name: Check style for frontend
21-
working-directory: ./frontend
22-
run: npm run lint
22+
run: npm run lint:frontend
2323
- name: Build for frontend
24-
working-directory: ./frontend
25-
run: npm run build
24+
run: npm run build:frontend
2625
- name: Test for frontend
27-
working-directory: ./frontend
28-
run: npm run test
26+
run: npm run test:frontend
27+
- name: Install Playwright Browsers
28+
run: npx playwright install --with-deps
29+
- name: e2e tests
30+
run: npm run test:e2e

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ yarn-error.log*
1616

1717
# OS generated files
1818
.DS_Store
19-
Thumbs.db
19+
Thumbs.db
20+
/test-results/
21+
/playwright-report/
22+
/blob-report/
23+
/playwright/.cache/

e2e-tests/homepage.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @ts-check
2+
const { test, expect } = require('@playwright/test');
3+
4+
test('has anecdotes title', async ({ page }) => {
5+
await page.goto('');
6+
7+
await expect(page.getByText('Anecdotes')).toBeVisible();
8+
});

package-lock.json

+76
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
"start": "node src/app.js",
77
"dev": "nodemon src/app.js",
88
"start:frontend": "cd frontend && npm run dev",
9-
"install:frontend": "cd frontend && npm install",
9+
"install:frontend": "cd frontend && npm ci",
10+
"lint:frontend": "cd frontend && npm run lint",
1011
"build:frontend": "cd frontend && npm run build",
11-
"test:frontend": "cd frontend && npm test"
12+
"test:frontend": "cd frontend && npm test",
13+
"test:e2e": "playwright test"
1214
},
1315
"keywords": [],
1416
"author": "",
@@ -20,6 +22,8 @@
2022
"uuid": "^10.0.0"
2123
},
2224
"devDependencies": {
25+
"@playwright/test": "^1.47.1",
26+
"@types/node": "^22.5.5",
2327
"nodemon": "^3.1.4"
2428
}
2529
}

playwright.config.js

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// @ts-check
2+
const { defineConfig, devices } = require('@playwright/test');
3+
4+
/**
5+
* Read environment variables from file.
6+
* https://github.com/motdotla/dotenv
7+
*/
8+
// require('dotenv').config({ path: path.resolve(__dirname, '.env') });
9+
10+
/**
11+
* @see https://playwright.dev/docs/test-configuration
12+
*/
13+
module.exports = defineConfig({
14+
testDir: './e2e-tests',
15+
/* Run tests in files in parallel */
16+
fullyParallel: false,
17+
/* Fail the build on CI if you accidentally left test.only in the source code. */
18+
forbidOnly: !!process.env.CI,
19+
/* Retry on CI only */
20+
retries: process.env.CI ? 2 : 0,
21+
/* Opt out of parallel tests on CI. */
22+
workers: process.env.CI ? 1 : undefined,
23+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
24+
reporter: 'html',
25+
webServer: {
26+
command: 'npm run start',
27+
url: 'http://127.0.0.1:3000',
28+
timeout: 120 * 1000,
29+
reuseExistingServer: !process.env.CI,
30+
},
31+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
32+
use: {
33+
/* Base URL to use in actions like `await page.goto('/')`. */
34+
baseURL: 'http://127.0.0.1:3000',
35+
36+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
37+
trace: 'on-first-retry',
38+
},
39+
40+
/* Configure projects for major browsers */
41+
projects: [
42+
{
43+
name: 'chromium',
44+
use: { ...devices['Desktop Chrome'] },
45+
},
46+
47+
{
48+
name: 'firefox',
49+
use: { ...devices['Desktop Firefox'] },
50+
},
51+
52+
{
53+
name: 'webkit',
54+
use: { ...devices['Desktop Safari'] },
55+
},
56+
57+
/* Test against mobile viewports. */
58+
// {
59+
// name: 'Mobile Chrome',
60+
// use: { ...devices['Pixel 5'] },
61+
// },
62+
// {
63+
// name: 'Mobile Safari',
64+
// use: { ...devices['iPhone 12'] },
65+
// },
66+
67+
/* Test against branded browsers. */
68+
// {
69+
// name: 'Microsoft Edge',
70+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
71+
// },
72+
// {
73+
// name: 'Google Chrome',
74+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
75+
// },
76+
],
77+
78+
/* Run your local dev server before starting the tests */
79+
// webServer: {
80+
// command: 'npm run start',
81+
// url: 'http://127.0.0.1:3000',
82+
// reuseExistingServer: !process.env.CI,
83+
// },
84+
});

0 commit comments

Comments
 (0)