-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Boost: Add e2e tests to Page Cache (#36501)
* Add test for Page Cache meta visibility when module is inactive * Add test for Page Cache header when module is inactive * Add test for Page cache meta visibility when module is active * Add permalink tests for page cache * add changelog * Add cache header test * Update boost CLI to support page cache * Fix test * Update GH actions to include page cache tests * Fix page cache tests * Update file permissions in docker to be writable * Add pnpm script to make files used by page cache writable * Revert permission changes * Fix prepare script * Update script * Update page cache test to check header value as well
- Loading branch information
Showing
9 changed files
with
220 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: added | ||
|
||
Add end to end tests for modules. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as JetpackBoostPage } from './wp-admin/JetpackBoostPage.js'; | ||
export { default as PermalinksPage } from './wp-admin/PermalinksPage.js'; | ||
export { default as FirstPostPage } from './frontend/FirstPostPage.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
projects/plugins/boost/tests/e2e/lib/pages/wp-admin/PermalinksPage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import WpPage from 'jetpack-e2e-commons/pages/wp-page.js'; | ||
import { resolveSiteUrl } from 'jetpack-e2e-commons/helpers/utils-helper.js'; | ||
|
||
export default class PermalinksPage extends WpPage { | ||
constructor( page ) { | ||
const url = `${ resolveSiteUrl() }/wp-admin/options-permalink.php`; | ||
super( page, { expectedSelectors: [ '.permalink-structure' ], url } ); | ||
} | ||
|
||
async usePlainStructure() { | ||
const selector = '[id="permalink-input-plain"]'; | ||
await this.page.click( selector ); | ||
await this.page.click( '[id="submit"]' ); | ||
await this.waitForLoad(); | ||
} | ||
|
||
async useDayNameStructure() { | ||
const selector = '[id="permalink-input-day-name"]'; | ||
await this.page.click( selector ); | ||
await this.page.click( '[id="submit"]' ); | ||
await this.waitForLoad(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
projects/plugins/boost/tests/e2e/specs/page-cache/page-cache.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import { test, expect } from 'jetpack-e2e-commons/fixtures/base-test.js'; | ||
import { boostPrerequisitesBuilder } from '../../lib/env/prerequisites.js'; | ||
import { JetpackBoostPage, PermalinksPage } from '../../lib/pages/index.js'; | ||
import { PostFrontendPage } from 'jetpack-e2e-commons/pages/index.js'; | ||
import { WPLoginPage } from 'jetpack-e2e-commons/pages/wp-admin/index.js'; | ||
import playwrightConfig from 'jetpack-e2e-commons/playwright.config.mjs'; | ||
import { resolveSiteUrl } from 'jetpack-e2e-commons/helpers/utils-helper.js'; | ||
|
||
test.describe( 'Cache module', () => { | ||
let page; | ||
|
||
test.beforeAll( async ( { browser } ) => { | ||
page = await browser.newPage( playwrightConfig.use ); | ||
await boostPrerequisitesBuilder( page ) | ||
.withInactiveModules( [ | ||
'page_cache', // Make sure it's inactive. | ||
] ) | ||
.withCleanEnv() | ||
.withConnection( true ) | ||
.build(); | ||
|
||
// Page Cache needs a pretty permalink structure to work properly. | ||
const permalinksPage = await PermalinksPage.visit( page ); | ||
await permalinksPage.useDayNameStructure(); | ||
} ); | ||
|
||
// Disabling the module before each test, because each test will decide if | ||
// it needs the module enabled or not. | ||
test.beforeEach( async () => { | ||
await boostPrerequisitesBuilder( page ).withInactiveModules( [ 'page_cache' ] ).build(); | ||
} ); | ||
|
||
test.afterAll( async () => { | ||
// Reset the environment for any other tests. | ||
await boostPrerequisitesBuilder( page ).withCleanEnv().withConnection( true ).build(); | ||
await page.close(); | ||
} ); | ||
|
||
test( 'No Page Cache meta information should show on the admin when the module is inactive', async () => { | ||
const jetpackBoostPage = await JetpackBoostPage.visit( page ); | ||
expect( | ||
await jetpackBoostPage.isThePageCacheMetaInformationVisible(), | ||
'Page Cache meta information should not be visible' | ||
).toBeFalsy(); | ||
} ); | ||
|
||
// Make sure there's no cache header when module is disabled. | ||
test( 'Page Cache header should not be present when module is inactive', async ( { | ||
browser, | ||
} ) => { | ||
const newPage = await browser.newPage( playwrightConfig.use ); | ||
const postFrontPage = await PostFrontendPage.visit( newPage ); | ||
await postFrontPage.logout(); | ||
|
||
newPage.on( 'response', response => { | ||
if ( response.url().replace( /\/$/, '' ) !== resolveSiteUrl().replace( /\/$/, '' ) ) { | ||
return; | ||
} | ||
|
||
expect( | ||
response.headers().hasOwnProperty( 'X-Jetpack-Boost-Cache'.toLowerCase() ), | ||
'Page Cache header should not be present' | ||
).toBeFalsy(); | ||
} ); | ||
|
||
await PostFrontendPage.visit( newPage ); | ||
|
||
await newPage.close(); | ||
} ); | ||
|
||
// Make sure there's an error message when trying to enable Page Cache with plain permalinks. | ||
test( 'Enabling Page Cache should show error notice when plain permalinks are enabled', async () => { | ||
const loginPage = await WPLoginPage.visit( page ); | ||
await loginPage.login(); | ||
|
||
const permalinksPage = await PermalinksPage.visit( page ); | ||
await permalinksPage.usePlainStructure(); | ||
|
||
const jetpackBoostPage = await JetpackBoostPage.visit( page ); | ||
await jetpackBoostPage.toggleModule( 'page_cache' ); | ||
expect( | ||
await jetpackBoostPage.waitForPageCachePermalinksErrorVisibility(), | ||
'Page Cache should show permalink error message when using plain permalink structure' | ||
).toBeTruthy(); | ||
} ); | ||
|
||
// Make sure Page Cache meta is visible when module is active. | ||
test( 'Page Cache meta information should show on the admin when the module is active', async () => { | ||
const permalinksPage = await PermalinksPage.visit( page ); | ||
await permalinksPage.useDayNameStructure(); | ||
|
||
// Activate the module. | ||
const jetpackBoostPage = await JetpackBoostPage.visit( page ); | ||
await jetpackBoostPage.toggleModule( 'page_cache' ); | ||
|
||
expect( | ||
await jetpackBoostPage.waitForPageCacheMetaInfoVisibility(), | ||
'Page Cache meta information should be visible' | ||
).toBeTruthy(); | ||
} ); | ||
|
||
// Make sure there's a cache header when module is enabled. | ||
test( 'Page Cache header should be present when module is active', async ( { browser } ) => { | ||
await boostPrerequisitesBuilder( page ).withActiveModules( [ 'page_cache' ] ).build(); | ||
|
||
const newPage = await browser.newPage( playwrightConfig.use ); | ||
const postFrontPage = await PostFrontendPage.visit( newPage ); | ||
await postFrontPage.logout(); | ||
|
||
let totalVisits = 0; | ||
|
||
newPage.on( 'response', response => { | ||
if ( response.url().replace( /\/$/, '' ) !== resolveSiteUrl().replace( /\/$/, '' ) ) { | ||
return; | ||
} | ||
|
||
totalVisits++; | ||
|
||
const responseHeaders = response.headers(); | ||
const cacheHeaderName = 'X-Jetpack-Boost-Cache'.toLowerCase(); | ||
|
||
// First visit should always be a miss. | ||
if ( totalVisits === 1 ) { | ||
expect( | ||
responseHeaders.hasOwnProperty( cacheHeaderName ) && | ||
responseHeaders[ cacheHeaderName ] === 'miss', | ||
'Page Cache header should be set to miss on first visit.' | ||
).toBeTruthy(); | ||
} else { | ||
expect( | ||
responseHeaders.hasOwnProperty( cacheHeaderName ) && | ||
responseHeaders[ cacheHeaderName ] === 'hit', | ||
'Page Cache header should be set to hit on second visit.' | ||
).toBeTruthy(); | ||
} | ||
} ); | ||
|
||
await PostFrontendPage.visit( newPage ); | ||
|
||
// Visit again to make sure the cache is hit. | ||
await PostFrontendPage.visit( newPage ); | ||
|
||
await newPage.close(); | ||
} ); | ||
} ); |