From c6ca57b3b8a128a4056cf2200993450e326ab0b6 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Wed, 11 Dec 2024 21:31:52 -0800 Subject: [PATCH] fix it on windows --- ...playwright-cli-install-should-work.spec.ts | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/tests/installation/playwright-cli-install-should-work.spec.ts b/tests/installation/playwright-cli-install-should-work.spec.ts index dfb2e18a9f..d1a8bd3d04 100755 --- a/tests/installation/playwright-cli-install-should-work.spec.ts +++ b/tests/installation/playwright-cli-install-should-work.spec.ts @@ -14,6 +14,7 @@ * limitations under the License. */ import { test, expect } from './npmTest'; +import { chromium } from '@playwright/test'; import path from 'path'; test.use({ isolateBrowsers: true }); @@ -96,39 +97,44 @@ test('install playwright-chromium should work', async ({ exec, installedSoftware await exec('node sanity.js playwright-chromium chromium'); }); -test('should print error if recording video without ffmpeg', async ({ exec }) => { +test('should print error if recording video without ffmpeg', async ({ exec, writeFiles }) => { await exec('npm i playwright'); + await writeFiles({ + 'launch.js': ` + const playwright = require('playwright'); + (async () => { + const browser = await playwright.chromium.launch({ executablePath: ${JSON.stringify(chromium.executablePath())} }); + try { + const context = await browser.newContext({ recordVideo: { dir: 'videos' } }); + const page = await context.newPage(); + } finally { + await browser.close(); + } + })().catch(e => { + console.error(e); + process.exit(1); + }); + `, + 'launchPersistentContext.js': ` + const playwright = require('playwright'); + process.on('unhandledRejection', (e) => console.error('unhandledRejection', e)); + (async () => { + const context = await playwright.chromium.launchPersistentContext('', { executablePath: ${JSON.stringify(chromium.executablePath())}, recordVideo: { dir: 'videos' } }); + })().catch(e => { + console.error(e); + process.exit(1); + }); + `, + }); + await test.step('BrowserType.launch', async () => { - const result = await exec('node', '-e', `" - const playwright = require('playwright'); - (async () => { - const browser = await playwright.chromium.launch({ channel: 'chrome' }); - try { - const context = await browser.newContext({ recordVideo: { dir: 'videos' } }); - const page = await context.newPage(); - } finally { - await browser.close(); - } - })().catch(e => { - console.error(e); - process.exit(1); - }); - "`, { expectToExitWithError: true }); + const result = await exec('node', 'launch.js', { expectToExitWithError: true }); expect(result).toContain(`browserContext.newPage: Executable doesn't exist at`); }); await test.step('BrowserType.launchPersistentContext', async () => { - const result = await exec('node', '-e', `" - const playwright = require('playwright'); - process.on('unhandledRejection', (e) => console.error('unhandledRejection', e)); - (async () => { - const context = await playwright.chromium.launchPersistentContext('', { channel: 'chrome', recordVideo: { dir: 'videos' } }); - })().catch(e => { - console.error(e); - process.exit(1); - }); - "`, { expectToExitWithError: true }); + const result = await exec('node', 'launchPersistentContext.js', { expectToExitWithError: true }); expect(result).not.toContain('unhandledRejection'); expect(result).toContain(`browserType.launchPersistentContext: Executable doesn't exist at`); });