fix(codegen): comment-out generated expects for library scripts (#28118)

- reverts "fix(codegen): generate expect import for library
(https://github.com/microsoft/playwright/pull/28107)";
- comments-out generated expects.
This commit is contained in:
Dmitry Gozman 2023-11-13 16:56:27 -08:00 committed by GitHub
parent 36b99c3437
commit 16aee8b5d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View file

@ -126,12 +126,12 @@ export class JavaScriptLanguageGenerator implements LanguageGenerator {
case 'select': case 'select':
return `await ${subject}.${this._asLocator(action.selector)}.selectOption(${formatObject(action.options.length > 1 ? action.options : action.options[0])});`; return `await ${subject}.${this._asLocator(action.selector)}.selectOption(${formatObject(action.options.length > 1 ? action.options : action.options[0])});`;
case 'assertText': case 'assertText':
return `await expect(${subject}.${this._asLocator(action.selector)}).${action.substring ? 'toContainText' : 'toHaveText'}(${quote(action.text)});`; return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)}).${action.substring ? 'toContainText' : 'toHaveText'}(${quote(action.text)});`;
case 'assertChecked': case 'assertChecked':
return `await expect(${subject}.${this._asLocator(action.selector)})${action.checked ? '' : '.not'}.toBeChecked();`; return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)})${action.checked ? '' : '.not'}.toBeChecked();`;
case 'assertValue': { case 'assertValue': {
const assertion = action.value ? `toHaveValue(${quote(action.value)})` : `toBeEmpty()`; const assertion = action.value ? `toHaveValue(${quote(action.value)})` : `toBeEmpty()`;
return `await expect(${subject}.${this._asLocator(action.selector)}).${assertion};`; return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)}).${assertion};`;
} }
} }
} }
@ -169,7 +169,7 @@ ${useText ? '\ntest.use(' + useText + ');\n' : ''}
generateStandaloneHeader(options: LanguageGeneratorOptions): string { generateStandaloneHeader(options: LanguageGeneratorOptions): string {
const formatter = new JavaScriptFormatter(); const formatter = new JavaScriptFormatter();
formatter.add(` formatter.add(`
const { expect, ${options.browserName}${options.deviceName ? ', devices' : ''} } = require('@playwright/test'); const { ${options.browserName}${options.deviceName ? ', devices' : ''} } = require('playwright');
(async () => { (async () => {
const browser = await ${options.browserName}.launch(${formatObjectOrVoid(options.launchOptions)}); const browser = await ${options.browserName}.launch(${formatObjectOrVoid(options.launchOptions)});

View file

@ -26,7 +26,7 @@ const launchOptions = (channel: string) => {
test('should print the correct imports and context options', async ({ browserName, channel, runCLI }) => { test('should print the correct imports and context options', async ({ browserName, channel, runCLI }) => {
const cli = runCLI(['--target=javascript', emptyHTML]); const cli = runCLI(['--target=javascript', emptyHTML]);
const expectedResult = `const { expect, ${browserName} } = require('@playwright/test'); const expectedResult = `const { ${browserName} } = require('playwright');
(async () => { (async () => {
const browser = await ${browserName}.launch({ 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 }) => { test('should print the correct context options for custom settings', async ({ browserName, channel, runCLI }) => {
const cli = runCLI(['--color-scheme=light', '--target=javascript', emptyHTML]); const cli = runCLI(['--color-scheme=light', '--target=javascript', emptyHTML]);
const expectedResult = `const { expect, ${browserName} } = require('@playwright/test'); const expectedResult = `const { ${browserName} } = require('playwright');
(async () => { (async () => {
const browser = await ${browserName}.launch({ 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'); test.skip(browserName !== 'chromium');
const cli = runCLI(['--device=Pixel 2', '--target=javascript', emptyHTML]); const cli = runCLI(['--device=Pixel 2', '--target=javascript', emptyHTML]);
const expectedResult = `const { expect, chromium, devices } = require('@playwright/test'); const expectedResult = `const { chromium, devices } = require('playwright');
(async () => { (async () => {
const browser = await chromium.launch({ 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'); test.skip(browserName !== 'webkit');
const cli = runCLI(['--color-scheme=light', '--device=iPhone 11', '--target=javascript', emptyHTML]); const cli = runCLI(['--color-scheme=light', '--device=iPhone 11', '--target=javascript', emptyHTML]);
const expectedResult = `const { expect, webkit, devices } = require('@playwright/test'); const expectedResult = `const { webkit, devices } = require('playwright');
(async () => { (async () => {
const browser = await webkit.launch({ 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(); await cli.waitForCleanExit();
const content = fs.readFileSync(tmpFile); const content = fs.readFileSync(tmpFile);
expect(content.toString()).toBe(`const { expect, ${browserName} } = require('@playwright/test'); expect(content.toString()).toBe(`const { ${browserName} } = require('playwright');
(async () => { (async () => {
const browser = await ${browserName}.launch({ 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'); const saveFileName = testInfo.outputPath('save.json');
await fs.promises.writeFile(loadFileName, JSON.stringify({ cookies: [], origins: [] }), 'utf8'); await fs.promises.writeFile(loadFileName, JSON.stringify({ cookies: [], origins: [] }), 'utf8');
const cli = runCLI([`--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=javascript', emptyHTML]); const cli = runCLI([`--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=javascript', emptyHTML]);
const expectedResult1 = `const { expect, ${browserName} } = require('@playwright/test'); const expectedResult1 = `const { ${browserName} } = require('playwright');
(async () => { (async () => {
const browser = await ${browserName}.launch({ const browser = await ${browserName}.launch({