-
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 concatenate JS/CSS (#36668)
* Add data attributes for testing to concatenate JS * Allow concatenate_js to be enabled via Boost's CLI * Add concatenate JS test for meta visibility when inactive * add changelog * Add e2e 'concatenate assets' helper plugin * Add concatenate JS test to make sure concatenation is not happening * Fix incorrect module name * Add test to make sure concat meta is visible when module is active * Add test to verify JS concatenation when module is active * Add Boost's concatenate JS test configuration to e2e test matrix * Add test to verify JS concatenation excludes jquery when enabled * Update concatenate JS tests to rely on custom assets instead * Add e2e tests for concatenate CSS * Add Boost's concatenate CSS test configuration to e2e test matrix * Update selectors in JS/CSS concat tests to allow for greater flexibility * Combine concatenate tests into one
- Loading branch information
1 parent
ca3e607
commit aac8002
Showing
13 changed files
with
179 additions
and
2 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
5 changes: 5 additions & 0 deletions
5
projects/plugins/boost/changelog/add-e2e-tests-concatenate-js-css
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,5 @@ | ||
Significance: patch | ||
Type: added | ||
Comment: Add e2e tests for Concatenate JS/CSS 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
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
1 change: 1 addition & 0 deletions
1
projects/plugins/boost/tests/e2e/plugins/e2e-concatenate-enqueue/assets/e2e-script-one.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 @@ | ||
console.log( 'e2e-script-one.js' ); |
1 change: 1 addition & 0 deletions
1
projects/plugins/boost/tests/e2e/plugins/e2e-concatenate-enqueue/assets/e2e-script-two.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 @@ | ||
console.log( 'e2e-script-two.js' ); |
1 change: 1 addition & 0 deletions
1
projects/plugins/boost/tests/e2e/plugins/e2e-concatenate-enqueue/assets/e2e-style-one.css
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 @@ | ||
.nonexistentselector { color: inherit; } |
1 change: 1 addition & 0 deletions
1
projects/plugins/boost/tests/e2e/plugins/e2e-concatenate-enqueue/assets/e2e-style-two.css
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 @@ | ||
.nonexistentselector2 { color: green; } |
22 changes: 22 additions & 0 deletions
22
projects/plugins/boost/tests/e2e/plugins/e2e-concatenate-enqueue/e2e-concatenate-enqueue.php
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,22 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Boost E2E Enqueue Assets | ||
* Description: Enqueue assets for testing Concatenate JS and CSS. | ||
* Plugin URI: https://github.com/automattic/jetpack | ||
* Author: Heart of Gold | ||
* Version: 1.0.0 | ||
* Text Domain: jetpack | ||
* | ||
* @package automattic/jetpack | ||
*/ | ||
|
||
add_action( 'wp_enqueue_scripts', 'e2e_enqueue_assets' ); | ||
|
||
function e2e_enqueue_assets() { | ||
wp_enqueue_script( 'jquery' ); | ||
wp_enqueue_script( 'e2e-script-one', plugins_url( 'assets/e2e-script-one.js', __FILE__ ), array(), '1.0.0', true ); | ||
wp_enqueue_script( 'e2e-script-two', plugins_url( 'assets/e2e-script-two.js', __FILE__ ), array(), '1.0.0', true ); | ||
|
||
wp_enqueue_style( 'e2e-style-one', plugins_url( 'assets/e2e-style-one.css', __FILE__ ), array(), '1.0.0' ); | ||
wp_enqueue_style( 'e2e-style-two', plugins_url( 'assets/e2e-style-two.css', __FILE__ ), array(), '1.0.0' ); | ||
} |
111 changes: 111 additions & 0 deletions
111
projects/plugins/boost/tests/e2e/specs/concatenate/concatenate.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,111 @@ | ||
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'; | ||
import { PostFrontendPage } from 'jetpack-e2e-commons/pages/index.js'; | ||
import playwrightConfig from 'jetpack-e2e-commons/playwright.config.mjs'; | ||
|
||
test.describe( 'Concatenate JS/CSS', () => { | ||
let page; | ||
|
||
test.beforeAll( async ( { browser } ) => { | ||
page = await browser.newPage( playwrightConfig.use ); | ||
await boostPrerequisitesBuilder( page ).withCleanEnv( true ).withConnection( true ).build(); | ||
} ); | ||
|
||
test.afterAll( async () => {} ); | ||
|
||
test( 'No Concatenate meta information should show on the admin when the modules are inactive', async () => { | ||
await boostPrerequisitesBuilder( page ) | ||
.withInactiveModules( [ 'minify_js', 'minify_css' ] ) | ||
.build(); | ||
const jetpackBoostPage = await JetpackBoostPage.visit( page ); | ||
|
||
expect( | ||
await jetpackBoostPage.isConcatenateJsMetaVisible(), | ||
'Concatenate JS meta information should not be visible' | ||
).toBeFalsy(); | ||
expect( | ||
await jetpackBoostPage.isConcatenateCssMetaVisible(), | ||
'Concatenate CSS meta information should not be visible' | ||
).toBeFalsy(); | ||
} ); | ||
|
||
test( 'Concatenation shouldn`t occur when the modules are inactive', async () => { | ||
await boostPrerequisitesBuilder( page ) | ||
.withInactiveModules( [ 'minify_js', 'minify_css' ] ) | ||
.withEnqueuedAssets( true ) | ||
.build(); | ||
const postFrontPage = await PostFrontendPage.visit( page ); | ||
|
||
expect( | ||
// This script is enqueued via a helper plugin. | ||
( await postFrontPage.page.locator( '[id="e2e-script-one-js"]' ).count() ) > 0, | ||
'JS concatenation shouldn`t occur when the module is inactive' | ||
).toBeTruthy(); | ||
expect( | ||
// This style is enqueued via a helper plugin. | ||
( await postFrontPage.page.locator( '[id="e2e-style-one-css"]' ).count() ) > 0, | ||
'CSS concatenation shouldn`t occur when the module is inactive' | ||
).toBeTruthy(); | ||
} ); | ||
|
||
test( 'Meta information should be visible when the modules are active', async () => { | ||
await boostPrerequisitesBuilder( page ) | ||
.withActiveModules( [ 'minify_js', 'minify_css' ] ) | ||
.build(); | ||
const jetpackBoostPage = await JetpackBoostPage.visit( page ); | ||
|
||
expect( | ||
await jetpackBoostPage.isConcatenateJsMetaVisible(), | ||
'Concatenate JS meta information should be visible' | ||
).toBeTruthy(); | ||
expect( | ||
await jetpackBoostPage.isConcatenateCssMetaVisible(), | ||
'Concatenate CSS meta information should be visible' | ||
).toBeTruthy(); | ||
} ); | ||
|
||
test( 'Concatenation occurs when modules are active', async () => { | ||
await boostPrerequisitesBuilder( page ) | ||
.withActiveModules( [ 'minify_js', 'minify_css' ] ) | ||
.withEnqueuedAssets( true ) | ||
.build(); | ||
const postFrontPage = await PostFrontendPage.visit( page ); | ||
|
||
expect( | ||
// e2e-script-one and e2e-script-two are enqueued by a helper plugin. When concatenation is enabled, | ||
// they should be concatenated into a single script. | ||
( await postFrontPage.page | ||
.locator( '[data-handles*="e2e-script-one"][data-handles*="e2e-script-two"]' ) | ||
.count() ) > 0, | ||
'JS Concatenation occurs when module is active' | ||
).toBeTruthy(); | ||
expect( | ||
// e2e-style-one and e2e-style-two are enqueued by a helper plugin. When concatenation is enabled, | ||
// they should be concatenated into a single style. | ||
( await postFrontPage.page | ||
.locator( '[data-handles*="e2e-style-one"][data-handles*="e2e-style-two"]' ) | ||
.count() ) > 0, | ||
'CSS Concatenation occurs when module is active' | ||
).toBeTruthy(); | ||
} ); | ||
|
||
test( 'Assets that are excluded by default shouldn`t be concatenated', async () => { | ||
await boostPrerequisitesBuilder( page ) | ||
.withActiveModules( [ 'minify_js', 'minify_css' ] ) | ||
.withEnqueuedAssets( true ) | ||
.build(); | ||
const postFrontPage = await PostFrontendPage.visit( page ); | ||
|
||
expect( | ||
// jQuery is enqueued by a helper plugin. | ||
( await postFrontPage.page.locator( '[id="jquery-core-js"]' ).count() ) > 0, | ||
'jQuery should not be concatenated' | ||
).toBeTruthy(); | ||
expect( | ||
// Admin bar stylesheet is enqueued by default when logged-in. | ||
( await postFrontPage.page.locator( '[id="admin-bar-css"]' ).count() ) > 0, | ||
'Admin bar stylesheet should not be concatenated' | ||
).toBeTruthy(); | ||
} ); | ||
} ); |
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