mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
codegen: use import instead of require for codegen tests (#10104)
This commit is contained in:
parent
61ff52704c
commit
51a7567907
@ -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();
|
||||
|
@ -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, '\\\\')}'
|
||||
|
Loading…
x
Reference in New Issue
Block a user