-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Add Critical CSS module related E2E tests
- Loading branch information
1 parent
75c72c9
commit e4f163e
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
projects/plugins/boost/tests/e2e/specs/jetpack-boost/critical-css.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,55 @@ | ||
import { test, expect } from '../../fixtures/base-test.js'; | ||
import { boostPrerequisitesBuilder } from '../../lib/env/prerequisites.js'; | ||
import { JetpackBoostPage, TestContentPage } from '../../lib/pages/index.js'; | ||
|
||
const testPostTitle = 'Hello World!'; | ||
|
||
test.describe.serial( 'Critical CSS module', () => { | ||
let page; | ||
|
||
test.beforeAll( async ( { browser } ) => { | ||
page = await browser.newPage(); | ||
await boostPrerequisitesBuilder( page ).withCleanEnv( true ).withConnection( true ).build(); | ||
} ); | ||
|
||
test( 'No Critical CSS meta information is showing on the admin when the module is inactive', async () => { | ||
await boostPrerequisitesBuilder( page ).withInactiveModules( [ 'critical-css' ] ).build(); | ||
await JetpackBoostPage.visit( page ); | ||
expect( await page.locator( '.jb-critical-css__meta' ).isHidden() ).toBeTruthy(); | ||
} ); | ||
|
||
test( 'No Critical CSS is available on the frontend when the module is inactive', async () => { | ||
await boostPrerequisitesBuilder( page ).withInactiveModules( [ 'critical-css' ] ).build(); | ||
await TestContentPage.visitByTitle( testPostTitle, page ); | ||
expect( | ||
await page.locator( '#jetpack-boost-critical-css' ).count( { | ||
timeout: 5 * 1000, | ||
} ) | ||
).toBe( 0 ); | ||
} ); | ||
|
||
// The order of the following tests is important as we are making reuse of the generated Critical CSS which is an lengthy tasks in a test. | ||
test( 'Critical CSS is being generated when the module is active', async () => { | ||
await boostPrerequisitesBuilder( page ).withActiveModules( [ 'critical-css' ] ).build(); | ||
await JetpackBoostPage.visit( page ); | ||
await expect( await page.locator( 'text=Generating Critical CSS…' ) ).toBeVisible(); | ||
await expect( await page.locator( '.jb-critical-css__meta' ) ).toBeVisible( { | ||
timeout: 2 * 60 * 1000, | ||
} ); | ||
} ); | ||
|
||
test( 'Critical CSS meta information is showing on the admin when the module is re-activated', async () => { | ||
await boostPrerequisitesBuilder( page ).withInactiveModules( [ 'critical-css' ] ).build(); | ||
await boostPrerequisitesBuilder( page ).withActiveModules( [ 'critical-css' ] ).build(); | ||
await JetpackBoostPage.visit( page ); | ||
await expect( await page.locator( '.jb-critical-css__meta' ) ).toBeVisible( { | ||
timeout: 2 * 60 * 1000, | ||
} ); | ||
} ); | ||
|
||
test( 'Critical CSS is available on the frontend when the module is active', async () => { | ||
await TestContentPage.visitByTitle( testPostTitle, page ); | ||
const criticalCss = await page.locator( '#jetpack-boost-critical-css' ).innerText(); | ||
expect( criticalCss.length ).toBeGreaterThan( 100 ); | ||
} ); | ||
} ); |