test: add more installation test scenarios (#27240)
This commit is contained in:
parent
567386c23f
commit
9116a81c17
|
@ -54,6 +54,8 @@ async function globalSetup() {
|
||||||
build('playwright-browser-chromium', '@playwright/browser-chromium'),
|
build('playwright-browser-chromium', '@playwright/browser-chromium'),
|
||||||
build('playwright-browser-firefox', '@playwright/browser-firefox'),
|
build('playwright-browser-firefox', '@playwright/browser-firefox'),
|
||||||
build('playwright-browser-webkit', '@playwright/browser-webkit'),
|
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 () => {
|
const buildPlaywrightTestPlugin = async () => {
|
||||||
|
@ -67,7 +69,7 @@ async function globalSetup() {
|
||||||
const tgzName = packResult.stdout.trim();
|
const tgzName = packResult.stdout.trim();
|
||||||
const outPath = path.resolve(path.join(outputDir, `playwright-test-plugin.tgz`));
|
const outPath = path.resolve(path.join(outputDir, `playwright-test-plugin.tgz`));
|
||||||
await fs.promises.rename(path.join(cwd, tgzName), outPath);
|
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];
|
return ['playwright-test-plugin', outPath];
|
||||||
};
|
};
|
||||||
builds.push(await buildPlaywrightTestPlugin());
|
builds.push(await buildPlaywrightTestPlugin());
|
||||||
|
|
|
@ -153,24 +153,25 @@ export const test = _test
|
||||||
args = argsAndOrOptions as string[];
|
args = argsAndOrOptions as string[];
|
||||||
|
|
||||||
let result!: {stdout: string, stderr: string, code: number | null, error?: Error};
|
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 () => {
|
await test.step(`exec: ${[cmd, ...args].join(' ')}`, async () => {
|
||||||
result = await spawnAsync(cmd, args, {
|
result = await spawnAsync(cmd, args, { shell: true, cwd, env });
|
||||||
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,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const command = [cmd, ...args].join(' ');
|
const command = [cmd, ...args].join(' ');
|
||||||
const stdio = result.stdout + result.stderr;
|
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
|
// This means something is really off with spawn
|
||||||
if (result.error)
|
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 };
|
export { expect };
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { test } from './npmTest';
|
import { test, expect } 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 }) => {
|
||||||
|
@ -45,6 +45,19 @@ test('npm: @playwright/test + playwright-core should work', async ({ exec, tmpWo
|
||||||
await exec('node', 'esm-playwright-test.mjs');
|
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 }) => {
|
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 install');
|
await exec('yarn playwright install');
|
||||||
|
|
Loading…
Reference in New Issue