Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typescript-eslint rules with type informations to e2e tests #48267

Merged
merged 3 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,17 @@ module.exports = {
'test/e2e/**/*.[tj]s',
'packages/e2e-test-utils-playwright/**/*.[tj]s',
],
extends: [ 'plugin:eslint-plugin-playwright/playwright-test' ],
extends: [
'plugin:eslint-plugin-playwright/playwright-test',
'plugin:@typescript-eslint/base',
],
parserOptions: {
tsconfigRootDir: __dirname,
project: [
'./test/e2e/tsconfig.json',
'./packages/e2e-test-utils-playwright/tsconfig.json',
],
},
rules: {
'@wordpress/no-global-active-element': 'off',
'@wordpress/no-global-get-selection': 'off',
Expand All @@ -411,6 +421,9 @@ module.exports = {
message: 'Prefer page.locator instead.',
},
],
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-misused-promises': 'error',
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/specs/editor/blocks/classic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ test.describe( 'Classic', () => {
} ) => {
// Based on docs routing diables caching.
// See: https://playwright.dev/docs/api/class-page#page-route
await page.route( '**', ( route ) => {
route.continue();
await page.route( '**', async ( route ) => {
await route.continue();
} );

await editor.insertBlock( { name: 'core/freeform' } );
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/code.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test.describe( 'Code', () => {
await editor.insertBlock( { name: 'core/code' } );

// Test to see if HTML and white space is kept.
await pageUtils.setClipboardData( { plainText: '<img />\n\t<br>' } );
pageUtils.setClipboardData( { plainText: '<img />\n\t<br>' } );

await pageUtils.pressKeyWithModifier( 'primary', 'v' );

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/gallery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test.describe( 'Gallery', () => {
} ) => {
await admin.createNewPost();

await pageUtils.setClipboardData( {
pageUtils.setClipboardData( {
plainText: `[gallery ids="${ uploadedMedia.id }"]`,
} );

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/specs/editor/blocks/image.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ test.describe( 'Image', () => {
// Add caption and navigate to inline toolbar.
await editor.clickBlockToolbarButton( 'Add caption' );
await pageUtils.pressKeyWithModifier( 'shift', 'Tab' );
await expect(
expect(
await page.evaluate( () =>
document.activeElement.getAttribute( 'aria-label' )
)
Expand All @@ -234,7 +234,7 @@ test.describe( 'Image', () => {
await page.keyboard.press( 'ArrowLeft' );
// Italic to bold.
await page.keyboard.press( 'ArrowLeft' );
await expect(
expect(
await page.evaluate( () =>
document.activeElement.getAttribute( 'aria-label' )
)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ test.describe( 'List', () => {
await pageUtils.pressKeyWithModifier( 'secondary', 'M' ); // Emulates CTRL+Shift+Alt + M => toggle code editor

// Paste empty list block
await pageUtils.setClipboardData( {
pageUtils.setClipboardData( {
plainText:
'<!-- wp:list -->\n<ul><li></li></ul>\n<!-- /wp:list -->',
} );
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/specs/editor/plugins/nonce.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ test.describe( 'Nonce', () => {
url.href.startsWith(
requestUtils.storageState.rootURL.slice( 0, -1 )
),
( route ) => {
async ( route ) => {
if ( refreshed ) {
route.continue();
await route.continue();
} else {
route.fulfill( {
await route.fulfill( {
status: 403,
contentType: 'application/json; charset=UTF-8',
body: JSON.stringify( {
Expand All @@ -63,7 +63,7 @@ test.describe( 'Nonce', () => {
}

const saveDraftResponses = [];
page.on( 'response', async ( response ) => {
page.on( 'response', ( response ) => {
const request = response.request();
if (
request.method() === 'POST' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,9 @@ test.describe( 'Autocomplete', () => {
await expect(
page.locator( `role=option[name="${ testData.optionText }"i]` )
).toBeVisible();
await page;
page.locator(
`role=option[name="${ testData.optionText }"i]`
).click();
await page
.locator( `role=option[name="${ testData.optionText }"i]` )
.click();

await expect
.poll( editor.getEditedPostContent )
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/specs/editor/various/copy-cut-paste.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ test.describe( 'Copy/cut/paste', () => {
// back to default browser behaviour, allowing the browser to insert
// unfiltered HTML. When we swap out the post title in the post editor
// with the proper block, this test can be removed.
await pageUtils.setClipboardData( {
pageUtils.setClipboardData( {
html: '<span style="border: 1px solid black">Hello World</span>',
} );
await pageUtils.pressKeyWithModifier( 'primary', 'v' );
Expand All @@ -423,7 +423,7 @@ test.describe( 'Copy/cut/paste', () => {
} ) => {
await page.keyboard.type( 'ab' );
await page.keyboard.press( 'ArrowLeft' );
await pageUtils.setClipboardData( {
pageUtils.setClipboardData( {
html: '<span style="border: 1px solid black">x</span>',
} );
await pageUtils.pressKeyWithModifier( 'primary', 'v' );
Expand All @@ -439,7 +439,7 @@ test.describe( 'Copy/cut/paste', () => {
pageUtils,
editor,
} ) => {
await pageUtils.setClipboardData( {
pageUtils.setClipboardData( {
html: '<pre>x</pre>',
} );
await editor.insertBlock( { name: 'core/list' } );
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/various/inserting-blocks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ test.describe( 'insert media from inserter', () => {
);
} );
test.afterAll( async ( { requestUtils } ) => {
Promise.all( [
await Promise.all( [
requestUtils.deleteAllMedia(),
requestUtils.deleteAllPosts(),
] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class ToolbarRovingTabindexUtils {
document.activeElement.getAttribute( 'aria-label' )
);
}
await expect( ariaLabel ).toBe( label );
expect( ariaLabel ).toBe( label );
}

async wrapCurrentBlockWithGroup( currentBlockTitle ) {
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/specs/site-editor/title.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test.describe( 'Site editor title', () => {
postType: 'wp_template',
} );
await editor.canvas.click( 'body' );
const title = await page.locator(
const title = page.locator(
'role=region[name="Editor top bar"i] >> role=heading[level=1]'
);

Expand All @@ -41,7 +41,7 @@ test.describe( 'Site editor title', () => {
postType: 'wp_template_part',
} );
await editor.canvas.click( 'body' );
const title = await page.locator(
const title = page.locator(
'role=region[name="Editor top bar"i] >> role=heading[level=1]'
);

Expand All @@ -60,14 +60,14 @@ test.describe( 'Site editor title', () => {
await editor.canvas.click( 'body' );
// Select the header template part via list view.
await page.click( 'role=button[name="List View"i]' );
const listView = await page.locator(
const listView = page.locator(
'role=treegrid[name="Block navigation structure"i]'
);
await listView.locator( 'role=gridcell >> text="header"' ).click();
await page.click( 'role=button[name="Close List View Sidebar"i]' );

// Evaluate the document settings secondary title.
const secondaryTitle = await page.locator(
const secondaryTitle = page.locator(
'.edit-site-document-actions__secondary-item'
);

Expand Down