test: make installation tests pass

This commit is contained in:
Max Schmitt 2024-12-19 18:55:37 +01:00
parent c626270c6a
commit 1c6a9a12bf
7 changed files with 32 additions and 24 deletions

View file

@ -103,8 +103,6 @@ function checkBrowsersToInstall(args: string[], options: { noShell?: boolean, on
executables.push(executable);
if (executable?.browserName === 'chromium')
executables.push(registry.findExecutable('ffmpeg')!);
if (process.platform === 'win32')
executables.push(registry.findExecutable('winldd')!);
};
for (const arg of args) {
@ -118,6 +116,9 @@ function checkBrowsersToInstall(args: string[], options: { noShell?: boolean, on
}
}
if (process.platform === 'win32')
executables.push(registry.findExecutable('winldd')!);
if (faultyArguments.length)
throw new Error(`Invalid installation targets: ${faultyArguments.map(name => `'${name}'`).join(', ')}. Expecting one of: ${suggestedBrowsersToInstall()}`);
return executables;

View file

@ -1315,6 +1315,8 @@ export async function installBrowsersForNpmInstall(browsers: string[]) {
return false;
}
const executables: Executable[] = [];
if (process.platform === 'win32')
executables.push(registry.findExecutable('winldd')!);
for (const browserName of browsers) {
const executable = registry.findExecutable(browserName);
if (!executable || executable.installType === 'none')

View file

@ -31,22 +31,22 @@ export const TMP_WORKSPACES = path.join(os.platform() === 'darwin' ? '/tmp' : os
const debug = debugLogger('itest');
const expect = _expect.extend({
toHaveLoggedSoftwareDownload(received: any, browsers: ('chromium' | 'chromium-headless-shell' | 'firefox' | 'webkit' | 'ffmpeg')[]) {
toHaveLoggedSoftwareDownload(received: string, browsers: ('chromium' | 'chromium-headless-shell' | 'firefox' | 'webkit' | 'winldd' |'ffmpeg')[]) {
if (typeof received !== 'string')
throw new Error(`Expected argument to be a string.`);
const downloaded = new Set();
let index = 0;
while (true) {
const match = received.substring(index).match(/(chromium|chromium headless shell|firefox|webkit|ffmpeg)[\s\d\.]+\(?playwright build v\d+\)? downloaded/im);
const match = received.substring(index).match(/(chromium|chromium headless shell|firefox|webkit|winldd|ffmpeg)[\s\d\.]+\(?playwright build v\d+\)? downloaded/im);
if (!match)
break;
downloaded.add(match[1].replace(/\s/g, '-').toLowerCase());
index += match.index + 1;
}
const expected = browsers;
if (expected.length === downloaded.size && expected.every(browser => downloaded.has(browser))) {
const expected = new Set(browsers);
if (expected.size === downloaded.size && [...expected].every(browser => downloaded.has(browser))) {
return {
pass: true,
message: () => 'Expected not to download browsers, but did.'

View file

@ -37,12 +37,14 @@ const parsedDownloads = (rawLogs: string) => {
test.use({ isolateBrowsers: true });
const extraInstalledSoftware = process.platform === 'win32' ? ['winldd' as const] : [];
for (const cdn of CDNS) {
test(`playwright cdn failover should work (${cdn})`, async ({ exec, checkInstalledSoftwareOnDisk }) => {
await exec('npm i playwright');
const result = await exec('npx playwright install', { env: { PW_TEST_CDN_THAT_SHOULD_WORK: cdn, DEBUG: 'pw:install' } });
expect(result).toHaveLoggedSoftwareDownload(['chromium', 'chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit']);
await checkInstalledSoftwareOnDisk(['chromium', 'chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit']);
expect(result).toHaveLoggedSoftwareDownload(['chromium', 'chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit', ...extraInstalledSoftware]);
await checkInstalledSoftwareOnDisk((['chromium', 'chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit', ...extraInstalledSoftware]));
const dls = parsedDownloads(result);
for (const software of ['chromium', 'ffmpeg', 'firefox', 'webkit'])
expect(dls).toContainEqual({ status: 200, name: software, url: expect.stringContaining(cdn) });

View file

@ -19,19 +19,21 @@ import path from 'path';
test.use({ isolateBrowsers: true });
const extraInstalledSoftware = process.platform === 'win32' ? ['winldd' as const] : [];
test('install command should work', async ({ exec, checkInstalledSoftwareOnDisk }) => {
await exec('npm i playwright');
await test.step('playwright install chromium', async () => {
const result = await exec('npx playwright install chromium');
expect(result).toHaveLoggedSoftwareDownload(['chromium', 'chromium-headless-shell', 'ffmpeg']);
await checkInstalledSoftwareOnDisk(['chromium', 'chromium-headless-shell', 'ffmpeg']);
expect(result).toHaveLoggedSoftwareDownload(['chromium', 'chromium-headless-shell', 'ffmpeg', ...extraInstalledSoftware]);
await checkInstalledSoftwareOnDisk(['chromium', 'chromium-headless-shell', 'ffmpeg', ...extraInstalledSoftware]);
});
await test.step('playwright install', async () => {
const result = await exec('npx playwright install');
expect(result).toHaveLoggedSoftwareDownload(['firefox', 'webkit']);
await checkInstalledSoftwareOnDisk(['chromium', 'chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit']);
await checkInstalledSoftwareOnDisk(['chromium', 'chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit', ...extraInstalledSoftware]);
});
await exec('node sanity.js playwright', { env: { PLAYWRIGHT_BROWSERS_PATH: '0' } });
@ -51,9 +53,9 @@ test('install command should work', async ({ exec, checkInstalledSoftwareOnDisk
test('should be able to remove browsers', async ({ exec, checkInstalledSoftwareOnDisk }) => {
await exec('npm i playwright');
await exec('npx playwright install chromium');
await checkInstalledSoftwareOnDisk(['chromium', 'chromium-headless-shell', 'ffmpeg']);
await checkInstalledSoftwareOnDisk(['chromium', 'chromium-headless-shell', 'ffmpeg', ...extraInstalledSoftware]);
await exec('npx playwright uninstall');
await checkInstalledSoftwareOnDisk([]);
await checkInstalledSoftwareOnDisk([...extraInstalledSoftware]);
});
test('should print the right install command without browsers', async ({ exec }) => {

View file

@ -18,12 +18,14 @@ import { test, expect } from './npmTest';
test.use({ isolateBrowsers: true });
const extraInstalledSoftware = process.platform === 'win32' ? ['winldd' as const] : [];
for (const browser of ['chromium', 'firefox', 'webkit']) {
test(`playwright-${browser} should work`, async ({ exec, checkInstalledSoftwareOnDisk }) => {
const pkg = `playwright-${browser}`;
const result = await exec('npm i --foreground-scripts', pkg);
const browserName = pkg.split('-')[1];
const expectedSoftware = [browserName];
const expectedSoftware = [browserName, ...extraInstalledSoftware];
if (browserName === 'chromium')
expectedSoftware.push('chromium-headless-shell', 'ffmpeg');
expect(result).toHaveLoggedSoftwareDownload(expectedSoftware as any);
@ -37,7 +39,7 @@ for (const browser of ['chromium', 'firefox', 'webkit']) {
for (const browser of ['chromium', 'firefox', 'webkit']) {
test(`@playwright/browser-${browser} should work`, async ({ exec, checkInstalledSoftwareOnDisk }) => {
const pkg = `@playwright/browser-${browser}`;
const expectedSoftware = [browser];
const expectedSoftware = [browser, ...extraInstalledSoftware];
if (browser === 'chromium')
expectedSoftware.push('chromium-headless-shell', 'ffmpeg');
@ -69,8 +71,8 @@ test(`playwright should work`, async ({ exec, checkInstalledSoftwareOnDisk }) =>
await checkInstalledSoftwareOnDisk([]);
const result2 = await exec('npx playwright install');
expect(result2).toHaveLoggedSoftwareDownload(['chromium', 'chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit']);
await checkInstalledSoftwareOnDisk(['chromium', 'chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit']);
expect(result2).toHaveLoggedSoftwareDownload(['chromium', 'chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit', ...extraInstalledSoftware]);
await checkInstalledSoftwareOnDisk(['chromium', 'chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit', ...extraInstalledSoftware]);
await exec('node sanity.js playwright chromium firefox webkit');
await exec('node esm-playwright.mjs');
@ -81,8 +83,8 @@ test(`playwright should work with chromium --no-shell`, async ({ exec, checkInst
expect(result1).toHaveLoggedSoftwareDownload([]);
await checkInstalledSoftwareOnDisk([]);
const result2 = await exec('npx playwright install chromium --no-shell');
expect(result2).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg']);
await checkInstalledSoftwareOnDisk(['chromium', 'ffmpeg']);
expect(result2).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg', ...extraInstalledSoftware]);
await checkInstalledSoftwareOnDisk(['chromium', 'ffmpeg', ...extraInstalledSoftware]);
});
test(`playwright should work with chromium --only-shell`, async ({ exec, checkInstalledSoftwareOnDisk }) => {
@ -90,8 +92,8 @@ test(`playwright should work with chromium --only-shell`, async ({ exec, checkIn
expect(result1).toHaveLoggedSoftwareDownload([]);
await checkInstalledSoftwareOnDisk([]);
const result2 = await exec('npx playwright install --only-shell');
expect(result2).toHaveLoggedSoftwareDownload(['chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit']);
await checkInstalledSoftwareOnDisk(['chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit']);
expect(result2).toHaveLoggedSoftwareDownload(['chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit', ...extraInstalledSoftware]);
await checkInstalledSoftwareOnDisk(['chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit', ...extraInstalledSoftware]);
});
test('@playwright/test should work', async ({ exec, checkInstalledSoftwareOnDisk }) => {
@ -102,8 +104,8 @@ test('@playwright/test should work', async ({ exec, checkInstalledSoftwareOnDisk
await exec('npx playwright test -c . sample.spec.js', { expectToExitWithError: true, message: 'should not be able to run tests without installing browsers' });
const result2 = await exec('npx playwright install');
expect(result2).toHaveLoggedSoftwareDownload(['chromium', 'chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit']);
await checkInstalledSoftwareOnDisk(['chromium', 'chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit']);
expect(result2).toHaveLoggedSoftwareDownload(['chromium', 'chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit', ...extraInstalledSoftware]);
await checkInstalledSoftwareOnDisk(['chromium', 'chromium-headless-shell', 'ffmpeg', 'firefox', 'webkit', ...extraInstalledSoftware]);
await exec('node sanity.js @playwright/test chromium firefox webkit');
await exec('node', 'esm-playwright-test.mjs');

View file

@ -26,7 +26,6 @@ function patchPackageJsonForPreReleaseIfNeeded(tmpWorkspace: string) {
// Workaround per https://stackoverflow.com/questions/71479750/npm-install-pre-release-versions-for-peer-dependency.
const pkg = JSON.parse(fs.readFileSync(path.resolve(tmpWorkspace, 'package.json'), 'utf-8'));
if (pkg.dependencies['@playwright/test'].match(/\d+\.\d+-\w+/)) {
console.log(`Setting overrides in package.json to make pre-release version of peer dependency work.`);
pkg.overrides = { '@playwright/test': '$@playwright/test' };
fs.writeFileSync(path.resolve(tmpWorkspace, 'package.json'), JSON.stringify(pkg, null, 2));
}