test: speed up installation tests by not isolating browser unless required (#27370)

This commit is contained in:
Dmitry Gozman 2023-10-02 11:26:08 -07:00 committed by GitHub
parent d1ae0ab94f
commit dfc75a1e1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 225 additions and 555 deletions

View file

@ -234,7 +234,7 @@ jobs:
env: env:
DEBUG: pw:install DEBUG: pw:install
- run: npm run build - run: npm run build
- run: npx playwright install-deps - run: npx playwright install --with-deps
- run: npm install -g yarn@1 - run: npm install -g yarn@1
- run: npm install -g pnpm@8 - run: npm install -g pnpm@8
- run: npm run itest - run: npm run itest

View file

@ -136,7 +136,7 @@ jobs:
env: env:
DEBUG: pw:install DEBUG: pw:install
- run: npm run build - run: npm run build
- run: npx playwright install-deps - run: npx playwright install --with-deps
- run: npm install -g yarn@1 - run: npm install -g yarn@1
- run: npm install -g pnpm@8 - run: npm install -g pnpm@8
- run: npm run itest - run: npm run itest

View file

@ -1,25 +0,0 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test } from './npmTest';
test('android types', async ({ exec, tsc, writeFiles }) => {
await exec('npm i --foreground-scripts playwright');
await writeFiles({
'test.ts':
`import { AndroidDevice, _android, AndroidWebView, Page } from 'playwright';`,
});
await tsc('test.ts');
});

View file

@ -20,7 +20,7 @@ import { test } from './npmTest';
test('connect to selenium', async ({ exec, tmpWorkspace }, testInfo) => { test('connect to selenium', async ({ exec, tmpWorkspace }, testInfo) => {
test.skip(os.platform() !== 'linux'); test.skip(os.platform() !== 'linux');
await exec('npm i --foreground-scripts playwright-core'); await exec('npm i playwright-core');
await exec(`node download-chromedriver.js ${tmpWorkspace}`); await exec(`node download-chromedriver.js ${tmpWorkspace}`);
const seleniumPath = path.join(tmpWorkspace, 'selenium'); const seleniumPath = path.join(tmpWorkspace, 'selenium');
await exec(`node download-selenium.js ${seleniumPath}`); await exec(`node download-selenium.js ${seleniumPath}`);

View file

@ -16,7 +16,7 @@
import { test, expect } from './npmTest'; import { test, expect } from './npmTest';
test('driver should work', async ({ exec }) => { test('driver should work', async ({ exec }) => {
await exec('npm i --foreground-scripts playwright'); await exec('npm i playwright');
await exec('npx playwright install'); await exec('npx playwright install');
await exec('node driver-client.js'); await exec('node driver-client.js');
}); });
@ -24,7 +24,7 @@ test('driver should work', async ({ exec }) => {
test('driver should ignore SIGINT', async ({ exec }) => { test('driver should ignore SIGINT', async ({ exec }) => {
test.skip(process.platform === 'win32', 'Only relevant for POSIX'); test.skip(process.platform === 'win32', 'Only relevant for POSIX');
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright-python/issues/1843' }); test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright-python/issues/1843' });
await exec('npm i --foreground-scripts playwright'); await exec('npm i playwright');
await exec('npx playwright install chromium'); await exec('npx playwright install chromium');
const output = await exec('node driver-client-sigint.js'); const output = await exec('node driver-client-sigint.js');
const lines = output.split('\n').filter(l => l.trim()); const lines = output.split('\n').filter(l => l.trim());

View file

@ -1,25 +0,0 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test } from './npmTest';
test('electron types', async ({ exec, tsc, writeFiles }) => {
await exec('npm i --foreground-scripts playwright electron@12');
await writeFiles({
'test.ts':
`import { Page, _electron, ElectronApplication, Electron } from 'playwright';`
});
await tsc('test.ts');
});

View file

@ -14,22 +14,13 @@
* limitations under the License. * limitations under the License.
*/ */
import http from 'http';
import https from 'https';
import url from 'url';
import type net from 'net';
import debugLogger from 'debug';
import path from 'path'; import path from 'path';
import fs from 'fs'; import fs from 'fs';
import { spawnAsync } from '../../packages/playwright-core/lib/utils/spawnAsync'; import { spawnAsync } from '../../packages/playwright-core/lib/utils/spawnAsync';
import { rimraf } from 'playwright-core/lib/utilsBundle'; import { rimraf } from 'playwright-core/lib/utilsBundle';
import { TMP_WORKSPACES } from './npmTest'; import { TMP_WORKSPACES } from './npmTest';
import { createHttpServer } from '../../packages/playwright-core/lib/utils/network';
import { calculateSha1 } from '../../packages/playwright-core/lib/utils/crypto';
const PACKAGE_BUILDER_SCRIPT = path.join(__dirname, '..', '..', 'utils', 'pack_package.js'); const PACKAGE_BUILDER_SCRIPT = path.join(__dirname, '..', '..', 'utils', 'pack_package.js');
const BROWSERS_CACHE_DIR = path.join(TMP_WORKSPACES, 'npm-test-browsers-cache');
const debug = debugLogger('itest');
async function globalSetup() { async function globalSetup() {
await rimraf(TMP_WORKSPACES); await rimraf(TMP_WORKSPACES);
@ -83,61 +74,6 @@ async function globalSetup() {
await fs.promises.writeFile(path.join(__dirname, '.registry.json'), JSON.stringify(Object.fromEntries(builds))); await fs.promises.writeFile(path.join(__dirname, '.registry.json'), JSON.stringify(Object.fromEntries(builds)));
} }
const cdnProxyServer = createHttpServer(async (request: http.IncomingMessage, response: http.ServerResponse) => {
const requestedPath = url.parse(request.url!).path;
const cachedPath = path.join(BROWSERS_CACHE_DIR, calculateSha1(requestedPath));
const cachedPathMetaInfo = cachedPath + '.metainfo';
if (!fs.existsSync(cachedPath)) {
const realUrl = 'https://playwright.azureedge.net' + requestedPath;
debug(`[cdn proxy] downloading ${realUrl} headers=${JSON.stringify(request.headers)}`);
const headers = { ...request.headers };
delete headers['host'];
const options = {
...url.parse(realUrl),
method: request.method,
headers,
};
const factory = options.protocol === 'https:' ? https : http;
let doneCallback = () => {};
const donePromise = new Promise<void>(f => doneCallback = () => {
debug(`[cdn proxy] downloading ${realUrl} finished`);
f();
});
const realRequest = factory.request(options, (realResponse: http.IncomingMessage) => {
const metaInfo = {
statusCode: realResponse.statusCode,
statusMessage: realResponse.statusMessage || '',
headers: realResponse.headers || {},
};
debug(`[cdn proxy] downloading ${realUrl} statusCode=${realResponse.statusCode}`);
fs.mkdirSync(path.dirname(cachedPathMetaInfo), { recursive: true });
fs.writeFileSync(cachedPathMetaInfo, JSON.stringify(metaInfo));
realResponse.pipe(fs.createWriteStream(cachedPath, { highWaterMark: 1024 * 1024 })).on('close', doneCallback).on('finish', doneCallback).on('error', doneCallback);
});
request.pipe(realRequest);
await donePromise;
}
const metaInfo = JSON.parse(fs.readFileSync(cachedPathMetaInfo, 'utf-8'));
response.writeHead(metaInfo.statusCode, metaInfo.statusMessage, metaInfo.headers);
const done = () => {
debug(`[cdn proxy] serving ${request.url!} finished`);
response.end();
};
fs.createReadStream(cachedPath, { highWaterMark: 1024 * 1024 }).pipe(response).on('close', done).on('error', done);
debug(`[cdn proxy] serving ${request.url!} from cached ${cachedPath}`);
});
cdnProxyServer.listen(0);
await new Promise(f => cdnProxyServer.once('listening', f));
process.env.CDN_PROXY_HOST = `http://127.0.0.1:${(cdnProxyServer.address() as net.AddressInfo).port}`;
console.log('Stared CDN proxy at ' + process.env.CDN_PROXY_HOST);
return async () => {
await new Promise(f => cdnProxyServer.close(f));
};
} }
export default globalSetup; export default globalSetup;

View file

@ -61,15 +61,15 @@ type ExecOptions = SpawnOptions & { message?: string, expectToExitWithError?: bo
type ArgsOrOptions = [] | [...string[]] | [...string[], ExecOptions] | [ExecOptions]; type ArgsOrOptions = [] | [...string[]] | [...string[], ExecOptions] | [ExecOptions];
type NPMTestOptions = { type NPMTestOptions = {
useRealCDN: boolean; isolateBrowsers: boolean;
allowGlobalInstall: boolean;
}; };
type NPMTestFixtures = { type NPMTestFixtures = {
_auto: void; _auto: void;
_browsersPath: string; _browsersPath: string;
tmpWorkspace: string; tmpWorkspace: string;
installedSoftwareOnDisk: (registryPath?: string) => Promise<string[]>; installedSoftwareOnDisk: () => Promise<string[]>;
writeConfig: (allowGlobal: boolean) => Promise<void>;
writeFiles: (nameToContents: Record<string, string>) => Promise<void>; writeFiles: (nameToContents: Record<string, string>) => Promise<void>;
exec: (cmd: string, ...argsAndOrOptions: ArgsOrOptions) => Promise<string>; exec: (cmd: string, ...argsAndOrOptions: ArgsOrOptions) => Promise<string>;
tsc: (args: string) => Promise<string>; tsc: (args: string) => Promise<string>;
@ -79,9 +79,10 @@ type NPMTestFixtures = {
export const test = _test export const test = _test
.extend<CommonFixtures, CommonWorkerFixtures>(commonFixtures) .extend<CommonFixtures, CommonWorkerFixtures>(commonFixtures)
.extend<NPMTestFixtures & NPMTestOptions>({ .extend<NPMTestFixtures & NPMTestOptions>({
useRealCDN: [false, { option: true }], isolateBrowsers: [false, { option: true }],
allowGlobalInstall: [false, { option: true }],
_browsersPath: async ({ tmpWorkspace }, use) => use(path.join(tmpWorkspace, 'browsers')), _browsersPath: async ({ tmpWorkspace }, use) => use(path.join(tmpWorkspace, 'browsers')),
_auto: [async ({ tmpWorkspace, exec, _browsersPath, writeConfig }, use) => { _auto: [async ({ tmpWorkspace, exec, _browsersPath, registry, allowGlobalInstall }, use, testInfo) => {
await exec('npm init -y'); await exec('npm init -y');
const sourceDir = path.join(__dirname, 'fixture-scripts'); const sourceDir = path.join(__dirname, 'fixture-scripts');
const contents = await fs.promises.readdir(sourceDir); const contents = await fs.promises.readdir(sourceDir);
@ -93,7 +94,20 @@ export const test = _test
packageJSON.pnpm = { overrides: prefixed }; packageJSON.pnpm = { overrides: prefixed };
await fs.promises.writeFile(path.join(tmpWorkspace, 'package.json'), JSON.stringify(packageJSON, null, 2)); await fs.promises.writeFile(path.join(tmpWorkspace, 'package.json'), JSON.stringify(packageJSON, null, 2));
await writeConfig(false); const yarnLines = [
`registry "${registry.url()}/"`,
`cache "${testInfo.outputPath('npm_cache')}"`,
];
const npmLines = [
`registry = ${registry.url()}/`,
`cache = ${testInfo.outputPath('npm_cache')}`,
];
if (!allowGlobalInstall) {
yarnLines.push(`prefix "${testInfo.outputPath('npm_global')}"`);
npmLines.push(`prefix = ${testInfo.outputPath('npm_global')}`);
}
await fs.promises.writeFile(path.join(tmpWorkspace, '.yarnrc'), yarnLines.join('\n'), 'utf-8');
await fs.promises.writeFile(path.join(tmpWorkspace, '.npmrc'), npmLines.join('\n'), 'utf-8');
await use(); await use();
if (test.info().status === test.info().expectedStatus) { if (test.info().status === test.info().expectedStatus) {
@ -124,28 +138,12 @@ export const test = _test
await use(registry); await use(registry);
await registry.shutdown(); await registry.shutdown();
}, },
writeConfig: async ({ tmpWorkspace, registry }, use, testInfo) => { installedSoftwareOnDisk: async ({ isolateBrowsers, _browsersPath }, use) => {
await use(async (allowGlobal: boolean) => { if (!isolateBrowsers)
const yarnLines = [ throw new Error(`Test that checks browser installation must set "isolateBrowsers" to true`);
`registry "${registry.url()}/"`, await use(async () => fs.promises.readdir(_browsersPath).catch(() => []).then(files => files.map(f => f.split('-')[0]).filter(f => !f.startsWith('.'))));
`cache "${testInfo.outputPath('npm_cache')}"`,
];
const npmLines = [
`registry = ${registry.url()}/`,
`cache = ${testInfo.outputPath('npm_cache')}`,
];
if (!allowGlobal) {
yarnLines.push(`prefix "${testInfo.outputPath('npm_global')}"`);
npmLines.push(`prefix = ${testInfo.outputPath('npm_global')}`);
}
await fs.promises.writeFile(path.join(tmpWorkspace, '.yarnrc'), yarnLines.join('\n'), 'utf-8');
await fs.promises.writeFile(path.join(tmpWorkspace, '.npmrc'), npmLines.join('\n'), 'utf-8');
});
}, },
installedSoftwareOnDisk: async ({ _browsersPath }, use) => { exec: async ({ tmpWorkspace, _browsersPath, isolateBrowsers }, use, testInfo) => {
await use(async (registryPath?: string) => fs.promises.readdir(registryPath || _browsersPath).catch(() => []).then(files => files.map(f => f.split('-')[0]).filter(f => !f.startsWith('.'))));
},
exec: async ({ useRealCDN, tmpWorkspace, _browsersPath }, use, testInfo) => {
await use(async (cmd: string, ...argsAndOrOptions: [] | [...string[]] | [...string[], ExecOptions] | [ExecOptions]) => { await use(async (cmd: string, ...argsAndOrOptions: [] | [...string[]] | [...string[], ExecOptions] | [ExecOptions]) => {
let args: string[] = []; let args: string[] = [];
let options: ExecOptions = {}; let options: ExecOptions = {};
@ -164,8 +162,7 @@ export const test = _test
'PATH': process.env.PATH, 'PATH': process.env.PATH,
'DISPLAY': process.env.DISPLAY, 'DISPLAY': process.env.DISPLAY,
'XAUTHORITY': process.env.XAUTHORITY, 'XAUTHORITY': process.env.XAUTHORITY,
'PLAYWRIGHT_BROWSERS_PATH': _browsersPath, ...(isolateBrowsers ? { PLAYWRIGHT_BROWSERS_PATH: _browsersPath } : {}),
...(useRealCDN ? {} : { PLAYWRIGHT_DOWNLOAD_HOST: process.env.CDN_PROXY_HOST }),
...options.env, ...options.env,
} }
}); });
@ -198,7 +195,7 @@ export const test = _test
}); });
}, },
tsc: async ({ exec }, use) => { tsc: async ({ exec }, use) => {
await exec('npm i --foreground-scripts typescript@5.2.2 @types/node@16'); await exec('npm i typescript@5.2.2 @types/node@16');
await use((args: string) => exec('npx', 'tsc', args, { shell: process.platform === 'win32' })); await use((args: string) => exec('npx', 'tsc', args, { shell: process.platform === 'win32' }));
}, },
}); });

View file

@ -1,24 +0,0 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test, expect } from './npmTest';
test('npx playwright --help should not download browsers', async ({ writeConfig, exec, installedSoftwareOnDisk }) => {
await writeConfig(true);
const result = await exec('npx playwright --help');
expect(result).toHaveLoggedSoftwareDownload([]);
expect(await installedSoftwareOnDisk()).toEqual([]);
expect(result).not.toContain(`To avoid unexpected behavior, please install your dependencies first`);
});

View file

@ -1,24 +0,0 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test, expect } from './npmTest';
test('npx playwright codegen', async ({ writeConfig, exec, installedSoftwareOnDisk }) => {
await writeConfig(true);
const stdio = await exec('npx playwright codegen', { expectToExitWithError: true });
expect(stdio).toHaveLoggedSoftwareDownload([]);
expect(await installedSoftwareOnDisk()).toEqual([]);
expect(stdio).toContain(`Please run the following command to download new browsers`);
});

View file

@ -15,10 +15,25 @@
*/ */
import { test, expect } from './npmTest'; import { test, expect } from './npmTest';
test('npx playwright install global', async ({ writeConfig, exec, installedSoftwareOnDisk }) => { test.use({ isolateBrowsers: true, allowGlobalInstall: true });
test('npx playwright --help should not download browsers', async ({ exec, installedSoftwareOnDisk }) => {
const result = await exec('npx playwright --help');
expect(result).toHaveLoggedSoftwareDownload([]);
expect(await installedSoftwareOnDisk()).toEqual([]);
expect(result).not.toContain(`To avoid unexpected behavior, please install your dependencies first`);
});
test('npx playwright codegen', async ({ exec, installedSoftwareOnDisk }) => {
const stdio = await exec('npx playwright codegen', { expectToExitWithError: true });
expect(stdio).toHaveLoggedSoftwareDownload([]);
expect(await installedSoftwareOnDisk()).toEqual([]);
expect(stdio).toContain(`Please run the following command to download new browsers`);
});
test('npx playwright install global', async ({ exec, installedSoftwareOnDisk }) => {
test.skip(process.platform === 'win32', 'isLikelyNpxGlobal() does not work in this setup on our bots'); test.skip(process.platform === 'win32', 'isLikelyNpxGlobal() does not work in this setup on our bots');
await writeConfig(true);
const result = await exec('npx playwright install'); const result = await exec('npx playwright install');
expect(result).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg', 'firefox', 'webkit']); expect(result).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg', 'firefox', 'webkit']);
expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']); expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']);

View file

@ -1,39 +0,0 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import http from 'http';
import type { AddressInfo } from 'net';
import { test, expect } from './npmTest';
test.use({ useRealCDN: true });
test(`playwright cdn should race with a timeout`, async ({ exec }) => {
const server = http.createServer(() => {});
await new Promise<void>(resolve => server.listen(0, resolve));
try {
await exec('npm i --foreground-scripts playwright');
const result = await exec('npx playwright install', {
env: {
PLAYWRIGHT_DOWNLOAD_HOST: `http://127.0.0.1:${(server.address() as AddressInfo).port}`,
DEBUG: 'pw:install',
PLAYWRIGHT_DOWNLOAD_CONNECTION_TIMEOUT: '1000',
},
expectToExitWithError: true
});
expect(result).toContain(`timed out after 1000ms`);
} finally {
await new Promise(resolve => server.close(resolve));
}
});

View file

@ -14,6 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
import { test, expect } from './npmTest'; import { test, expect } from './npmTest';
import http from 'http';
import type { AddressInfo } from 'net';
const CDNS = [ const CDNS = [
'https://playwright.azureedge.net', 'https://playwright.azureedge.net',
@ -32,11 +34,11 @@ const parsedDownloads = (rawLogs: string) => {
return out; return out;
}; };
test.use({ useRealCDN: true }); test.use({ isolateBrowsers: true });
for (const cdn of CDNS) { for (const cdn of CDNS) {
test(`playwright cdn failover should work (${cdn})`, async ({ exec, installedSoftwareOnDisk }) => { test(`playwright cdn failover should work (${cdn})`, async ({ exec, installedSoftwareOnDisk }) => {
await exec('npm i --foreground-scripts playwright'); await exec('npm i playwright');
const result = await exec('npx playwright install', { env: { PW_TEST_CDN_THAT_SHOULD_WORK: cdn, DEBUG: 'pw:install' } }); const result = await exec('npx playwright install', { env: { PW_TEST_CDN_THAT_SHOULD_WORK: cdn, DEBUG: 'pw:install' } });
expect(result).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg', 'firefox', 'webkit']); expect(result).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg', 'firefox', 'webkit']);
expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']); expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']);
@ -47,3 +49,22 @@ for (const cdn of CDNS) {
await exec('node esm-playwright.mjs'); await exec('node esm-playwright.mjs');
}); });
} }
test(`playwright cdn should race with a timeout`, async ({ exec }) => {
const server = http.createServer(() => {});
await new Promise<void>(resolve => server.listen(0, resolve));
try {
await exec('npm i playwright');
const result = await exec('npx playwright install', {
env: {
PLAYWRIGHT_DOWNLOAD_HOST: `http://127.0.0.1:${(server.address() as AddressInfo).port}`,
DEBUG: 'pw:install',
PLAYWRIGHT_DOWNLOAD_CONNECTION_TIMEOUT: '1000',
},
expectToExitWithError: true
});
expect(result).toContain(`timed out after 1000ms`);
} finally {
await new Promise(resolve => server.close(resolve));
}
});

View file

@ -1,39 +0,0 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test, expect } from './npmTest';
test('codegen should print the right install command without browsers', async ({ exec }) => {
await exec('npm i --foreground-scripts playwright');
const pwLangName2InstallCommand = {
'java': 'mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install"',
'python': 'playwright install',
'csharp': 'pwsh bin/Debug/netX/playwright.ps1 install',
'': 'npx playwright install',
};
for (const [langName, installCommand] of Object.entries(pwLangName2InstallCommand)) {
await test.step(`codegen should work for ${langName}`, async () => {
const result = await exec('npx playwright codegen', {
expectToExitWithError: true,
env: {
PW_LANG_NAME: langName,
}
});
expect(result).toContain(installCommand);
});
}
});

View file

@ -14,9 +14,12 @@
* limitations under the License. * limitations under the License.
*/ */
import { test, expect } from './npmTest'; import { test, expect } from './npmTest';
import path from 'path';
test.use({ isolateBrowsers: true });
test('install command should work', async ({ exec, installedSoftwareOnDisk }) => { test('install command should work', async ({ exec, installedSoftwareOnDisk }) => {
await exec('npm i --foreground-scripts playwright', { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } }); await exec('npm i playwright');
await test.step('playwright install chromium', async () => { await test.step('playwright install chromium', async () => {
const result = await exec('npx playwright install chromium'); const result = await exec('npx playwright install chromium');
@ -30,14 +33,59 @@ test('install command should work', async ({ exec, installedSoftwareOnDisk }) =>
expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']); expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']);
}); });
await exec('node sanity.js playwright', { env: { PLAYWRIGHT_BROWSERS_PATH: undefined } }); await exec('node sanity.js playwright', { env: { PLAYWRIGHT_BROWSERS_PATH: '0' } });
await exec('node sanity.js playwright chromium firefox webkit'); await exec('node sanity.js playwright chromium firefox webkit');
const packages = ['playwright-chromium', 'playwright-firefox', 'playwright-webkit', '@playwright/browser-chromium', '@playwright/browser-firefox', '@playwright/browser-webkit'];
for (const pkg of packages) {
await test.step(pkg, async () => {
const result = await exec(`npm i ${pkg}`);
expect(result).toHaveLoggedSoftwareDownload([]);
if (!pkg.includes('@playwright/browser-'))
await exec('node sanity.js', pkg, 'chromium firefox webkit');
});
}
}); });
test('should be able to remove browsers', async ({ exec, installedSoftwareOnDisk }) => { test('should be able to remove browsers', async ({ exec, installedSoftwareOnDisk }) => {
await exec('npm i --foreground-scripts playwright'); await exec('npm i playwright');
await exec('npx playwright install chromium'); await exec('npx playwright install chromium');
expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg']); expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg']);
await exec('npx playwright uninstall'); await exec('npx playwright uninstall');
expect(await installedSoftwareOnDisk()).toEqual([]); expect(await installedSoftwareOnDisk()).toEqual([]);
}); });
test('should print the right install command without browsers', async ({ exec }) => {
await exec('npm i playwright');
const pwLangName2InstallCommand = {
'java': 'mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install"',
'python': 'playwright install',
'csharp': 'pwsh bin/Debug/netX/playwright.ps1 install',
'': 'npx playwright install',
};
for (const [langName, installCommand] of Object.entries(pwLangName2InstallCommand)) {
await test.step(`codegen should work for ${langName}`, async () => {
const result = await exec('npx playwright codegen', {
expectToExitWithError: true,
env: {
PW_LANG_NAME: langName,
}
});
expect(result).toContain(installCommand);
});
}
});
test('subsequent installs works', async ({ exec }) => {
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/1651' });
await exec('npm i @playwright/browser-chromium');
// Note: the `npm install` would not actually crash, the error
// is merely logged to the console. To reproduce the error, we should make
// sure that script's install.js can be run subsequently without unhandled promise rejections.
// Note: the flag `--unhandled-rejections=strict` will force node to terminate in case
// of UnhandledPromiseRejection.
await exec('node --unhandled-rejections=strict', path.join('node_modules', '@playwright', 'browser-chromium', 'install.js'));
});

View file

@ -1,28 +0,0 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test } from './npmTest';
import fs from 'fs';
import path from 'path';
test('playwright cli screenshot should work', async ({ exec, tmpWorkspace }) => {
await exec('npm i --foreground-scripts playwright');
await exec('npx playwright install chromium');
await exec(path.join('node_modules', '.bin', 'playwright'), 'screenshot about:blank one.png');
await fs.promises.stat(path.join(tmpWorkspace, 'one.png'));
await exec('npx playwright screenshot about:blank two.png');
await fs.promises.stat(path.join(tmpWorkspace, 'two.png'));
});

View file

@ -14,9 +14,11 @@
* limitations under the License. * limitations under the License.
*/ */
import { test, expect } from './npmTest'; import { test, expect } from './npmTest';
import path from 'path';
import fs from 'fs';
test('codegen should work', async ({ exec }) => { test('cli should work', async ({ exec, tmpWorkspace }) => {
await exec('npm i --foreground-scripts playwright'); await exec('npm i playwright');
await exec('npx playwright install chromium'); await exec('npx playwright install chromium');
await test.step('codegen without arguments', async () => { await test.step('codegen without arguments', async () => {
@ -48,4 +50,12 @@ test('codegen should work', async ({ exec }) => {
}); });
expect(result).toContain(`browser.close`); expect(result).toContain(`browser.close`);
}); });
await test.step('screenshot', async () => {
await exec(path.join('node_modules', '.bin', 'playwright'), 'screenshot about:blank one.png');
await fs.promises.stat(path.join(tmpWorkspace, 'one.png'));
await exec('npx playwright screenshot about:blank two.png');
await fs.promises.stat(path.join(tmpWorkspace, 'two.png'));
});
}); });

View file

@ -1,24 +0,0 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test, expect } from './npmTest';
test(`playwright-core should work`, async ({ exec, installedSoftwareOnDisk }) => {
const result1 = await exec('npm i --foreground-scripts playwright-core');
expect(result1).toHaveLoggedSoftwareDownload([]);
expect(await installedSoftwareOnDisk()).toEqual([]);
const stdio = await exec('npx playwright-core', 'test', '-c', '.', { expectToExitWithError: true });
expect(stdio).toContain(`Please install @playwright/test package`);
});

View file

@ -15,7 +15,12 @@
*/ */
import { test } from './npmTest'; import { test } from './npmTest';
test('electron should work', async ({ exec }) => { test('electron should work', async ({ exec, tsc, writeFiles }) => {
await exec('npm i --foreground-scripts playwright electron@19.0.11'); await exec('npm i playwright electron@19.0.11');
await exec('node sanity-electron.js'); await exec('node sanity-electron.js');
await writeFiles({
'test.ts':
`import { Page, _electron, ElectronApplication, Electron } from 'playwright';`
});
await tsc('test.ts');
}); });

View file

@ -1,28 +0,0 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test, expect } from './npmTest';
test('global installation cross package', async ({ exec, installedSoftwareOnDisk }) => {
const packages = ['playwright-chromium', 'playwright-firefox', 'playwright-webkit'];
for (const pkg of packages)
await exec('npm i --foreground-scripts', pkg, { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
const result = await exec('npx playwright install');
expect(result).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg', 'firefox', 'webkit']);
expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']);
for (const pkg of packages)
await test.step(pkg, () => exec('node sanity.js', pkg, 'chromium firefox webkit'));
});

View file

@ -1,29 +0,0 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test, expect } from './npmTest';
test('global installation', async ({ exec, installedSoftwareOnDisk }) => {
const result1 = await exec('npm i --foreground-scripts playwright');
expect(result1).toHaveLoggedSoftwareDownload([]);
expect(await installedSoftwareOnDisk()).toEqual([]);
const result2 = await exec('npx playwright install');
expect(result2).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg', 'firefox', 'webkit']);
expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']);
await exec('node sanity.js playwright', { env: { PLAYWRIGHT_BROWSERS_PATH: undefined } });
await exec('node sanity.js playwright chromium firefox webkit');
});

View file

@ -1,28 +0,0 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test } from './npmTest';
import path from 'path';
test('subsequent installs works', async ({ exec }) => {
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/1651' });
await exec('npm i --foreground-scripts @playwright/browser-chromium');
// Note: the `npm install` would not actually crash, the error
// is merely logged to the console. To reproduce the error, we should make
// sure that script's install.js can be run subsequently without unhandled promise rejections.
// Note: the flag `--unhandled-rejections=strict` will force node to terminate in case
// of UnhandledPromiseRejection.
await exec('node --unhandled-rejections=strict', path.join('node_modules', '@playwright', 'browser-chromium', 'install.js'));
});

View file

@ -16,6 +16,8 @@
*/ */
import { test, expect } from './npmTest'; import { test, expect } from './npmTest';
test.use({ isolateBrowsers: true });
for (const browser of ['chromium', 'firefox', 'webkit']) { for (const browser of ['chromium', 'firefox', 'webkit']) {
test(`playwright-${browser} should work`, async ({ exec, installedSoftwareOnDisk }) => { test(`playwright-${browser} should work`, async ({ exec, installedSoftwareOnDisk }) => {
const pkg = `playwright-${browser}`; const pkg = `playwright-${browser}`;
@ -52,3 +54,46 @@ for (const browser of ['chromium', 'firefox', 'webkit']) {
await exec('node browser-only.js', pkg); await exec('node browser-only.js', pkg);
}); });
} }
test(`playwright-core should work`, async ({ exec, installedSoftwareOnDisk }) => {
const result1 = await exec('npm i --foreground-scripts playwright-core');
expect(result1).toHaveLoggedSoftwareDownload([]);
expect(await installedSoftwareOnDisk()).toEqual([]);
const stdio = await exec('npx playwright-core', 'test', '-c', '.', { expectToExitWithError: true });
expect(stdio).toContain(`Please install @playwright/test package`);
});
test(`playwright should work`, async ({ exec, installedSoftwareOnDisk }) => {
const result1 = await exec('npm i --foreground-scripts playwright');
expect(result1).toHaveLoggedSoftwareDownload([]);
expect(await installedSoftwareOnDisk()).toEqual([]);
const result2 = await exec('npx playwright install');
expect(result2).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg', 'firefox', 'webkit']);
expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']);
await exec('node sanity.js playwright chromium firefox webkit');
await exec('node esm-playwright.mjs');
});
test('@playwright/test should work', async ({ exec, installedSoftwareOnDisk }) => {
const result1 = await exec('npm i --foreground-scripts @playwright/test');
expect(result1).toHaveLoggedSoftwareDownload([]);
expect(await installedSoftwareOnDisk()).toEqual([]);
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', 'ffmpeg', 'firefox', 'webkit']);
expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']);
await exec('node sanity.js @playwright/test chromium firefox webkit');
await exec('node', 'esm-playwright-test.mjs');
const result3 = await exec('npx playwright test -c . --browser=all --reporter=list sample.spec.js');
expect(result3).toContain('3 passed');
const result4 = await exec('npx playwright test -c . failing.spec.js', { expectToExitWithError: true, env: { DEBUG: 'pw:api' } });
expect(result4).toContain('expect.toHaveText started');
expect(result4).toContain('failing.spec.js:5:38');
});

View file

@ -20,7 +20,7 @@ import path from 'path';
test('playwright should work with relative home path', async ({ exec, tmpWorkspace }) => { test('playwright should work with relative home path', async ({ exec, tmpWorkspace }) => {
await fs.promises.mkdir(path.join(tmpWorkspace, 'foo')); await fs.promises.mkdir(path.join(tmpWorkspace, 'foo'));
// Make sure that browsers path is resolved relative to the `npm install` call location. // Make sure that browsers path is resolved relative to the `npm install` call location.
await exec('npm i --foreground-scripts playwright', { cwd: path.join(tmpWorkspace, 'foo'), env: { PLAYWRIGHT_BROWSERS_PATH: path.join('..', 'relative') } }); await exec('npm i playwright', { cwd: path.join(tmpWorkspace, 'foo'), env: { PLAYWRIGHT_BROWSERS_PATH: path.join('..', 'relative') } });
await exec('npx playwright install', { cwd: path.join(tmpWorkspace, 'foo'), env: { PLAYWRIGHT_BROWSERS_PATH: path.join('..', 'relative') } }); await exec('npx playwright install', { cwd: path.join(tmpWorkspace, 'foo'), env: { PLAYWRIGHT_BROWSERS_PATH: path.join('..', 'relative') } });
await exec('node sanity.js playwright chromium firefox webkit', { env: { PLAYWRIGHT_BROWSERS_PATH: path.join('.', 'relative') } }); await exec('node sanity.js playwright chromium firefox webkit', { env: { PLAYWRIGHT_BROWSERS_PATH: path.join('.', 'relative') } });
}); });

View file

@ -20,7 +20,7 @@ test('playwright should work with relative home path', async ({ exec }) => {
test.skip(os.platform().startsWith('win')); test.skip(os.platform().startsWith('win'));
const env = { PLAYWRIGHT_BROWSERS_PATH: '0', HOME: '.' }; const env = { PLAYWRIGHT_BROWSERS_PATH: '0', HOME: '.' };
await exec('npm i --foreground-scripts playwright @playwright/browser-chromium @playwright/browser-webkit', { env }); await exec('npm i playwright @playwright/browser-chromium @playwright/browser-webkit', { env });
// Firefox does not work with relative HOME. // Firefox does not work with relative HOME.
await exec('node sanity.js playwright chromium webkit', { env }); await exec('node sanity.js playwright chromium webkit', { env });
}); });

View file

@ -1,31 +0,0 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test, expect } from './npmTest';
test.use({ useRealCDN: true });
test(`playwright should work`, async ({ exec, installedSoftwareOnDisk }) => {
const result1 = await exec('npm i --foreground-scripts playwright');
expect(result1).toHaveLoggedSoftwareDownload([]);
expect(await installedSoftwareOnDisk()).toEqual([]);
const result2 = await exec('npm i --foreground-scripts @playwright/browser-chromium @playwright/browser-firefox @playwright/browser-webkit');
expect(result2).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg', 'firefox', 'webkit']);
expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']);
await exec('node sanity.js playwright chromium firefox webkit');
await exec('node esm-playwright.mjs');
});

View file

@ -17,9 +17,7 @@ import { test } from './npmTest';
import path from 'path'; import path from 'path';
test('npm: @playwright/test should work', async ({ exec, tmpWorkspace }) => { test('npm: @playwright/test should work', async ({ exec, tmpWorkspace }) => {
await exec('npm i --foreground-scripts @playwright/test'); await exec('npm i @playwright/test');
await exec('npx playwright test -c . sample.spec.js', { expectToExitWithError: true, message: 'should not be able to run tests without installing browsers' });
await exec('npx playwright install'); await exec('npx playwright install');
await exec('npx playwright test -c . --browser=all --reporter=list,json sample.spec.js', { env: { PLAYWRIGHT_JSON_OUTPUT_NAME: 'report.json' } }); await exec('npx playwright test -c . --browser=all --reporter=list,json sample.spec.js', { env: { PLAYWRIGHT_JSON_OUTPUT_NAME: 'report.json' } });
await exec('node read-json-report.js', path.join(tmpWorkspace, 'report.json')); await exec('node read-json-report.js', path.join(tmpWorkspace, 'report.json'));
@ -28,8 +26,8 @@ test('npm: @playwright/test should work', async ({ exec, tmpWorkspace }) => {
}); });
test('npm: playwright + @playwright/test should work', async ({ exec, tmpWorkspace }) => { test('npm: playwright + @playwright/test should work', async ({ exec, tmpWorkspace }) => {
await exec('npm i --foreground-scripts playwright'); await exec('npm i playwright');
await exec('npm i --foreground-scripts @playwright/test'); await exec('npm i @playwright/test');
await exec('npx playwright install'); await exec('npx playwright install');
await exec('npx playwright test -c . --browser=all --reporter=list,json sample.spec.js', { env: { PLAYWRIGHT_JSON_OUTPUT_NAME: 'report.json' } }); await exec('npx playwright test -c . --browser=all --reporter=list,json sample.spec.js', { env: { PLAYWRIGHT_JSON_OUTPUT_NAME: 'report.json' } });
await exec('node read-json-report.js', path.join(tmpWorkspace, 'report.json')); await exec('node read-json-report.js', path.join(tmpWorkspace, 'report.json'));
@ -38,8 +36,8 @@ test('npm: playwright + @playwright/test should work', async ({ exec, tmpWorkspa
}); });
test('npm: @playwright/test + playwright-core should work', async ({ exec, tmpWorkspace }) => { test('npm: @playwright/test + playwright-core should work', async ({ exec, tmpWorkspace }) => {
await exec('npm i --foreground-scripts @playwright/test'); await exec('npm i @playwright/test');
await exec('npm i --foreground-scripts playwright-core'); await exec('npm i playwright-core');
await exec('npx playwright install'); await exec('npx playwright install');
await exec('npx playwright test -c . --browser=all --reporter=list,json sample.spec.js', { env: { PLAYWRIGHT_JSON_OUTPUT_NAME: 'report.json' } }); await exec('npx playwright test -c . --browser=all --reporter=list,json sample.spec.js', { env: { PLAYWRIGHT_JSON_OUTPUT_NAME: 'report.json' } });
await exec('node read-json-report.js', path.join(tmpWorkspace, 'report.json')); await exec('node read-json-report.js', path.join(tmpWorkspace, 'report.json'));
@ -49,8 +47,6 @@ test('npm: @playwright/test + playwright-core should work', async ({ exec, tmpWo
test('yarn: @playwright/test should work', async ({ exec, tmpWorkspace }) => { test('yarn: @playwright/test should work', async ({ exec, tmpWorkspace }) => {
await exec('yarn add @playwright/test'); await exec('yarn add @playwright/test');
await exec('yarn playwright test -c .', { expectToExitWithError: true, message: 'should not be able to run tests without installing browsers' });
await exec('yarn playwright install'); await exec('yarn playwright install');
await exec('yarn playwright test -c . --browser=all --reporter=list,json sample.spec.js', { env: { PLAYWRIGHT_JSON_OUTPUT_NAME: 'report.json' } }); await exec('yarn playwright test -c . --browser=all --reporter=list,json sample.spec.js', { env: { PLAYWRIGHT_JSON_OUTPUT_NAME: 'report.json' } });
await exec('node read-json-report.js', path.join(tmpWorkspace, 'report.json')); await exec('node read-json-report.js', path.join(tmpWorkspace, 'report.json'));
@ -60,7 +56,6 @@ test('yarn: @playwright/test should work', async ({ exec, tmpWorkspace }) => {
test('pnpm: @playwright/test should work', async ({ exec, tmpWorkspace }) => { test('pnpm: @playwright/test should work', async ({ exec, tmpWorkspace }) => {
await exec('pnpm add @playwright/test'); await exec('pnpm add @playwright/test');
await exec('pnpm exec playwright test -c .', { expectToExitWithError: true, message: 'should not be able to run tests without installing browsers' });
await exec('pnpm exec playwright install'); await exec('pnpm exec playwright install');
await exec('pnpm exec playwright test -c . --browser=all --reporter=list,json sample.spec.js', { env: { PLAYWRIGHT_JSON_OUTPUT_NAME: 'report.json' } }); await exec('pnpm exec playwright test -c . --browser=all --reporter=list,json sample.spec.js', { env: { PLAYWRIGHT_JSON_OUTPUT_NAME: 'report.json' } });
await exec('node read-json-report.js', path.join(tmpWorkspace, 'report.json')); await exec('node read-json-report.js', path.join(tmpWorkspace, 'report.json'));

View file

@ -33,16 +33,16 @@ function patchPackageJsonForPreReleaseIfNeeded(tmpWorkspace: string) {
} }
test('npm: @playwright/test plugin should work', async ({ exec, tmpWorkspace }) => { test('npm: @playwright/test plugin should work', async ({ exec, tmpWorkspace }) => {
await exec('npm i --foreground-scripts @playwright/test'); await exec('npm i @playwright/test');
patchPackageJsonForPreReleaseIfNeeded(tmpWorkspace); patchPackageJsonForPreReleaseIfNeeded(tmpWorkspace);
await exec('npm i --foreground-scripts playwright-test-plugin'); await exec('npm i playwright-test-plugin');
await exec('npx playwright install chromium'); await exec('npx playwright install chromium');
const output = await exec('npx playwright test -c . --browser=chromium --reporter=line plugin.spec.ts'); const output = await exec('npx playwright test -c . --browser=chromium --reporter=line plugin.spec.ts');
expect(output).toContain('plugin value: hello from plugin'); expect(output).toContain('plugin value: hello from plugin');
expect(output).toContain('1 passed'); expect(output).toContain('1 passed');
await exec('npm i --foreground-scripts typescript@5.2.2 @types/node@16'); await exec('npm i typescript@5.2.2 @types/node@16');
await exec('npx tsc playwright-test-plugin-types.ts'); await exec('npx tsc playwright-test-plugin-types.ts');
}); });

View file

@ -1,24 +0,0 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test, expect } from './npmTest';
test('@playwright/test stacks should work', async ({ exec }) => {
await exec('npm i --foreground-scripts @playwright/test');
await exec('npx playwright install chromium');
const output = await exec('npx playwright test -c . failing.spec.js', { expectToExitWithError: true, env: { DEBUG: 'pw:api' } });
expect(output).toContain('expect.toHaveText started');
expect(output).toContain('failing.spec.js:5:38');
});

View file

@ -16,8 +16,6 @@
import { test } from './npmTest'; import { test } from './npmTest';
test('screencast works', async ({ exec }) => { test('screencast works', async ({ exec }) => {
await exec('npm i --foreground-scripts', 'playwright', 'playwright-chromium', 'playwright-firefox', 'playwright-webkit'); await exec('npm i playwright');
await test.step('playwright', () => exec('node screencast.js playwright chromium firefox webkit')); await exec('node screencast.js playwright chromium firefox webkit');
for (const browser of ['chromium', 'firefox', 'webkit'])
await test.step(browser, () => exec(`node screencast.js playwright-${browser} ${browser}`));
}); });

View file

@ -1,25 +0,0 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test, expect } from './npmTest';
test('should skip download', async ({ exec }) => {
const installOutput = await exec('npm i --foreground-scripts playwright @playwright/browser-chromium', { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
expect(installOutput).toContain('Skipping browsers download because');
if (process.platform === 'linux') {
const output = await exec('node inspector-custom-executable.js', { env: { PWDEBUG: '1' } });
expect(output).toContain('SUCCESS');
}
});

View file

@ -15,9 +15,16 @@
*/ */
import { test, expect } from './npmTest'; import { test, expect } from './npmTest';
test('PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD should skip browser installs', async ({ exec, installedSoftwareOnDisk }) => { test.use({ isolateBrowsers: true });
const result = await exec('npm i --foreground-scripts @playwright/browser-firefox', { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
test('should skip browser installs', async ({ exec, installedSoftwareOnDisk }) => {
const result = await exec('npm i --foreground-scripts playwright @playwright/browser-firefox', { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
expect(result).toHaveLoggedSoftwareDownload([]); expect(result).toHaveLoggedSoftwareDownload([]);
expect(await installedSoftwareOnDisk()).toEqual([]); expect(await installedSoftwareOnDisk()).toEqual([]);
expect(result).toContain(`Skipping browsers download because`); expect(result).toContain(`Skipping browsers download because`);
if (process.platform === 'linux') {
const output = await exec('node inspector-custom-executable.js', { env: { PWDEBUG: '1' } });
expect(output).toContain('SUCCESS');
}
}); });

View file

@ -31,28 +31,15 @@ test('typescript types should work', async ({ exec, tsc, writeFiles }) => {
[filename]: `import { Page } from '${libraryPackage}';`, [filename]: `import { Page } from '${libraryPackage}';`,
}); });
await tsc(filename); await tsc(filename);
}
await tsc('playwright-test-types.ts');
});
test('typescript types should work with module: NodeNext', async ({ exec, tsc, writeFiles }) => {
const libraryPackages = [
'playwright',
'playwright-core',
'playwright-firefox',
'playwright-webkit',
'playwright-chromium',
];
await exec('npm i @playwright/test', ...libraryPackages, { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
for (const libraryPackage of libraryPackages) {
const filename = libraryPackage + '.ts';
await writeFiles({
[filename]: `import { Page } from '${libraryPackage}';`,
});
await tsc(`--module nodenext ${filename}`); await tsc(`--module nodenext ${filename}`);
} }
await tsc('playwright-test-types.ts');
await tsc('--module nodenext playwright-test-types.ts'); await tsc('--module nodenext playwright-test-types.ts');
await writeFiles({
'test.ts':
`import { AndroidDevice, _android, AndroidWebView, Page } from 'playwright';`,
});
await tsc('test.ts');
}); });

View file

@ -15,18 +15,17 @@
*/ */
import { test, expect } from './npmTest'; import { test, expect } from './npmTest';
test.describe('validate dependencies', () => { test('validate dependencies', async ({ exec }) => {
test('default (on)', async ({ exec }) => { await exec('npm i playwright');
await exec('npm i --foreground-scripts playwright');
await exec('npx playwright install chromium'); await exec('npx playwright install chromium');
const result = await exec('node validate-dependencies.js');
expect(result).toContain(`PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS`); await test.step('default (on)', async () => {
const result1 = await exec('node validate-dependencies.js');
expect(result1).toContain(`PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS`);
}); });
test('disabled (off)', async ({ exec }) => { await test.step('disabled (off)', async () => {
await exec('npm i --foreground-scripts playwright'); const result2 = await exec('node validate-dependencies-skip-executable-path.js');
await exec('npx playwright install chromium'); expect(result2).not.toContain(`PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS`);
const result = await exec('node validate-dependencies-skip-executable-path.js');
expect(result).not.toContain(`PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS`);
}); });
}); });