Skip to content

Commit 8a0f1d2

Browse files
feat(tests): adding playwright w/ nx v17
1 parent 7d7ec2e commit 8a0f1d2

File tree

7 files changed

+142
-3
lines changed

7 files changed

+142
-3
lines changed

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["ms-playwright.playwright"]
3+
}

apps/website/.eslintrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"extends": [
3+
"plugin:playwright/recommended",
34
"../../.eslintrc.json",
45
"eslint:recommended",
56
"plugin:@typescript-eslint/recommended",
@@ -28,6 +29,10 @@
2829
{
2930
"files": ["*.js", "*.jsx"],
3031
"rules": {}
32+
},
33+
{
34+
"files": ["e2e/**/*.{ts,js,tsx,jsx}"],
35+
"rules": {}
3136
}
3237
]
3338
}

apps/website/e2e/example.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('has title', async ({ page }) => {
4+
await page.goto('/');
5+
6+
// Expect h1 to contain a substring.
7+
expect(await page.locator('h1').innerText()).toContain('Qwik UI');
8+
});

apps/website/playwright.config.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { nxE2EPreset } from '@nx/playwright/preset';
2+
import { defineConfig, devices } from '@playwright/test';
3+
4+
import { workspaceRoot } from '@nx/devkit';
5+
6+
// For CI, you may want to set BASE_URL to the deployed application.
7+
const baseURL = process.env['BASE_URL'] || 'http://localhost:5173';
8+
9+
/**
10+
* Read environment variables from file.
11+
* https://github.com/motdotla/dotenv
12+
*/
13+
// require('dotenv').config();
14+
15+
/**
16+
* See https://playwright.dev/docs/test-configuration.
17+
*/
18+
export default defineConfig({
19+
...nxE2EPreset(__filename, { testDir: './e2e' }),
20+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
21+
use: {
22+
baseURL,
23+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
24+
trace: 'on-first-retry',
25+
},
26+
/* Run your local dev server before starting the tests */
27+
webServer: {
28+
command: 'pnpm dev',
29+
url: 'http://localhost:5173',
30+
reuseExistingServer: !process.env.CI,
31+
cwd: workspaceRoot,
32+
// timeout: 120000,
33+
},
34+
projects: [
35+
{
36+
name: 'chromium',
37+
use: { ...devices['Desktop Chrome'] },
38+
},
39+
40+
{
41+
name: 'firefox',
42+
use: { ...devices['Desktop Firefox'] },
43+
},
44+
45+
{
46+
name: 'webkit',
47+
use: { ...devices['Desktop Safari'] },
48+
},
49+
50+
// Uncomment for mobile browsers support
51+
/* {
52+
name: 'Mobile Chrome',
53+
use: { ...devices['Pixel 5'] },
54+
},
55+
{
56+
name: 'Mobile Safari',
57+
use: { ...devices['iPhone 12'] },
58+
}, */
59+
60+
// Uncomment for branded browsers
61+
/* {
62+
name: 'Microsoft Edge',
63+
use: { ...devices['Desktop Edge'], channel: 'msedge' },
64+
},
65+
{
66+
name: 'Google Chrome',
67+
use: { ...devices['Desktop Chrome'], channel: 'chrome' },
68+
} */
69+
],
70+
});

apps/website/project.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@
8888
"options": {
8989
"command": "npx nx run website:build:production"
9090
}
91+
},
92+
"e2e": {
93+
"executor": "@nx/playwright:playwright",
94+
"outputs": ["{workspaceRoot}/dist/.playwright/apps/website"],
95+
"options": {
96+
"config": "apps/website/playwright.config.ts"
97+
}
9198
}
9299
},
93100
"tags": []

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"@nx/vite": "17.1.3",
6262
"@nx/workspace": "17.1.3",
6363
"@oddbird/popover-polyfill": "0.3.7",
64+
"@playwright/test": "^1.36.0",
6465
"@storybook/addon-a11y": "7.6.0",
6566
"@storybook/addon-coverage": "^0.0.9",
6667
"@storybook/addon-essentials": "7.6.0",
@@ -103,6 +104,7 @@
103104
"eslint": "^8.48.0",
104105
"eslint-config-prettier": "9.0.0",
105106
"eslint-plugin-cypress": "^2.14.0",
107+
"eslint-plugin-playwright": "^0.15.3",
106108
"eslint-plugin-qwik": "^1.4.0",
107109
"eslint-plugin-storybook": "^0.6.13",
108110
"focus-trap": "7.5.3",
@@ -160,5 +162,6 @@
160162
],
161163
"nx": {
162164
"includedScripts": []
163-
}
165+
},
166+
"dependencies": {}
164167
}

pnpm-lock.yaml

Lines changed: 45 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)