Skip to content

Commit

Permalink
chore: move to new Playwright fixtures approach (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Mar 14, 2024
1 parent 531ee04 commit adf8bb0
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
${{ runner.os }}-playwright-bin-v1-
- name: Install Playwright
run: pnpm playwright-core install
run: pnpm playwright install chromium

- name: Prepare build environment
run: pnpm dev:prepare
Expand Down
29 changes: 15 additions & 14 deletions examples/app-playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,21 @@ export default defineConfig<ConfigOptions>({
nuxt,
}
},
{
name: 'Firefox',
use: {
...devices['Desktop Firefox'],
nuxt,
}
},
{
name: 'WebKit',
use: {
...devices['Desktop Safari'],
nuxt,
}
}
/* Test against other common browser engines. */
// {
// name: 'Firefox',
// use: {
// ...devices['Desktop Firefox'],
// nuxt,
// }
// },
// {
// name: 'WebKit',
// use: {
// ...devices['Desktop Safari'],
// nuxt,
// }
// }
/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"@nuxt/schema": "^3.10.3",
"@nuxt/test-utils": "workspace:*",
"@playwright/test": "^1.43.0-alpha-2024-03-14",
"playwright-core": "^1.43.0-alpha-2024-03-14",
"rollup": "4.13.0",
"vite": "5.1.6",
"vue": "^3.4.21"
Expand Down
31 changes: 7 additions & 24 deletions pnpm-lock.yaml

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

8 changes: 5 additions & 3 deletions src/core/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import type { TestContext, TestOptions } from './types'
let currentContext: TestContext | undefined

export function createTestContext (options: Partial<TestOptions>): TestContext {
const isVitest = process.env.VITEST === 'true'
const isPlaywright = 'PW_TS_ESM_LEGACY_LOADER_ON' in process.env || 'TEST_WORKER_INDEX' in process.env
const _options: Partial<TestOptions> = defu(options, {
testDir: resolve(process.cwd(), 'test'),
fixture: 'fixture',
Expand All @@ -17,11 +15,15 @@ export function createTestContext (options: Partial<TestOptions>): TestContext {
server: true,
build: (options.browser !== false) || (options.server !== false),
nuxtConfig: {},
runner: isVitest ? 'vitest' : isPlaywright ? 'playwright' : 'jest',
browserOptions: {
type: 'chromium' as const
}
} satisfies Partial<TestOptions>)
if (process.env.VITEST === 'true') {
_options.runner = 'vitest'
} else if (process.env.JEST_WORKER_ID) {
_options.runner = 'jest'
}

return setTestContext({
options: _options as TestOptions
Expand Down
2 changes: 0 additions & 2 deletions src/core/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import { createBrowser } from '../browser'
import type { TestHooks, TestOptions } from '../types'
import setupCucumber from './cucumber'
import setupJest from './jest'
import setupPlaywright from './playwright'
import setupVitest from './vitest'

export const setupMaps = {
cucumber: setupCucumber,
jest: setupJest,
playwright: setupPlaywright,
vitest: setupVitest
}

Expand Down
22 changes: 0 additions & 22 deletions src/core/setup/playwright.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Nuxt, NuxtConfig } from '@nuxt/schema'
import type { ExecaChildProcess } from 'execa'
import type { Browser, LaunchOptions } from 'playwright-core'

export type TestRunner = 'vitest' | 'jest' | 'cucumber' | 'playwright'
export type TestRunner = 'vitest' | 'jest' | 'cucumber'

export interface TestOptions {
testDir: string
Expand Down

0 comments on commit adf8bb0

Please sign in to comment.