codegen: use import instead of require for codegen tests (#10104)

This commit is contained in:
Andrey Lushnikov 2021-11-05 19:01:54 -07:00 committed by GitHub
parent 61ff52704c
commit 51a7567907
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -161,7 +161,7 @@ export class JavaScriptLanguageGenerator implements LanguageGenerator {
const formatter = new JavaScriptFormatter();
const useText = formatContextOptions(options.contextOptions, options.deviceName);
formatter.add(`
const { test, expect${options.deviceName ? ', devices' : ''} } = require('@playwright/test');
import { test, expect${options.deviceName ? ', devices' : ''} } from '@playwright/test';
${useText ? '\ntest.use(' + useText + ');\n' : ''}
test('test', async ({ page }) => {`);
return formatter.format();

View File

@ -22,7 +22,7 @@ const emptyHTML = new URL('file://' + path.join(__dirname, '..', 'assets', 'empt
test('should print the correct imports and context options', async ({ runCLI }) => {
const cli = runCLI([emptyHTML]);
const expectedResult = `const { test, expect } = require('@playwright/test');
const expectedResult = `import { test, expect } from '@playwright/test';
test('test', async ({ page }) => {
@ -33,7 +33,7 @@ test('test', async ({ page }) => {
test('should print the correct context options for custom settings', async ({ browserName, channel, runCLI }) => {
const cli = runCLI(['--color-scheme=light', emptyHTML]);
const expectedResult = `const { test, expect } = require('@playwright/test');
const expectedResult = `import { test, expect } from '@playwright/test';
test.use({
colorScheme: 'light'
@ -49,7 +49,7 @@ test('should print the correct context options when using a device', async ({ br
test.skip(browserName !== 'chromium');
const cli = runCLI(['--device=Pixel 2', emptyHTML]);
const expectedResult = `const { test, expect, devices } = require('@playwright/test');
const expectedResult = `import { test, expect, devices } from '@playwright/test';
test.use({
...devices['Pixel 2'],
@ -64,7 +64,7 @@ test('should print the correct context options when using a device and additiona
test.skip(browserName !== 'webkit');
const cli = runCLI(['--color-scheme=light', '--device=iPhone 11', emptyHTML]);
const expectedResult = `const { test, expect, devices } = require('@playwright/test');
const expectedResult = `import { test, expect, devices } from '@playwright/test';
test.use({
...devices['iPhone 11'],
@ -80,7 +80,7 @@ test('should print load storageState', async ({ browserName, channel, runCLI },
const loadFileName = testInfo.outputPath('load.json');
await fs.promises.writeFile(loadFileName, JSON.stringify({ cookies: [], origins: [] }), 'utf8');
const cli = runCLI([`--load-storage=${loadFileName}`, emptyHTML]);
const expectedResult = `const { test, expect } = require('@playwright/test');
const expectedResult = `import { test, expect } from '@playwright/test';
test.use({
storageState: '${loadFileName.replace(/\\/g, '\\\\')}'