Skip to content

Commit

Permalink
WIP: Add Critical CSS module related E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlonjon committed Dec 3, 2021
1 parent 75c72c9 commit e4f163e
Showing 1 changed file with 55 additions and 0 deletions.
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 );
} );
} );

0 comments on commit e4f163e

Please sign in to comment.