Skip to content

Commit 83d9df1

Browse files
authored
Merge pull request #517 from Lemoncode/feature/#514-Configure-Playwright-e2e
setup Playwright with initial e2e test and scripts
2 parents d450740 + 4a1b9c3 commit 83d9df1

File tree

6 files changed

+180
-13
lines changed

6 files changed

+180
-13
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25+
/test-results/
26+
/playwright-report/
27+
/blob-report/
28+
/playwright/.cache/
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('navigates to and verifies MongoDB Designer URL', async ({ page }) => {
4+
await page.goto('');
5+
6+
await page.getByRole('link', { name: 'Launch MongoDB Designer' }).click();
7+
await expect(page).toHaveURL('http://localhost:5173/editor.html');
8+
});

package-lock.json

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

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
"version": "0.0.0",
55
"type": "module",
66
"scripts": {
7+
"postinstall": "npm run install:e2e-browsers",
8+
"install:e2e-browsers": "npx playwright install",
79
"dev": "vite",
810
"build": "tsc && vite build",
911
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
1012
"preview": "vite preview",
1113
"format": "prettier --write .",
1214
"test": "vitest",
13-
"prepare": "husky install",
14-
"tsc-check": "tsc --noEmit"
15+
"prepare": "husky || \"No need to install husky\"",
16+
"tsc-check": "tsc --noEmit",
17+
"e2e": "playwright test --ui"
1518
},
1619
"dependencies": {
1720
"@lemoncode/fonk": "^1.5.4",
@@ -26,6 +29,7 @@
2629
"react-dom": "^18.2.0"
2730
},
2831
"devDependencies": {
32+
"@playwright/test": "^1.48.1",
2933
"@testing-library/dom": "^9.3.4",
3034
"@testing-library/react": "^14.2.1",
3135
"@types/jest": "^29.5.11",

playwright.config.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
const BASE_URL = 'http://localhost:5173/';
4+
5+
export default defineConfig({
6+
testDir: './e2e',
7+
fullyParallel: true,
8+
forbidOnly: !!process.env.CI,
9+
retries: process.env.CI ? 2 : 0,
10+
workers: process.env.CI ? 1 : undefined,
11+
reporter: 'html',
12+
use: {
13+
baseURL: BASE_URL,
14+
trace: 'on-first-retry',
15+
},
16+
17+
/* Configure projects for major browsers */
18+
projects: [
19+
{
20+
name: 'chromium',
21+
use: { ...devices['Desktop Chrome'] },
22+
},
23+
24+
{
25+
name: 'firefox',
26+
use: { ...devices['Desktop Firefox'] },
27+
},
28+
29+
{
30+
name: 'webkit',
31+
use: { ...devices['Desktop Safari'] },
32+
},
33+
34+
/* Test against mobile viewports. */
35+
// {
36+
// name: 'Mobile Chrome',
37+
// use: { ...devices['Pixel 5'] },
38+
// },
39+
// {
40+
// name: 'Mobile Safari',
41+
// use: { ...devices['iPhone 12'] },
42+
// },
43+
44+
/* Test against branded browsers. */
45+
// {
46+
// name: 'Microsoft Edge',
47+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
48+
// },
49+
// {
50+
// name: 'Google Chrome',
51+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
52+
// },
53+
],
54+
/* Run your local dev server before starting the tests */
55+
webServer: {
56+
command: 'npm run dev',
57+
reuseExistingServer: !process.env.CI,
58+
},
59+
});

vite.config.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,7 @@ import { defineConfig } from 'vite';
22
import { fileURLToPath, URL } from 'node:url';
33
import react from '@vitejs/plugin-react';
44
import checker from 'vite-plugin-checker';
5-
import type { UserConfig as VitestUserConfigInterface } from 'vitest/config';
6-
7-
const vitestConfig: VitestUserConfigInterface = {
8-
test: {
9-
setupFiles: ['./vitest.setup.ts'],
10-
globals: true,
11-
restoreMocks: true,
12-
environment: 'jsdom',
13-
},
14-
};
5+
import { configDefaults } from 'vitest/config';
156

167
// https://vitejs.dev/config/
178
export default defineConfig({
@@ -24,7 +15,14 @@ export default defineConfig({
2415
},
2516
},
2617
},
27-
test: vitestConfig.test,
18+
test: {
19+
setupFiles: ['./vitest.setup.ts'],
20+
globals: true,
21+
environment: 'jsdom',
22+
restoreMocks: true,
23+
include: ['./src/**/*.spec.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
24+
exclude: [...configDefaults.exclude, 'e2e/*'],
25+
},
2826
resolve: {
2927
alias: {
3028
'@': fileURLToPath(new URL('./src', import.meta.url)),

0 commit comments

Comments
 (0)