Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: add more installation test scenarios (#27240)

Dmitry Gozman9116a81c170a
diff --git a/tests/installation/globalSetup.ts b/tests/installation/globalSetup.ts
index 5a42beb334..4ca65d7340 100644
--- a/tests/installation/globalSetup.ts
+++ b/tests/installation/globalSetup.ts
@@ -54,6 +54,8 @@ async function globalSetup() {
build('playwright-browser-chromium', '@playwright/browser-chromium'),
build('playwright-browser-firefox', '@playwright/browser-firefox'),
build('playwright-browser-webkit', '@playwright/browser-webkit'),
+ build('playwright-ct-react', '@playwright/experimental-ct-react'),
+ build('playwright-ct-core', '@playwright/experimental-ct-core'),
]);
const buildPlaywrightTestPlugin = async () => {
@@ -67,7 +69,7 @@ async function globalSetup() {
const tgzName = packResult.stdout.trim();
const outPath = path.resolve(path.join(outputDir, `playwright-test-plugin.tgz`));
await fs.promises.rename(path.join(cwd, tgzName), outPath);
- console.log('Built playwright-test-plugin');
+ console.log('Built: playwright-test-plugin');
return ['playwright-test-plugin', outPath];
};
builds.push(await buildPlaywrightTestPlugin());
diff --git a/tests/installation/npmTest.ts b/tests/installation/npmTest.ts
index 1074a61022..cfe9189bf7 100644
--- a/tests/installation/npmTest.ts
+++ b/tests/installation/npmTest.ts
@@ -153,24 +153,25 @@ export const test = _test
args = argsAndOrOptions as string[];
let result!: {stdout: string, stderr: string, code: number | null, error?: Error};
+ const cwd = options.cwd ?? tmpWorkspace;
+ // NB: We end up running npm-in-npm, so it's important that we do NOT forward process.env and instead cherry-pick environment variables.
+ const PATH = sanitizeEnvPath(process.env.PATH || '');
+ const env = {
+ 'PATH': PATH,
+ 'DISPLAY': process.env.DISPLAY,
+ 'XAUTHORITY': process.env.XAUTHORITY,
+ ...(isolateBrowsers ? { PLAYWRIGHT_BROWSERS_PATH: _browsersPath } : {}),
+ ...options.env,
+ };
await test.step(`exec: ${[cmd, ...args].join(' ')}`, async () => {
- result = await spawnAsync(cmd, args, {
- shell: true,
- cwd: options.cwd ?? tmpWorkspace,
- // NB: We end up running npm-in-npm, so it's important that we do NOT forward process.env and instead cherry-pick environment variables.
- env: {
- 'PATH': process.env.PATH,
- 'DISPLAY': process.env.DISPLAY,
- 'XAUTHORITY': process.env.XAUTHORITY,
- ...(isolateBrowsers ? { PLAYWRIGHT_BROWSERS_PATH: _browsersPath } : {}),
- ...options.env,
- }
- });
+ result = await spawnAsync(cmd, args, { shell: true, cwd, env });
});
const command = [cmd, ...args].join(' ');
const stdio = result.stdout + result.stderr;
- await testInfo.attach(command, { body: `COMMAND: ${command}\n\nEXIT CODE: ${result.code}\n\n====== STDOUT + STDERR ======\n\n${stdio}` });
+ const commandEnv = Object.entries(env).map(e => `${e[0]}=${e[1]}`).join(' ');
+ const fullCommand = `cd ${cwd} && ${commandEnv} ${command}`;
+ await testInfo.attach(command, { body: `COMMAND: ${fullCommand}\n\nEXIT CODE: ${result.code}\n\n====== STDOUT + STDERR ======\n\n${stdio}` });
// This means something is really off with spawn
if (result.error)
@@ -200,5 +201,10 @@ export const test = _test
},
});
+function sanitizeEnvPath(value: string) {
+ if (process.platform === 'win32')
+ return value.split(';').filter(path => !path.endsWith('node_modules\\.bin')).join(';');
+ return value.split(':').filter(path => !path.endsWith('node_modules/.bin')).join(':');
+}
export { expect };
diff --git a/tests/installation/playwright-test-package-managers.spec.ts b/tests/installation/playwright-test-package-managers.spec.ts
index 5d8af73ca4..e3e50379f1 100755
--- a/tests/installation/playwright-test-package-managers.spec.ts
+++ b/tests/installation/playwright-test-package-managers.spec.ts
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import { test } from './npmTest';
+import { test, expect } from './npmTest';
import path from 'path';
test('npm: @playwright/test should work', async ({ exec, tmpWorkspace }) => {
@@ -45,6 +45,19 @@ test('npm: @playwright/test + playwright-core should work', async ({ exec, tmpWo
await exec('node', 'esm-playwright-test.mjs');
});
+test('npm: @playwright/test should install playwright-core bin', async ({ exec, tmpWorkspace }) => {
+ await exec('npm i @playwright/test');
+ const result = await exec('npx playwright-core --version');
+ expect(result).toContain('Version 1.');
+});
+
+test('npm: uninstalling ct removes playwright bin', async ({ exec, tmpWorkspace }) => {
+ await exec('npm i @playwright/test');
+ await exec('npm i @playwright/experimental-ct-react');
+ await exec('npm uninstall @playwright/experimental-ct-react');
+ await exec('npx playwright test', { expectToExitWithError: true, message: 'command not found' });
+});
+
test('yarn: @playwright/test should work', async ({ exec, tmpWorkspace }) => {
await exec('yarn add @playwright/test');
await exec('yarn playwright install');