mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(ct): baseURL playwright config (#27689)
closes: https://github.com/microsoft/playwright/issues/27627
This commit is contained in:
parent
fd82b2b3fa
commit
562938b271
@ -69,8 +69,7 @@ export function createPlugin(
|
|||||||
// - frameworks overrides (frameworkOverrides);
|
// - frameworks overrides (frameworkOverrides);
|
||||||
|
|
||||||
const use = config.projects[0].use as CtConfig;
|
const use = config.projects[0].use as CtConfig;
|
||||||
const port = use.ctPort || 3100;
|
const baseURL = new URL(use.baseURL || 'http://localhost');
|
||||||
const host = use.baseURL || 'localhost';
|
|
||||||
const relativeTemplateDir = use.ctTemplateDir || 'playwright';
|
const relativeTemplateDir = use.ctTemplateDir || 'playwright';
|
||||||
|
|
||||||
// FIXME: use build plugin to determine html location to resolve this.
|
// FIXME: use build plugin to determine html location to resolve this.
|
||||||
@ -79,7 +78,7 @@ export function createPlugin(
|
|||||||
const templateDir = path.join(configDir, relativeTemplateDir);
|
const templateDir = path.join(configDir, relativeTemplateDir);
|
||||||
|
|
||||||
// Compose base config from the playwright config only.
|
// Compose base config from the playwright config only.
|
||||||
const baseConfig = {
|
const baseConfig: InlineConfig = {
|
||||||
root: configDir,
|
root: configDir,
|
||||||
configFile: false,
|
configFile: false,
|
||||||
define: {
|
define: {
|
||||||
@ -92,8 +91,9 @@ export function createPlugin(
|
|||||||
outDir: use.ctCacheDir ? path.resolve(configDir, use.ctCacheDir) : path.resolve(templateDir, '.cache')
|
outDir: use.ctCacheDir ? path.resolve(configDir, use.ctCacheDir) : path.resolve(templateDir, '.cache')
|
||||||
},
|
},
|
||||||
preview: {
|
preview: {
|
||||||
port,
|
https: baseURL.protocol.startsWith('https:'),
|
||||||
host,
|
host: baseURL.hostname,
|
||||||
|
port: use.ctPort || Number(baseURL.port) || 3100
|
||||||
},
|
},
|
||||||
// Vite preview server will otherwise always return the index.html with 200.
|
// Vite preview server will otherwise always return the index.html with 200.
|
||||||
appType: 'custom',
|
appType: 'custom',
|
||||||
|
|||||||
@ -377,7 +377,7 @@ test('should handle the baseUrl config', async ({ runInlineTest }) => {
|
|||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
import { defineConfig } from '@playwright/experimental-ct-react';
|
import { defineConfig } from '@playwright/experimental-ct-react';
|
||||||
export default defineConfig({ use: { baseURL: '127.0.0.1' } });
|
export default defineConfig({ use: { baseURL: 'http://127.0.0.1:8080' } });
|
||||||
`,
|
`,
|
||||||
'playwright/index.html': `<script type="module" src="./index.js"></script>`,
|
'playwright/index.html': `<script type="module" src="./index.js"></script>`,
|
||||||
'playwright/index.js': ``,
|
'playwright/index.js': ``,
|
||||||
@ -392,7 +392,7 @@ test('should handle the baseUrl 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/');
|
await expect(page).toHaveURL('http://127.0.0.1:8080/');
|
||||||
});
|
});
|
||||||
`,
|
`,
|
||||||
}, { workers: 1 });
|
}, { workers: 1 });
|
||||||
@ -435,7 +435,7 @@ test('should prioritize the vite host config over the baseUrl config', async ({
|
|||||||
import { defineConfig } from '@playwright/experimental-ct-react';
|
import { defineConfig } from '@playwright/experimental-ct-react';
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
use: {
|
use: {
|
||||||
baseURL: 'localhost',
|
baseURL: 'http://localhost:8080',
|
||||||
ctViteConfig: { preview: { host: '127.0.0.1' } }
|
ctViteConfig: { preview: { host: '127.0.0.1' } }
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -453,7 +453,7 @@ test('should prioritize the vite host config over the baseUrl config', async ({
|
|||||||
|
|
||||||
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/');
|
await expect(page).toHaveURL('http://127.0.0.1:8080/');
|
||||||
});
|
});
|
||||||
`,
|
`,
|
||||||
}, { workers: 1 });
|
}, { workers: 1 });
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user