fix(codegen): do not codegen non-existing fixtures (#32993)
Closes https://github.com/microsoft/playwright/issues/32981
This commit is contained in:
parent
6ba5ee3a83
commit
7047c3a6c6
|
@ -138,7 +138,7 @@ export class JavaScriptLanguageGenerator implements LanguageGenerator {
|
|||
|
||||
generateTestHeader(options: LanguageGeneratorOptions): string {
|
||||
const formatter = new JavaScriptFormatter();
|
||||
const useText = formatContextOptions(options.contextOptions, options.deviceName);
|
||||
const useText = formatContextOptions(options.contextOptions, options.deviceName, this._isTest);
|
||||
formatter.add(`
|
||||
import { test, expect${options.deviceName ? ', devices' : ''} } from '@playwright/test';
|
||||
${useText ? '\ntest.use(' + useText + ');\n' : ''}
|
||||
|
@ -157,7 +157,7 @@ ${useText ? '\ntest.use(' + useText + ');\n' : ''}
|
|||
|
||||
(async () => {
|
||||
const browser = await ${options.browserName}.launch(${formatObjectOrVoid(options.launchOptions)});
|
||||
const context = await browser.newContext(${formatContextOptions(options.contextOptions, options.deviceName)});`);
|
||||
const context = await browser.newContext(${formatContextOptions(options.contextOptions, options.deviceName, false)});`);
|
||||
return formatter.format();
|
||||
}
|
||||
|
||||
|
@ -199,8 +199,12 @@ function formatObjectOrVoid(value: any, indent = ' '): string {
|
|||
return result === '{}' ? '' : result;
|
||||
}
|
||||
|
||||
function formatContextOptions(options: BrowserContextOptions, deviceName: string | undefined): string {
|
||||
function formatContextOptions(options: BrowserContextOptions, deviceName: string | undefined, isTest: boolean): string {
|
||||
const device = deviceName && deviceDescriptors[deviceName];
|
||||
if (isTest) {
|
||||
// No recordHAR fixture in test.
|
||||
options = { ...options, recordHar: undefined };
|
||||
}
|
||||
if (!device)
|
||||
return formatObjectOrVoid(options);
|
||||
// Filter out all the properties from the device descriptor.
|
||||
|
|
|
@ -85,13 +85,11 @@ test('test', async ({ page }) => {`;
|
|||
await cli.waitFor(expectedResult);
|
||||
});
|
||||
|
||||
test('should work with --save-har', async ({ runCLI }, testInfo) => {
|
||||
test('should not generate recordHAR with --save-har', async ({ runCLI }, testInfo) => {
|
||||
const harFileName = testInfo.outputPath('har.har');
|
||||
const expectedResult = `
|
||||
recordHar: {
|
||||
mode: 'minimal',
|
||||
path: '${harFileName.replace(/\\/g, '\\\\')}'
|
||||
}`;
|
||||
const expectedResult = `test.use({
|
||||
serviceWorkers: 'block'
|
||||
});`;
|
||||
const cli = runCLI(['--target=playwright-test', `--save-har=${harFileName}`], {
|
||||
autoExitWhen: expectedResult,
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue