Skip to content

Commit

Permalink
test: component + e2e testing setup
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisSmuda committed Feb 16, 2025
1 parent 458557c commit 6342756
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 18 deletions.
10 changes: 10 additions & 0 deletions e2e/about-page.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { expect, test } from '@nuxt/test-utils/playwright'

test.beforeEach(async ({ goto }) => {
await goto('/about')
})

test('page: about - shows correct title', async ({ page }) => {
const headingContent = await page.textContent('h1')
await expect(headingContent).toContain('about me')
})
49 changes: 48 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"build": "nuxt build",
"dev": "nuxt dev",
"test": "vitest",
"test:e2e": "playwright test -c playwright.config.ts",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
Expand All @@ -24,11 +25,11 @@
"devDependencies": {
"@antfu/eslint-config": "^4.2.1",
"@nuxt/test-utils": "^3.15.4",
"@playwright/test": "^1.50.1",
"@tailwindcss/typography": "^0.5.16",
"@vue/test-utils": "^2.4.6",
"eslint": "^9.20.1",
"happy-dom": "^16.8.1",
"playwright-core": "^1.50.1",
"vitest": "^3.0.5"
}
}
80 changes: 80 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import type { ConfigOptions } from '@nuxt/test-utils/playwright'
import { fileURLToPath } from 'node:url'
import { defineConfig, devices } from '@playwright/test'
import { isCI, isWindows } from 'std-env'

export default defineConfig<ConfigOptions>({
testDir: './e2e',
testIgnore: '**/features/**',
fullyParallel: true,
forbidOnly: !!isCI,
retries: isCI ? 2 : 0,
workers: isCI ? 1 : undefined,
timeout: isWindows ? 60000 : undefined,
reporter: 'html',

use: {
// trace: 'on-first-retry',
nuxt: {
rootDir: fileURLToPath(new URL('.', import.meta.url)),
},
},
// ...
// projects: devicesToTest.map(p => typeof p === 'string' ? ({ name: p, use: devices[p] }) : p),
})

/**
* See https://playwright.dev/docs/test-configuration.
*/
/**
*
export default defineConfig({
use: {
baseURL: 'http://localhost:3000',
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },
// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],
webServer: {
command: 'npm run dev',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
},
})
*/
14 changes: 0 additions & 14 deletions test/about-page.spect.ts

This file was deleted.

3 changes: 1 addition & 2 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { defineVitestConfig } from '@nuxt/test-utils/config'

console.log('jojo')

export default defineVitestConfig({
test: {
environment: 'nuxt',
exclude: ['**/e2e/**', '**/node_modules/**'],
},
})

0 comments on commit 6342756

Please sign in to comment.