mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-08 04:19:19 +03:00
fix(ct): pass local config to preview (#16481)
This commit is contained in:
parent
dc07a60f14
commit
e1d3246d1c
@ -110,32 +110,37 @@ export function createPlugin(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
const { build, preview } = require('vite');
|
const { build, preview } = require('vite');
|
||||||
if (sourcesDirty) {
|
// Build config unconditionally, either build or build & preview will use it.
|
||||||
viteConfig.plugins = viteConfig.plugins || [
|
viteConfig.plugins = viteConfig.plugins || [
|
||||||
frameworkPluginFactory()
|
frameworkPluginFactory()
|
||||||
];
|
];
|
||||||
|
// But only add out own plugin when we actually build / transform.
|
||||||
|
if (sourcesDirty)
|
||||||
viteConfig.plugins.push(vitePlugin(registerSource, relativeTemplateDir, buildInfo, componentRegistry));
|
viteConfig.plugins.push(vitePlugin(registerSource, relativeTemplateDir, buildInfo, componentRegistry));
|
||||||
viteConfig.configFile = viteConfig.configFile || false;
|
viteConfig.configFile = viteConfig.configFile || false;
|
||||||
viteConfig.define = viteConfig.define || {};
|
viteConfig.define = viteConfig.define || {};
|
||||||
viteConfig.define.__VUE_PROD_DEVTOOLS__ = true;
|
viteConfig.define.__VUE_PROD_DEVTOOLS__ = true;
|
||||||
viteConfig.css = viteConfig.css || {};
|
viteConfig.css = viteConfig.css || {};
|
||||||
viteConfig.css.devSourcemap = true;
|
viteConfig.css.devSourcemap = true;
|
||||||
viteConfig.build = {
|
viteConfig.build = {
|
||||||
...viteConfig.build,
|
...viteConfig.build,
|
||||||
target: 'esnext',
|
target: 'esnext',
|
||||||
minify: false,
|
minify: false,
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
treeshake: false,
|
treeshake: false,
|
||||||
input: {
|
input: {
|
||||||
index: path.join(templateDir, 'index.html')
|
index: path.join(templateDir, 'index.html')
|
||||||
},
|
|
||||||
},
|
},
|
||||||
sourcemap: true,
|
},
|
||||||
};
|
sourcemap: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (sourcesDirty)
|
||||||
await build(viteConfig);
|
await build(viteConfig);
|
||||||
}
|
|
||||||
if (hasNewTests || hasNewComponents || sourcesDirty)
|
if (hasNewTests || hasNewComponents || sourcesDirty)
|
||||||
await fs.promises.writeFile(buildInfoFile, JSON.stringify(buildInfo, undefined, 2));
|
await fs.promises.writeFile(buildInfoFile, JSON.stringify(buildInfo, undefined, 2));
|
||||||
|
|
||||||
const previewServer = await preview(viteConfig);
|
const previewServer = await preview(viteConfig);
|
||||||
stoppableServer = stoppable(previewServer.httpServer, 0);
|
stoppableServer = stoppable(previewServer.httpServer, 0);
|
||||||
const isAddressInfo = (x: any): x is AddressInfo => x?.address;
|
const isAddressInfo = (x: any): x is AddressInfo => x?.address;
|
||||||
|
@ -267,3 +267,30 @@ test('should cache build', async ({ runInlineTest }, testInfo) => {
|
|||||||
expect(output, 'should rebuild bundle').toContain('modules transformed');
|
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);
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user