From 3da2a4998bf877099a25d282a1dfb50e60cf7914 Mon Sep 17 00:00:00 2001 From: Liam Sarsfield <43409125+LiamSarsfield@users.noreply.github.com> Date: Tue, 8 Jul 2025 11:55:53 +0100 Subject: [PATCH] Re-introduce Boost Module E2E tests --- .github/files/e2e-tests/e2e-matrix.js | 8 ++ .../js/features/speed-score/speed-score.tsx | 13 +++- projects/plugins/boost/app/lib/class-cli.php | 2 +- .../fix-boost-modules-e2e-tests-hog-193 | 5 ++ ...e-boost-e2e-mock-unrelated-testing-hog-200 | 5 ++ .../boost/tests/e2e/lib/env/prerequisites.js | 27 +++++++ .../lib/pages/wp-admin/JetpackBoostPage.js | 77 +++++++++++++++---- .../e2e/plugins/e2e-mock-boost-connection.php | 17 ++++ .../boost/tests/e2e/specs/base/common.test.js | 6 +- .../tests/e2e/specs/base/get-started.test.ts | 6 +- .../e2e/specs/concatenate/concatenate.test.js | 10 ++- .../specs/critical-css/critical-css.test.js | 13 +++- .../e2e/specs/modules/modules-common.test.js | 28 ++++--- .../specs/modules/render-blocking-js.test.js | 11 ++- .../specs/modules/score-auto-refresh.test.js | 15 +++- .../e2e/specs/modules/speed-score.test.js | 23 +++--- .../e2e/specs/page-cache/page-cache.test.js | 4 +- .../docker/jetpack-docker-config-default.yml | 1 + 18 files changed, 222 insertions(+), 49 deletions(-) create mode 100644 projects/plugins/boost/changelog/fix-boost-modules-e2e-tests-hog-193 create mode 100644 projects/plugins/boost/changelog/update-boost-e2e-mock-unrelated-testing-hog-200 create mode 100644 projects/plugins/boost/tests/e2e/plugins/e2e-mock-boost-connection.php diff --git a/.github/files/e2e-tests/e2e-matrix.js b/.github/files/e2e-tests/e2e-matrix.js index e1ba2d19367f8..62cd7db909c50 100644 --- a/.github/files/e2e-tests/e2e-matrix.js +++ b/.github/files/e2e-tests/e2e-matrix.js @@ -50,6 +50,14 @@ const projects = [ suite: '', buildGroup: 'jetpack-boost', }, + { + project: 'Jetpack Boost - Modules', + path: 'projects/plugins/boost/tests/e2e', + testArgs: [ 'specs/modules' ], + targets: [ 'plugins/boost' ], + suite: '', + buildGroup: 'jetpack-boost', + }, { project: 'Jetpack Boost - Critical CSS', path: 'projects/plugins/boost/tests/e2e', diff --git a/projects/plugins/boost/app/assets/src/js/features/speed-score/speed-score.tsx b/projects/plugins/boost/app/assets/src/js/features/speed-score/speed-score.tsx index d10c84d5fe76e..2be44ff56d4e7 100644 --- a/projects/plugins/boost/app/assets/src/js/features/speed-score/speed-score.tsx +++ b/projects/plugins/boost/app/assets/src/js/features/speed-score/speed-score.tsx @@ -77,17 +77,26 @@ const SpeedScore = () => { } }, [ loadScore, site.online ] ); + const isCriticalCssEnabled = () => { + if ( ! data?.cloud_css?.available ) { + return data?.cloud_css?.active ?? false; + } + + return data?.critical_css?.active ?? false; + }; + // Refresh the score when something that can affect the score changes. useDebouncedRefreshScore( { moduleStates, pendingStates: { criticalCss: { - isPending: cssState.status === 'pending' || criticalCssIsGenerating, + isPending: + isCriticalCssEnabled() && ( cssState.status === 'pending' || criticalCssIsGenerating ), timestamp: cssState.updated || 0, }, lcp: { - isPending: lcpState?.status === 'pending', + isPending: data?.lcp?.active === true && lcpState?.status === 'pending', timestamp: lcpState?.updated || 0, }, }, diff --git a/projects/plugins/boost/app/lib/class-cli.php b/projects/plugins/boost/app/lib/class-cli.php index 326dc72d54b36..374c1f1af578f 100644 --- a/projects/plugins/boost/app/lib/class-cli.php +++ b/projects/plugins/boost/app/lib/class-cli.php @@ -28,7 +28,7 @@ class CLI { */ private $jetpack_boost; - const MAKE_E2E_TESTS_WORK_MODULES = array( 'critical_css', 'render_blocking_js', 'page_cache', 'minify_js', 'minify_css', 'image_cdn', 'image_guide' ); + const MAKE_E2E_TESTS_WORK_MODULES = array( 'critical_css', 'render_blocking_js', 'page_cache', 'lcp', 'minify_js', 'minify_css', 'image_cdn', 'image_guide' ); /** * CLI constructor. diff --git a/projects/plugins/boost/changelog/fix-boost-modules-e2e-tests-hog-193 b/projects/plugins/boost/changelog/fix-boost-modules-e2e-tests-hog-193 new file mode 100644 index 0000000000000..98978730a7a98 --- /dev/null +++ b/projects/plugins/boost/changelog/fix-boost-modules-e2e-tests-hog-193 @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Add back previously flaky e2e tests + + diff --git a/projects/plugins/boost/changelog/update-boost-e2e-mock-unrelated-testing-hog-200 b/projects/plugins/boost/changelog/update-boost-e2e-mock-unrelated-testing-hog-200 new file mode 100644 index 0000000000000..9c14f81fa12a8 --- /dev/null +++ b/projects/plugins/boost/changelog/update-boost-e2e-mock-unrelated-testing-hog-200 @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: E2E Tests: Ensure resource heavy functionality is mocked where appropriate + + diff --git a/projects/plugins/boost/tests/e2e/lib/env/prerequisites.js b/projects/plugins/boost/tests/e2e/lib/env/prerequisites.js index f4bd70c7623e3..a54241180bab4 100644 --- a/projects/plugins/boost/tests/e2e/lib/env/prerequisites.js +++ b/projects/plugins/boost/tests/e2e/lib/env/prerequisites.js @@ -16,6 +16,7 @@ export function boostPrerequisitesBuilder( page ) { loggedIn: undefined, modules: { active: undefined, inactive: undefined }, connected: undefined, + mockConnection: undefined, jetpackDeactivated: undefined, mockSpeedScore: undefined, enqueuedAssets: undefined, @@ -39,6 +40,10 @@ export function boostPrerequisitesBuilder( page ) { state.connected = shouldBeConnected; return this; }, + withMockConnection( shouldBeMocked ) { + state.mockConnection = shouldBeMocked; + return this; + }, withTestContent( testPostTitles = [] ) { state.testPostTitles = testPostTitles; return this; @@ -84,6 +89,7 @@ async function buildPrerequisites( state, page ) { modules: () => ensureModulesState( state.modules ), loggedIn: () => ensureUserIsLoggedIn( page ), connected: () => ensureConnectedState( state.connected, page ), + mockConnection: () => ensureMockConnectionState( state.mockConnection ), testPostTitles: () => ensureTestPosts( state.testPostTitles ), clean: () => ensureCleanState( state.clean ), mockSpeedScore: () => ensureMockSpeedScoreState( state.mockSpeedScore ), @@ -198,6 +204,9 @@ export async function deactivateModules( modules ) { * @param {page} page - Playwright page instance. */ export async function ensureConnectedState( requiredConnected, page ) { + // Ensure the mock connection plugin is deactivated. + await execWpCommand( 'plugin deactivate e2e-mock-boost-connection' ); + const isConnected = await checkIfConnected(); if ( requiredConnected && isConnected ) { @@ -213,6 +222,24 @@ export async function ensureConnectedState( requiredConnected, page ) { } } +/** + * Ensure mock connection state. + * @param {boolean} mockConnection - Whether the site should be connected. + */ +export async function ensureMockConnectionState( mockConnection ) { + if ( mockConnection ) { + logger.prerequisites( 'Mocking connection' ); + await execWpCommand( 'plugin activate e2e-mock-boost-connection' ); + // Update the WP option jb_get_started to false. + await execWpCommand( 'option update jb_get_started 0' ); + } else { + logger.prerequisites( 'Unmocking connection' ); + await execWpCommand( 'plugin deactivate e2e-mock-boost-connection' ); + // Update the WP option jb_get_started to true. + await execWpCommand( 'option update jb_get_started 1' ); + } +} + /** * Connect. * @param {page} page - Playwright page instance. diff --git a/projects/plugins/boost/tests/e2e/lib/pages/wp-admin/JetpackBoostPage.js b/projects/plugins/boost/tests/e2e/lib/pages/wp-admin/JetpackBoostPage.js index 8e8e7cf95da8e..22286cbce589a 100644 --- a/projects/plugins/boost/tests/e2e/lib/pages/wp-admin/JetpackBoostPage.js +++ b/projects/plugins/boost/tests/e2e/lib/pages/wp-admin/JetpackBoostPage.js @@ -3,7 +3,6 @@ import WpPage from '_jetpack-e2e-commons/pages/wp-page.js'; const apiEndpointsRegex = { 'modules-state': /jetpack-boost-ds\/modules-state\/set/, - connection: /jetpack-boost\/v1\/connection/, }; export default class JetpackBoostPage extends WpPage { @@ -18,8 +17,9 @@ export default class JetpackBoostPage extends WpPage { async chooseFreePlan() { const button = this.page.locator( 'text=Start for free' ); await button.click(); + // We should wait a longer time to ensure the connection/plan is complete/established. - await this.waitForElementToBeVisible( '[data-testid="speed-scores"]', 30 * 1000 ); + await this.isOverallScoreHeaderShown( 30 * 1000 ); } /** @@ -47,8 +47,8 @@ export default class JetpackBoostPage extends WpPage { return showingScoreArea && ! isOffline; } - async isOverallScoreHeaderShown() { - return await this.isElementVisible( '[data-testid="speed-scores"]' ); + async isOverallScoreHeaderShown( timeout ) { + return await this.isElementVisible( '[data-testid="speed-scores"]', timeout ); } async isSiteScoreLoading() { @@ -57,27 +57,78 @@ export default class JetpackBoostPage extends WpPage { return classNames.includes( 'loading' ); } - async waitForApiResponse( apiEndpointId ) { + async waitForApiResponse( apiEndpointId, moduleName, expectedState ) { await this.page.waitForResponse( - response => - response.url().match( apiEndpointsRegex[ apiEndpointId ] ) && response.status() === 200, + async response => { + const isSuccess = response.status() === 200; + if ( ! isSuccess ) { + return false; + } + + const isMatch = response.url().match( apiEndpointsRegex[ apiEndpointId ] ); + if ( ! isMatch ) { + return false; + } + + const body = ( await response.json() )?.JSON; + console.log( `body[ ${ moduleName } ]?.active >`, body[ moduleName ]?.active ); + console.log( 'expectedState >', expectedState ); + return body[ moduleName ]?.active === expectedState; + }, { timeout: 2 * 60 * 1000 } ); } - async toggleModule( moduleName ) { - this.page.click( `.jb-feature-toggle-${ moduleName }` ); - await this.waitForApiResponse( 'modules-state' ); + /** + * Toggle a module and wait for the success notice to appear. + * + * @param {string} moduleName - The name of the module to toggle. + * @param {boolean} expectedState - The expected state of the module. + */ + async toggleModule( moduleName, expectedState ) { + console.log( `toggleModule > ${ moduleName } > ${ expectedState }` ); + + const stateSelector = expectedState ? ':not(.is-checked)' : '.is-checked'; + const locator = `[data-testid="module-${ moduleName }"] .components-form-toggle${ stateSelector } input`; + + const toggle = this.page.locator( locator ); + + toggle.click(); + + // Wait for the success notice to appear + const expectedMessage = expectedState ? 'Module activated' : 'Module deactivated'; + const notice = this.page.locator( `.components-snackbar:has-text("${ expectedMessage }")` ); + await notice.waitFor( { + timeout: 10000, + } ); + + // Wait for the notice to disappear + await notice.waitFor( { + timeout: 10000, + state: 'hidden', + } ); } - async isModuleEnabled( moduleName ) { + async waitForModuleState( moduleName, expectedState = true ) { + console.log( 'before >', expectedState ); const toggleSwitch = this.page.locator( `.jb-feature-toggle-${ moduleName } .components-form-toggle` ); + + // Wait for the toggle to reach the expected state await toggleSwitch.waitFor(); - const classNames = await toggleSwitch.getAttribute( 'class' ); - return classNames.includes( 'is-checked' ); + // Wait for the element to have the expected class state + await toggleSwitch.waitFor( async () => { + const classNames = await toggleSwitch.getAttribute( 'class' ); + const isChecked = classNames.includes( 'is-checked' ); + return expectedState ? isChecked : ! isChecked; + } ); + + // Return whether the expected state was achieved + const classNames = await toggleSwitch.getAttribute( 'class' ); + const actualState = classNames.includes( 'is-checked' ); + return actualState === expectedState; } async getSpeedScore( platform ) { diff --git a/projects/plugins/boost/tests/e2e/plugins/e2e-mock-boost-connection.php b/projects/plugins/boost/tests/e2e/plugins/e2e-mock-boost-connection.php new file mode 100644 index 0000000000000..4eabd91b25e10 --- /dev/null +++ b/projects/plugins/boost/tests/e2e/plugins/e2e-mock-boost-connection.php @@ -0,0 +1,17 @@ + { test.beforeAll( async ( { browser } ) => { page = await browser.newPage( playwrightConfig.use ); - await boostPrerequisitesBuilder( page ).withCleanEnv().withConnection( true ).build(); + await boostPrerequisitesBuilder( page ) + .withCleanEnv() + .withMockConnection( true ) + .withSpeedScoreMocked( true ) + .build(); } ); test.afterAll( async () => { diff --git a/projects/plugins/boost/tests/e2e/specs/base/get-started.test.ts b/projects/plugins/boost/tests/e2e/specs/base/get-started.test.ts index 79d6a142b63e2..06867fc9c7900 100644 --- a/projects/plugins/boost/tests/e2e/specs/base/get-started.test.ts +++ b/projects/plugins/boost/tests/e2e/specs/base/get-started.test.ts @@ -9,7 +9,11 @@ test.describe( 'Getting started page', () => { test.beforeEach( async ( { browser } ) => { page = await browser.newPage( playwrightConfig.use ); - await boostPrerequisitesBuilder( page ).withCleanEnv().withConnection( false ).build(); + await boostPrerequisitesBuilder( page ) + .withCleanEnv() + .withConnection( false ) + .withSpeedScoreMocked( true ) + .build(); jetpackBoostPage = await JetpackBoostPage.visit( page ); } ); diff --git a/projects/plugins/boost/tests/e2e/specs/concatenate/concatenate.test.js b/projects/plugins/boost/tests/e2e/specs/concatenate/concatenate.test.js index 27b33ce5125db..a52d0009a3237 100644 --- a/projects/plugins/boost/tests/e2e/specs/concatenate/concatenate.test.js +++ b/projects/plugins/boost/tests/e2e/specs/concatenate/concatenate.test.js @@ -9,10 +9,16 @@ test.describe( 'Concatenate JS and CSS', () => { test.beforeAll( async ( { browser } ) => { page = await browser.newPage( playwrightConfig.use ); - await boostPrerequisitesBuilder( page ).withCleanEnv( true ).withConnection( true ).build(); + await boostPrerequisitesBuilder( page ) + .withCleanEnv() + .withMockConnection( true ) + .withSpeedScoreMocked( true ) + .build(); } ); - test.afterAll( async () => {} ); + test.afterAll( async () => { + await page.close(); + } ); test( 'No Concatenate meta information should show on the admin when the modules are inactive', async () => { await boostPrerequisitesBuilder( page ) diff --git a/projects/plugins/boost/tests/e2e/specs/critical-css/critical-css.test.js b/projects/plugins/boost/tests/e2e/specs/critical-css/critical-css.test.js index d29f1c61e42ac..33a8cc187756c 100644 --- a/projects/plugins/boost/tests/e2e/specs/critical-css/critical-css.test.js +++ b/projects/plugins/boost/tests/e2e/specs/critical-css/critical-css.test.js @@ -1,7 +1,7 @@ -import { test, expect } from '_jetpack-e2e-commons/fixtures/base-test.js'; +import { expect, test } from '_jetpack-e2e-commons/fixtures/base-test.js'; import { execWpCommand } from '_jetpack-e2e-commons/helpers/utils-helper.js'; import { PostFrontendPage } from '_jetpack-e2e-commons/pages/index.js'; -import { DashboardPage, ThemesPage, Sidebar } from '_jetpack-e2e-commons/pages/wp-admin/index.js'; +import { DashboardPage, Sidebar, ThemesPage } from '_jetpack-e2e-commons/pages/wp-admin/index.js'; import playwrightConfig from '_jetpack-e2e-commons/playwright.config.mjs'; import { boostPrerequisitesBuilder } from '../../lib/env/prerequisites.js'; import { JetpackBoostPage } from '../../lib/pages/index.js'; @@ -12,15 +12,22 @@ test.describe( 'Critical CSS module', () => { test.beforeAll( async ( { browser } ) => { page = await browser.newPage( playwrightConfig.use ); - await boostPrerequisitesBuilder( page ).withCleanEnv( true ).withConnection( true ).build(); + await boostPrerequisitesBuilder( page ) + .withCleanEnv() + .withMockConnection( true ) + .withSpeedScoreMocked( true ) + .build(); + await execWpCommand( 'plugin activate e2e-critical-css-force-errors' ); } ); test.afterAll( async () => { await execWpCommand( 'plugin deactivate e2e-critical-css-force-errors' ); + if ( previousTheme !== null ) { await execWpCommand( `theme activate ${ previousTheme }` ); } + await page.close(); } ); // NOTE: The order of the following tests is important as we are making reuse of the generated Critical CSS diff --git a/projects/plugins/boost/tests/e2e/specs/modules/modules-common.test.js b/projects/plugins/boost/tests/e2e/specs/modules/modules-common.test.js index b3181c642cd52..9117b5b0f5af2 100644 --- a/projects/plugins/boost/tests/e2e/specs/modules/modules-common.test.js +++ b/projects/plugins/boost/tests/e2e/specs/modules/modules-common.test.js @@ -5,7 +5,7 @@ import { JetpackBoostPage } from '../../lib/pages/index.js'; const modules = [ // ['MODULE_NAME', 'DEFAULT STATE'], - [ 'critical_css', 'disabled' ], + [ 'critical_css', 'enabled' ], [ 'render_blocking_js', 'disabled' ], ]; @@ -17,34 +17,40 @@ test.describe.serial( 'Modules', () => { page = await browser.newPage( playwrightConfig.use ); await boostPrerequisitesBuilder( page ) + .withCleanEnv() .withConnection( true ) - .withInactiveModules( [ 'critical_css', 'render_blocking_js' ] ) + .withSpeedScoreMocked( true ) .build(); jetpackBoostPage = await JetpackBoostPage.visit( page ); } ); + test.afterAll( async () => { + await page.close(); + } ); + modules.forEach( ( [ moduleSlug, moduleState ] = module ) => { test( `The ${ moduleSlug } module should be ${ moduleState } by default`, async () => { expect( - await jetpackBoostPage.isModuleEnabled( moduleSlug ), + await jetpackBoostPage.waitForModuleState( moduleSlug, moduleState === 'enabled' ), `${ moduleSlug } should be enabled` - ).toEqual( moduleState === 'enabled' ); + ).toBeTruthy(); } ); test( `The ${ moduleSlug } module state should toggle to an inverse state`, async () => { - await jetpackBoostPage.toggleModule( moduleSlug ); + await jetpackBoostPage.toggleModule( moduleSlug, moduleState !== 'enabled' ); expect( - await jetpackBoostPage.isModuleEnabled( moduleSlug ), - `${ moduleSlug } should not be enabled` - ).toEqual( moduleState !== 'enabled' ); + await jetpackBoostPage.waitForModuleState( moduleSlug, moduleState !== 'enabled' ), + `${ moduleSlug } should be enabled` + ).toBeTruthy(); } ); test( `The ${ moduleSlug } module state should revert back to original state`, async () => { - await jetpackBoostPage.toggleModule( moduleSlug ); + await jetpackBoostPage.toggleModule( moduleSlug, moduleState === 'enabled' ); + expect( - await jetpackBoostPage.isModuleEnabled( moduleSlug ), + await jetpackBoostPage.waitForModuleState( moduleSlug, moduleState === 'enabled' ), `${ moduleSlug } should be enabled` - ).toEqual( moduleState === 'enabled' ); + ).toBeTruthy(); } ); } ); } ); diff --git a/projects/plugins/boost/tests/e2e/specs/modules/render-blocking-js.test.js b/projects/plugins/boost/tests/e2e/specs/modules/render-blocking-js.test.js index 6d8206b033ac2..4eecee84a119b 100644 --- a/projects/plugins/boost/tests/e2e/specs/modules/render-blocking-js.test.js +++ b/projects/plugins/boost/tests/e2e/specs/modules/render-blocking-js.test.js @@ -10,7 +10,16 @@ test.describe( 'Render Blocking JS module', () => { test.beforeAll( async ( { browser } ) => { page = await browser.newPage( playwrightConfig.use ); - await boostPrerequisitesBuilder( page ).withTestContent( [ testPostTitle ] ).build(); + await boostPrerequisitesBuilder( page ) + .withCleanEnv() + .withMockConnection( true ) + .withSpeedScoreMocked( true ) + .withTestContent( [ testPostTitle ] ) + .build(); + } ); + + test.afterAll( async () => { + await page.close(); } ); test( 'JavaScript on a post should be at its original position in the document when the module is inactive', async () => { diff --git a/projects/plugins/boost/tests/e2e/specs/modules/score-auto-refresh.test.js b/projects/plugins/boost/tests/e2e/specs/modules/score-auto-refresh.test.js index f61b63a559f21..db34b19ce5e0f 100644 --- a/projects/plugins/boost/tests/e2e/specs/modules/score-auto-refresh.test.js +++ b/projects/plugins/boost/tests/e2e/specs/modules/score-auto-refresh.test.js @@ -11,21 +11,28 @@ test.describe( 'Auto refresh of speed scores', () => { page = await browser.newPage( playwrightConfig.use ); await boostPrerequisitesBuilder( page ) + .withCleanEnv() .withConnection( true ) + .withSpeedScoreMocked( false ) .withInactiveModules( [ 'critical_css', 'render_blocking_js' ] ) .build(); jetpackBoostPage = await JetpackBoostPage.visit( page ); } ); + test.afterAll( async () => { + await page.close(); + } ); + [ 'render_blocking_js' ].forEach( moduleSlug => { test( `Enabling ${ moduleSlug } should refresh scores`, async () => { await jetpackBoostPage.waitForScoreLoadingToFinish(); - await jetpackBoostPage.toggleModule( moduleSlug ); + expect( await jetpackBoostPage.isScoreVisible(), 'Score should be visible' ).toBeTruthy(); + + await jetpackBoostPage.toggleModule( moduleSlug, true ); await new Promise( resolve => setTimeout( resolve, 2100 ) ); // Score refresh starts after 2 seconds delay - expect( await jetpackBoostPage.isScoreLoading(), 'Score should be loading' ).toBeTruthy(); await jetpackBoostPage.waitForScoreLoadingToFinish(); expect( await jetpackBoostPage.isScoreVisible(), 'Score should be visible' ).toBeTruthy(); } ); @@ -34,11 +41,13 @@ test.describe( 'Auto refresh of speed scores', () => { test( 'Score refresh should debounce between multiple module toggle', async () => { await jetpackBoostPage.waitForScoreLoadingToFinish(); + expect( await jetpackBoostPage.isScoreVisible(), 'Score should be visible' ).toBeTruthy(); + // Wait a second before toggling another. await new Promise( resolve => setTimeout( resolve, 1000 ) ); // Toggle another module before the automatic score refresh started - const renderBlockingPromise = jetpackBoostPage.toggleModule( 'render_blocking_js' ); + const renderBlockingPromise = jetpackBoostPage.toggleModule( 'minify_js', true ); // Wait slightly more than a second after second module is toggled await new Promise( resolve => setTimeout( resolve, 1100 ) ); diff --git a/projects/plugins/boost/tests/e2e/specs/modules/speed-score.test.js b/projects/plugins/boost/tests/e2e/specs/modules/speed-score.test.js index 4df4b7bdf9960..10578f60d5b18 100644 --- a/projects/plugins/boost/tests/e2e/specs/modules/speed-score.test.js +++ b/projects/plugins/boost/tests/e2e/specs/modules/speed-score.test.js @@ -2,24 +2,30 @@ import { test, expect } from '_jetpack-e2e-commons/fixtures/base-test.js'; import { boostPrerequisitesBuilder } from '../../lib/env/prerequisites.js'; import { JetpackBoostPage } from '../../lib/pages/index.js'; -let jetpackBoostPage; - test.describe( 'Speed Score feature', () => { + let page; + let jetpackBoostPage; + test.beforeAll( async ( { browser } ) => { - const page = await browser.newPage(); - await boostPrerequisitesBuilder( page ).withSpeedScoreMocked( false ).build(); + page = await browser.newPage(); + await boostPrerequisitesBuilder( page ) + .withCleanEnv() + .withConnection( true ) + .withSpeedScoreMocked( false ) + .build(); } ); - test.afterAll( async ( { browser } ) => { - const page = await browser.newPage(); - await boostPrerequisitesBuilder( page ).withSpeedScoreMocked( true ).build(); + test.afterAll( async () => { + await page.close(); } ); - test.beforeEach( async function ( { page } ) { + test.beforeEach( async () => { jetpackBoostPage = await JetpackBoostPage.visit( page ); } ); test( 'The Speed Score section should display a mobile and desktop speed score greater than zero', async () => { + await jetpackBoostPage.waitForScoreLoadingToFinish(); + expect( await jetpackBoostPage.getSpeedScore( 'mobile' ), 'Mobile speed score should be greater than 0' @@ -34,7 +40,6 @@ test.describe( 'Speed Score feature', () => { await jetpackBoostPage.waitForScoreLoadingToFinish(); await jetpackBoostPage.clickRefreshSpeedScore(); - expect( await jetpackBoostPage.isScoreLoading(), 'Score should be loading' ).toBeTruthy(); await jetpackBoostPage.waitForScoreLoadingToFinish(); expect( await jetpackBoostPage.isScoreVisible(), 'Score should be displayed' ).toBeTruthy(); } ); diff --git a/projects/plugins/boost/tests/e2e/specs/page-cache/page-cache.test.js b/projects/plugins/boost/tests/e2e/specs/page-cache/page-cache.test.js index 3ae097792eaf9..ca571816d338e 100644 --- a/projects/plugins/boost/tests/e2e/specs/page-cache/page-cache.test.js +++ b/projects/plugins/boost/tests/e2e/specs/page-cache/page-cache.test.js @@ -75,7 +75,7 @@ test.describe( 'Cache module', () => { await permalinksPage.usePlainStructure(); const jetpackBoostPage = await JetpackBoostPage.visit( page ); - await jetpackBoostPage.toggleModule( 'page_cache' ); + await jetpackBoostPage.toggleModule( 'page_cache', true ); expect( await jetpackBoostPage.waitForPageCachePermalinksErrorVisibility(), 'Page Cache should show permalink error message when using plain permalink structure' @@ -89,7 +89,7 @@ test.describe( 'Cache module', () => { // Activate the module. const jetpackBoostPage = await JetpackBoostPage.visit( page ); - await jetpackBoostPage.toggleModule( 'page_cache' ); + await jetpackBoostPage.toggleModule( 'page_cache', true ); expect( await jetpackBoostPage.waitForPageCacheMetaInfoVisibility(), diff --git a/tools/docker/jetpack-docker-config-default.yml b/tools/docker/jetpack-docker-config-default.yml index 47110763c234f..a1931a95e2757 100644 --- a/tools/docker/jetpack-docker-config-default.yml +++ b/tools/docker/jetpack-docker-config-default.yml @@ -68,6 +68,7 @@ e2e: projects/plugins/boost/tests/e2e/plugins/e2e-concatenate-enqueue/: /var/www/html/wp-content/plugins/e2e-concatenate-enqueue/ projects/plugins/boost/tests/e2e/plugins/e2e-appended-image/: /var/www/html/wp-content/plugins/e2e-appended-image/ projects/plugins/boost/tests/e2e/plugins/e2e-mock-speed-score-api.php: /var/www/html/wp-content/plugins/e2e-mock-speed-score-api.php + projects/plugins/boost/tests/e2e/plugins/e2e-mock-boost-connection.php: /var/www/html/wp-content/plugins/e2e-mock-boost-connection.php projects/plugins/boost/tests/e2e/plugins/e2e-critical-css-force-errors.php: /var/www/html/wp-content/plugins/e2e-critical-css-force-errors.php tools/e2e-commons/plugins/e2e-search-test-helper.php: /var/www/html/wp-content/plugins/e2e-search-test-helper.php tools/e2e-commons/plugins/e2e-wpcom-request-interceptor.php: /var/www/html/wp-content/plugins/e2e-wpcom-request-interceptor.php