diff --git a/packages/e2e-test-utils-playwright/src/request-utils/plugins.ts b/packages/e2e-test-utils-playwright/src/request-utils/plugins.ts index 5f1639f109d2e..f018d7d9f3903 100644 --- a/packages/e2e-test-utils-playwright/src/request-utils/plugins.ts +++ b/packages/e2e-test-utils-playwright/src/request-utils/plugins.ts @@ -27,25 +27,55 @@ async function getPluginsMap( this: RequestUtils, forceRefetch = false ) { for ( const plugin of plugins ) { // Ideally, we should be using sanitize_title() in PHP rather than kebabCase(), // but we don't have the exact port of it in JS. - this.pluginsMap[ kebabCase( plugin.name ) ] = plugin.plugin; + // This is a good approximation though. + const slug = kebabCase( plugin.name.toLowerCase() ); + this.pluginsMap[ slug ] = plugin.plugin; } return this.pluginsMap; } /** - * Activates an installed plugin. + * Finds a plugin in the plugin map. * - * @param this RequestUtils. - * @param slug Plugin slug. + * Attempts to provide a helpful error message if not found. + * + * @param slug Plugin slug. + * @param pluginsMap Plugins map. */ -async function activatePlugin( this: RequestUtils, slug: string ) { - const pluginsMap = await this.getPluginsMap(); +function getPluginFromMap( + slug: string, + pluginsMap: Record< string, string > +) { const plugin = pluginsMap[ slug ]; if ( ! plugin ) { + for ( const key of Object.keys( pluginsMap ) ) { + if ( + key.toLowerCase().replace( /-/g, '' ) === + slug.toLowerCase().replace( /-/g, '' ) + ) { + throw new Error( + `The plugin "${ slug }" isn't installed. Did you perhaps mean "${ key }"?` + ); + } + } + throw new Error( `The plugin "${ slug }" isn't installed` ); } + return plugin; +} + +/** + * Activates an installed plugin. + * + * @param this RequestUtils. + * @param slug Plugin slug. + */ +async function activatePlugin( this: RequestUtils, slug: string ) { + const pluginsMap = await this.getPluginsMap(); + const plugin = getPluginFromMap( slug, pluginsMap ); + await this.rest( { method: 'PUT', path: `/wp/v2/plugins/${ plugin }`, @@ -61,11 +91,7 @@ async function activatePlugin( this: RequestUtils, slug: string ) { */ async function deactivatePlugin( this: RequestUtils, slug: string ) { const pluginsMap = await this.getPluginsMap(); - const plugin = pluginsMap[ slug ]; - - if ( ! plugin ) { - throw new Error( `The plugin "${ slug }" isn't installed` ); - } + const plugin = getPluginFromMap( slug, pluginsMap ); await this.rest( { method: 'PUT', diff --git a/test/e2e/specs/editor/plugins/inner-blocks-allowed-blocks.spec.js b/test/e2e/specs/editor/plugins/inner-blocks-allowed-blocks.spec.js index a859a2204de03..a515ef68316e8 100644 --- a/test/e2e/specs/editor/plugins/inner-blocks-allowed-blocks.spec.js +++ b/test/e2e/specs/editor/plugins/inner-blocks-allowed-blocks.spec.js @@ -6,13 +6,13 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); test.describe( 'Allowed Blocks Setting on InnerBlocks', () => { test.beforeAll( async ( { requestUtils } ) => { await requestUtils.activatePlugin( - 'gutenberg-test-inner-blocks-allowed-blocks' + 'gutenberg-test-innerblocks-allowed-blocks' ); } ); test.afterAll( async ( { requestUtils } ) => { await requestUtils.deactivatePlugin( - 'gutenberg-test-inner-blocks-allowed-blocks' + 'gutenberg-test-innerblocks-allowed-blocks' ); } ); diff --git a/test/e2e/specs/editor/various/inner-blocks-templates.spec.js b/test/e2e/specs/editor/various/inner-blocks-templates.spec.js index bbb4a51c75c52..47ef0dfe74791 100644 --- a/test/e2e/specs/editor/various/inner-blocks-templates.spec.js +++ b/test/e2e/specs/editor/various/inner-blocks-templates.spec.js @@ -6,7 +6,7 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); test.describe( 'Inner blocks templates', () => { test.beforeAll( async ( { requestUtils } ) => { await requestUtils.activatePlugin( - 'gutenberg-test-inner-blocks-templates' + 'gutenberg-test-innerblocks-templates' ); } ); @@ -16,7 +16,7 @@ test.describe( 'Inner blocks templates', () => { test.afterAll( async ( { requestUtils } ) => { await requestUtils.deactivatePlugin( - 'gutenberg-test-inner-blocks-templates' + 'gutenberg-test-innerblocks-templates' ); } );