From 8b1c637c1682c8fa529f6145cb22f25d2f497410 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 13 Nov 2023 21:54:30 +0100 Subject: [PATCH] fix(codegen): generate expect import for library (#28107) --- .../src/server/recorder/javascript.ts | 2 +- .../library/inspector/cli-codegen-javascript.spec.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/playwright-core/src/server/recorder/javascript.ts b/packages/playwright-core/src/server/recorder/javascript.ts index 6ffbb00dcf..71e60d6f7b 100644 --- a/packages/playwright-core/src/server/recorder/javascript.ts +++ b/packages/playwright-core/src/server/recorder/javascript.ts @@ -169,7 +169,7 @@ ${useText ? '\ntest.use(' + useText + ');\n' : ''} generateStandaloneHeader(options: LanguageGeneratorOptions): string { const formatter = new JavaScriptFormatter(); formatter.add(` - const { ${options.browserName}${options.deviceName ? ', devices' : ''} } = require('playwright'); + const { expect, ${options.browserName}${options.deviceName ? ', devices' : ''} } = require('@playwright/test'); (async () => { const browser = await ${options.browserName}.launch(${formatObjectOrVoid(options.launchOptions)}); diff --git a/tests/library/inspector/cli-codegen-javascript.spec.ts b/tests/library/inspector/cli-codegen-javascript.spec.ts index f2c34899d8..198721bb06 100644 --- a/tests/library/inspector/cli-codegen-javascript.spec.ts +++ b/tests/library/inspector/cli-codegen-javascript.spec.ts @@ -26,7 +26,7 @@ const launchOptions = (channel: string) => { test('should print the correct imports and context options', async ({ browserName, channel, runCLI }) => { const cli = runCLI(['--target=javascript', emptyHTML]); - const expectedResult = `const { ${browserName} } = require('playwright'); + const expectedResult = `const { expect, ${browserName} } = require('@playwright/test'); (async () => { const browser = await ${browserName}.launch({ @@ -38,7 +38,7 @@ test('should print the correct imports and context options', async ({ browserNam test('should print the correct context options for custom settings', async ({ browserName, channel, runCLI }) => { const cli = runCLI(['--color-scheme=light', '--target=javascript', emptyHTML]); - const expectedResult = `const { ${browserName} } = require('playwright'); + const expectedResult = `const { expect, ${browserName} } = require('@playwright/test'); (async () => { const browser = await ${browserName}.launch({ @@ -55,7 +55,7 @@ test('should print the correct context options when using a device', async ({ br test.skip(browserName !== 'chromium'); const cli = runCLI(['--device=Pixel 2', '--target=javascript', emptyHTML]); - const expectedResult = `const { chromium, devices } = require('playwright'); + const expectedResult = `const { expect, chromium, devices } = require('@playwright/test'); (async () => { const browser = await chromium.launch({ @@ -71,7 +71,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', '--target=javascript', emptyHTML]); - const expectedResult = `const { webkit, devices } = require('playwright'); + const expectedResult = `const { expect, webkit, devices } = require('@playwright/test'); (async () => { const browser = await webkit.launch({ @@ -91,7 +91,7 @@ test('should save the codegen output to a file if specified', async ({ browserNa }); await cli.waitForCleanExit(); const content = fs.readFileSync(tmpFile); - expect(content.toString()).toBe(`const { ${browserName} } = require('playwright'); + expect(content.toString()).toBe(`const { expect, ${browserName} } = require('@playwright/test'); (async () => { const browser = await ${browserName}.launch({ @@ -113,7 +113,7 @@ test('should print load/save storageState', async ({ browserName, channel, runCL const saveFileName = testInfo.outputPath('save.json'); await fs.promises.writeFile(loadFileName, JSON.stringify({ cookies: [], origins: [] }), 'utf8'); const cli = runCLI([`--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=javascript', emptyHTML]); - const expectedResult1 = `const { ${browserName} } = require('playwright'); + const expectedResult1 = `const { expect, ${browserName} } = require('@playwright/test'); (async () => { const browser = await ${browserName}.launch({