From 51a75679077c7de9c58c43671c5fc60b01d99b40 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Fri, 5 Nov 2021 19:01:54 -0700 Subject: [PATCH] codegen: use import instead of require for codegen tests (#10104) --- .../src/server/supplements/recorder/javascript.ts | 2 +- tests/inspector/cli-codegen-test.spec.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/playwright-core/src/server/supplements/recorder/javascript.ts b/packages/playwright-core/src/server/supplements/recorder/javascript.ts index 2baef302ba..f6ceb70ccd 100644 --- a/packages/playwright-core/src/server/supplements/recorder/javascript.ts +++ b/packages/playwright-core/src/server/supplements/recorder/javascript.ts @@ -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(); diff --git a/tests/inspector/cli-codegen-test.spec.ts b/tests/inspector/cli-codegen-test.spec.ts index e16af0278a..82dad27b2a 100644 --- a/tests/inspector/cli-codegen-test.spec.ts +++ b/tests/inspector/cli-codegen-test.spec.ts @@ -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, '\\\\')}'