Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(ct): pass local config to preview (#16481)
Pavel Feldmane1d3246d1cfb
diff --git a/packages/playwright-test/src/plugins/vitePlugin.ts b/packages/playwright-test/src/plugins/vitePlugin.tsindex afaf313dc4..21593f80ef 100644--- a/packages/playwright-test/src/plugins/vitePlugin.ts+++ b/packages/playwright-test/src/plugins/vitePlugin.ts@@ -110,32 +110,37 @@ export function createPlugin(};}const { build, preview } = require('vite');- if (sourcesDirty) {- viteConfig.plugins = viteConfig.plugins || [- frameworkPluginFactory()- ];+ // Build config unconditionally, either build or build & preview will use it.+ viteConfig.plugins = viteConfig.plugins || [+ frameworkPluginFactory()+ ];+ // But only add out own plugin when we actually build / transform.+ if (sourcesDirty)viteConfig.plugins.push(vitePlugin(registerSource, relativeTemplateDir, buildInfo, componentRegistry));- viteConfig.configFile = viteConfig.configFile || false;- viteConfig.define = viteConfig.define || {};- viteConfig.define.__VUE_PROD_DEVTOOLS__ = true;- viteConfig.css = viteConfig.css || {};- viteConfig.css.devSourcemap = true;- viteConfig.build = {- ...viteConfig.build,- target: 'esnext',- minify: false,- rollupOptions: {- treeshake: false,- input: {- index: path.join(templateDir, 'index.html')- },+ viteConfig.configFile = viteConfig.configFile || false;+ viteConfig.define = viteConfig.define || {};+ viteConfig.define.__VUE_PROD_DEVTOOLS__ = true;+ viteConfig.css = viteConfig.css || {};+ viteConfig.css.devSourcemap = true;+ viteConfig.build = {+ ...viteConfig.build,+ target: 'esnext',+ minify: false,+ rollupOptions: {+ treeshake: false,+ input: {+ index: path.join(templateDir, 'index.html')},- sourcemap: true,- };+ },+ sourcemap: true,+ };++ if (sourcesDirty)await build(viteConfig);- }+if (hasNewTests || hasNewComponents || sourcesDirty)await fs.promises.writeFile(buildInfoFile, JSON.stringify(buildInfo, undefined, 2));+const previewServer = await preview(viteConfig);stoppableServer = stoppable(previewServer.httpServer, 0);const isAddressInfo = (x: any): x is AddressInfo => x?.address;diff --git a/tests/playwright-test/playwright.ct-build.spec.ts b/tests/playwright-test/playwright.ct-build.spec.tsindex cc1e8e7530..c36449f957 100644--- a/tests/playwright-test/playwright.ct-build.spec.ts+++ b/tests/playwright-test/playwright.ct-build.spec.ts@@ -267,3 +267,30 @@ test('should cache build', async ({ runInlineTest }, testInfo) => {expect(output, 'should rebuild bundle').toContain('modules transformed');});});++test('should not use global config for preview', async ({ runInlineTest }) => {+ const result1 = await runInlineTest({+ 'playwright/index.html': `<script type="module" src="/playwright/index.js"></script>`,+ 'playwright/index.js': ``,+ 'vite.config.js': `+ export default {+ plugins: [{+ configurePreviewServer: () => {+ throw new Error('Original preview throws');+ }+ }]+ };+ `,+ 'a.test.ts': `+ //@no-header+ import { test, expect } from '@playwright/experimental-ct-react';+ test('pass', async ({ mount }) => {});+ `,+ }, { workers: 1 });+ expect(result1.exitCode).toBe(0);+ expect(result1.passed).toBe(1);++ const result2 = await runInlineTest({}, { workers: 1 });+ expect(result2.exitCode).toBe(0);+ expect(result2.passed).toBe(1);+});\ No newline at end of file