chore: automatically detect the dev server (#29176)
This commit is contained in:
parent
24ff2e2bad
commit
6a14b1dc51
|
@ -181,8 +181,9 @@ export async function isURLAvailable(url: URL, ignoreHTTPSErrors: boolean, onLog
|
||||||
|
|
||||||
async function httpStatusCode(url: URL, ignoreHTTPSErrors: boolean, onLog?: (data: string) => void, onStdErr?: (data: string) => void): Promise<number> {
|
async function httpStatusCode(url: URL, ignoreHTTPSErrors: boolean, onLog?: (data: string) => void, onStdErr?: (data: string) => void): Promise<number> {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
onLog?.(`HTTP GET: ${url}`);
|
onLog?.(`HTTP HEAD: ${url}`);
|
||||||
httpRequest({
|
httpRequest({
|
||||||
|
method: 'HEAD',
|
||||||
url: url.toString(),
|
url: url.toString(),
|
||||||
headers: { Accept: '*/*' },
|
headers: { Accept: '*/*' },
|
||||||
rejectUnauthorized: !ignoreHTTPSErrors
|
rejectUnauthorized: !ignoreHTTPSErrors
|
||||||
|
|
|
@ -56,7 +56,7 @@ export function createPlugin(
|
||||||
const endpoint = resolveEndpoint(config);
|
const endpoint = resolveEndpoint(config);
|
||||||
const protocol = endpoint.https ? 'https:' : 'http:';
|
const protocol = endpoint.https ? 'https:' : 'http:';
|
||||||
const url = new URL(`${protocol}//${endpoint.host}:${endpoint.port}`);
|
const url = new URL(`${protocol}//${endpoint.host}:${endpoint.port}`);
|
||||||
if (process.env.PW_CT_DEV && await isURLAvailable(url, true)) {
|
if (await isURLAvailable(url, true)) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(`Test Server is already running at ${url.toString()}, using it.\n`);
|
console.log(`Test Server is already running at ${url.toString()}, using it.\n`);
|
||||||
process.env.PLAYWRIGHT_TEST_BASE_URL = url.toString();
|
process.env.PLAYWRIGHT_TEST_BASE_URL = url.toString();
|
||||||
|
|
|
@ -21,7 +21,12 @@ test.describe.configure({ mode: 'parallel' });
|
||||||
|
|
||||||
const playwrightConfig = `
|
const playwrightConfig = `
|
||||||
import { defineConfig } from '@playwright/experimental-ct-react';
|
import { defineConfig } from '@playwright/experimental-ct-react';
|
||||||
export default defineConfig({ projects: [{name: 'foo'}] });
|
export default defineConfig({
|
||||||
|
use: {
|
||||||
|
ctPort: ${3200 + (+process.env.TEST_PARALLEL_INDEX)}
|
||||||
|
},
|
||||||
|
projects: [{name: 'foo'}],
|
||||||
|
});
|
||||||
`;
|
`;
|
||||||
|
|
||||||
test('should work with the empty component list', async ({ runInlineTest }, testInfo) => {
|
test('should work with the empty component list', async ({ runInlineTest }, testInfo) => {
|
||||||
|
|
|
@ -18,7 +18,12 @@ import { test, expect } from './playwright-test-fixtures';
|
||||||
|
|
||||||
const playwrightConfig = `
|
const playwrightConfig = `
|
||||||
import { defineConfig } from '@playwright/experimental-ct-react';
|
import { defineConfig } from '@playwright/experimental-ct-react';
|
||||||
export default defineConfig({ projects: [{name: 'foo'}] });
|
export default defineConfig({
|
||||||
|
use: {
|
||||||
|
ctPort: ${3200 + (+process.env.TEST_PARALLEL_INDEX)}
|
||||||
|
},
|
||||||
|
projects: [{name: 'foo'}],
|
||||||
|
});
|
||||||
`;
|
`;
|
||||||
|
|
||||||
test('should work with TSX', async ({ runInlineTest }) => {
|
test('should work with TSX', async ({ runInlineTest }) => {
|
||||||
|
@ -420,7 +425,8 @@ test('should handle the vite host config', async ({ runInlineTest }) => {
|
||||||
|
|
||||||
test('pass component', async ({ page, mount }) => {
|
test('pass component', async ({ page, mount }) => {
|
||||||
const component = await mount(<Component />);
|
const component = await mount(<Component />);
|
||||||
await expect(page).toHaveURL('http://127.0.0.1:3100/');
|
const host = await page.evaluate(() => window.location.hostname);
|
||||||
|
await expect(host).toBe('127.0.0.1');
|
||||||
});
|
});
|
||||||
`,
|
`,
|
||||||
}, { workers: 1 });
|
}, { workers: 1 });
|
||||||
|
|
|
@ -21,7 +21,11 @@ test.describe.configure({ mode: 'parallel', retries });
|
||||||
const basicTestTree = {
|
const basicTestTree = {
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
import { defineConfig } from '@playwright/experimental-ct-react';
|
import { defineConfig } from '@playwright/experimental-ct-react';
|
||||||
export default defineConfig({});
|
export default defineConfig({
|
||||||
|
use: {
|
||||||
|
ctPort: ${3200 + (+process.env.TEST_PARALLEL_INDEX)}
|
||||||
|
}
|
||||||
|
});
|
||||||
`,
|
`,
|
||||||
'playwright/index.html': `<script type="module" src="./index.ts"></script>`,
|
'playwright/index.html': `<script type="module" src="./index.ts"></script>`,
|
||||||
'playwright/index.ts': ``,
|
'playwright/index.ts': ``,
|
||||||
|
|
|
@ -661,7 +661,7 @@ test('should check ipv4 and ipv6 with happy eyeballs when URL is passed', async
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
expect(result.passed).toBe(1);
|
expect(result.passed).toBe(1);
|
||||||
expect(result.output).toContain('Process started');
|
expect(result.output).toContain('Process started');
|
||||||
expect(result.output).toContain(`HTTP GET: http://localhost:${port}/`);
|
expect(result.output).toContain(`HTTP HEAD: http://localhost:${port}/`);
|
||||||
expect(result.output).toContain('WebServer available');
|
expect(result.output).toContain('WebServer available');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue