Skip to content

Commit c8b5ec9

Browse files
committed
feat: integrate Playwright for end-to-end testing and update configuration files
1 parent 9cc4d5b commit c8b5ec9

File tree

4 files changed

+56
-81
lines changed

4 files changed

+56
-81
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ jobs:
3737
with:
3838
node-version: ${{ matrix.node }}
3939
cache: 'pnpm'
40-
40+
4141
- name: Install dependencies
4242
run: pnpm i --frozen-lockfile
43-
# - name: E2E Tests
44-
# run: pnpm nx e2e
45-
# env:
46-
# CI: true
43+
- name: E2E Tests
44+
run: pnpm e2e
45+
env:
46+
CI: true
4747
- name: Build
4848
run: pnpm run build
4949
env:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ Thumbs.db
4747
.nx/cache
4848
.nx/workspace-data
4949
/.scannerwork/
50+
test-results

.vscode/launch.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
33
"version": "0.2.0",
44
"configurations": [
5-
{
6-
"name": "ng serve",
7-
"type": "chrome",
8-
"request": "launch",
9-
"preLaunchTask": "npm: start",
10-
"url": "http://localhost:4200/"
11-
},
12-
{
13-
"name": "ng test",
14-
"type": "chrome",
15-
"request": "launch",
16-
"preLaunchTask": "npm: test",
17-
"url": "http://localhost:9876/debug.html"
18-
}
19-
]
5+
{
6+
"name": "Start App",
7+
"type": "chrome",
8+
"request": "attach",
9+
"preLaunchTask": "npm: start",
10+
"url": "http://localhost:4300"
11+
},
12+
{
13+
"name": "ng test",
14+
"type": "chrome",
15+
"request": "launch",
16+
"preLaunchTask": "npm: test",
17+
"url": "http://localhost:9876/debug.html"
18+
}
19+
]
2020
}

playwright.config.ts

Lines changed: 35 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,40 @@
11
import { devices, type PlaywrightTestConfig } from '@playwright/test';
2-
/**
3-
* Read environment variables from file.
4-
* https://github.com/motdotla/dotenv
5-
*/
6-
// require('dotenv').config();
72

83
/**
94
* See https://playwright.dev/docs/test-configuration.
105
*/
116
const config: PlaywrightTestConfig = {
12-
testDir: './playwright/e2e',
7+
testDir: './projects/ng-kit-demo/e2e',
138
/* Maximum time one test can run for. */
149
timeout: 30000,
1510
expect: {
1611
/**
1712
* Maximum time expect() should wait for the condition to be met.
1813
* For example in `await expect(locator).toHaveText();`
1914
*/
20-
timeout: 30000,
15+
timeout: 20000,
2116
},
2217
/* Run tests in files in parallel */
2318
fullyParallel: true,
2419
/* Fail the build on CI if you accidentally left test.only in the source code. */
2520
forbidOnly: !!process.env['CI'],
26-
/* Retry on CI only */
27-
retries: 2,
21+
/* Retry on CI twice */
22+
retries: process.env['CI'] ? 1 : 0,
2823
/* Opt out of parallel tests on CI. */
29-
workers: process.env['CI'] ? 2 : 4,
24+
workers: process.env['CI'] ? 3 : 4,
3025
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
31-
reporter: process.env['CI'] ? 'dot' : 'list',
26+
reporter: 'list',
3227
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
3328
use: {
34-
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
35-
actionTimeout: 0,
3629
/* Base URL to use in actions like `await page.goto('/')`. */
37-
//baseURL: process.env.CI ? process.env.URL : 'http://localhost:4200',
3830
baseURL: process.env['URL'],
31+
32+
/* set data-cy as test attribute */
33+
testIdAttribute: 'data-cy',
34+
35+
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
36+
actionTimeout: 0,
37+
3938
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
4039
trace: 'on-first-retry',
4140
screenshot: 'off',
@@ -44,62 +43,37 @@ const config: PlaywrightTestConfig = {
4443

4544
/* Configure projects for major browsers */
4645
projects: [
46+
{ name: 'setup', testMatch: /.*\.setup\.ts/ },
4747
{
4848
name: 'chromium',
49-
50-
/* Project-specific settings. */
5149
use: {
5250
...devices['Desktop Chrome'],
51+
storageState: 'playwright/.auth/read-only-user.json',
5352
},
53+
dependencies: ['setup'],
54+
},
55+
{
56+
name: 'firefox',
57+
use: {
58+
...devices['Desktop Firefox'],
59+
storageState: 'playwright/.auth/read-only-user.json',
60+
},
61+
dependencies: ['setup'],
62+
},
63+
{
64+
name: 'webkit',
65+
use: {
66+
...devices['Desktop Safari'],
67+
storageState: 'playwright/.auth/read-only-user.json',
68+
},
69+
dependencies: ['setup'],
5470
},
55-
/* Test against branded browsers. */
56-
// {
57-
// name: 'Microsoft Edge',
58-
// use: {
59-
// channel: 'msedge',
60-
// },
61-
// },
62-
// {
63-
// name: 'Google Chrome',
64-
// use: {
65-
// channel: 'chrome',
66-
// },
67-
// },
68-
// {
69-
// name: 'firefox',
70-
// use: {
71-
// ...devices['Desktop Firefox'],
72-
// },
73-
// },
74-
// {
75-
// name: 'webkit',
76-
// use: {
77-
// ...devices['Desktop Safari'],
78-
// },
79-
// },
80-
/* Test against mobile viewports. */
81-
// {
82-
// name: 'Mobile Chrome',
83-
// use: {
84-
// ...devices['Pixel 5'],
85-
// },
86-
// },
87-
// {
88-
// name: 'Mobile Safari',
89-
// use: {
90-
// ...devices['iPhone 12'],
91-
// },
92-
// },
9371
],
9472

95-
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
96-
// outputDir: 'test-results/',
97-
9873
/* Run your local dev server before starting the tests */
99-
// webServer: {
100-
// command: 'npm run start',
101-
// port: 4200,
102-
// },
74+
webServer: {
75+
command: 'pnpm start',
76+
},
10377
};
10478

10579
export default config;

0 commit comments

Comments
 (0)