From adf8bb0b25a396b92fea8e7ab77aff9b412fae04 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Fri, 15 Mar 2024 00:00:19 +0100 Subject: [PATCH] chore: move to new Playwright fixtures approach (#778) --- .github/workflows/ci.yml | 2 +- examples/app-playwright/playwright.config.ts | 29 +++++++++--------- package.json | 1 + pnpm-lock.yaml | 31 +++++--------------- src/core/context.ts | 8 +++-- src/core/setup/index.ts | 2 -- src/core/setup/playwright.ts | 22 -------------- src/core/types.ts | 2 +- 8 files changed, 30 insertions(+), 67 deletions(-) delete mode 100644 src/core/setup/playwright.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2997a1fea..0097fe35e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/examples/app-playwright/playwright.config.ts b/examples/app-playwright/playwright.config.ts index c9d13f200..84d5172b0 100644 --- a/examples/app-playwright/playwright.config.ts +++ b/examples/app-playwright/playwright.config.ts @@ -41,20 +41,21 @@ export default defineConfig({ 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', diff --git a/package.json b/package.json index a2e187878..7a1b89d25 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4afffa363..c5c977b5f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,6 +9,7 @@ overrides: '@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 @@ -160,8 +161,8 @@ importers: specifier: 3.10.3 version: 3.10.3(eslint@8.57.0)(rollup@4.13.0)(typescript@5.3.3)(vite@5.1.6)(vue-tsc@2.0.6) playwright-core: - specifier: 1.42.1 - version: 1.42.1 + specifier: ^1.43.0-alpha-2024-03-14 + version: 1.43.0-alpha-2024-03-14 rollup: specifier: 4.13.0 version: 4.13.0 @@ -231,8 +232,8 @@ importers: specifier: ^29.7.0 version: 29.7.0(@types/node@20.10.5)(ts-node@10.9.2) playwright-core: - specifier: 1.40.1 - version: 1.40.1 + specifier: ^1.43.0-alpha-2024-03-14 + version: 1.43.0-alpha-2024-03-14 ts-jest: specifier: ^29.1.1 version: 29.1.1(@babel/core@7.23.9)(jest@29.7.0)(typescript@5.3.3) @@ -284,8 +285,8 @@ importers: specifier: ^12.10.3 version: 12.10.3 playwright-core: - specifier: ^1.40.1 - version: 1.41.0 + specifier: ^1.43.0-alpha-2024-03-14 + version: 1.43.0-alpha-2024-03-14 typescript: specifier: ^5.3.3 version: 5.3.3 @@ -9768,24 +9769,6 @@ packages: mlly: 1.6.0 pathe: 1.1.2 - /playwright-core@1.40.1: - resolution: {integrity: sha512-+hkOycxPiV534c4HhpfX6yrlawqVUzITRKwHAmYfmsVreltEl6fAZJ3DPfLMOODw0H3s1Itd6MDCWmP1fl/QvQ==} - engines: {node: '>=16'} - hasBin: true - dev: true - - /playwright-core@1.41.0: - resolution: {integrity: sha512-UGKASUhXmvqm2Lxa1fNr8sFwAtqjpgBRr9jQ7XBI8Rn5uFiEowGUGwrruUQsVPIom4bk7Lt+oLGpXobnXzrBIw==} - engines: {node: '>=16'} - hasBin: true - dev: true - - /playwright-core@1.42.1: - resolution: {integrity: sha512-mxz6zclokgrke9p1vtdy/COWBH+eOZgYUVVU34C73M+4j4HLlQJHtfcqiqqxpP0o8HhMkflvfbquLX5dg6wlfA==} - engines: {node: '>=16'} - hasBin: true - dev: true - /playwright-core@1.43.0-alpha-2024-03-14: resolution: {integrity: sha512-Rmf6Atjiao2KHY51+q/I4I6NAoN2+Fzdu34JxrelpWXbjOADDX7dMyn16pWC2iAnX8Zb9+1kOyRBC27mZA7k2A==} engines: {node: '>=16'} diff --git a/src/core/context.ts b/src/core/context.ts index cf0b7a53e..5fd612eff 100644 --- a/src/core/context.ts +++ b/src/core/context.ts @@ -5,8 +5,6 @@ import type { TestContext, TestOptions } from './types' let currentContext: TestContext | undefined export function createTestContext (options: Partial): 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 = defu(options, { testDir: resolve(process.cwd(), 'test'), fixture: 'fixture', @@ -17,11 +15,15 @@ export function createTestContext (options: Partial): TestContext { server: true, build: (options.browser !== false) || (options.server !== false), nuxtConfig: {}, - runner: isVitest ? 'vitest' : isPlaywright ? 'playwright' : 'jest', browserOptions: { type: 'chromium' as const } } satisfies Partial) + if (process.env.VITEST === 'true') { + _options.runner = 'vitest' + } else if (process.env.JEST_WORKER_ID) { + _options.runner = 'jest' + } return setTestContext({ options: _options as TestOptions diff --git a/src/core/setup/index.ts b/src/core/setup/index.ts index ce4ddad05..0e91d5b2c 100644 --- a/src/core/setup/index.ts +++ b/src/core/setup/index.ts @@ -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 } diff --git a/src/core/setup/playwright.ts b/src/core/setup/playwright.ts deleted file mode 100644 index 5c5f8d296..000000000 --- a/src/core/setup/playwright.ts +++ /dev/null @@ -1,22 +0,0 @@ -import type { TestHooks } from '../types' - -const stubs: Array = ['clearLine', 'cursorTo'] - -export default async function setupPlaywright (hooks: TestHooks) { - const { test } = await import('@playwright/test') - for (const stub of stubs) { - try { - // Can be removed after https://github.com/microsoft/playwright/pull/29865 - // @ts-expect-error assigning to read-only property - process.stdout[stub] ||= () => {} - } catch { - // noop - } - } - test.beforeAll(hooks.setup) - test.beforeEach(hooks.beforeEach) - - test.afterEach(hooks.afterEach) - test.afterAll(hooks.afterAll) -} - diff --git a/src/core/types.ts b/src/core/types.ts index 04f57639a..1114b3663 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -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