Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
bfbb5d0
Enable single quotes in yml
thelovekesh Feb 24, 2024
5cfcd3d
Add setup-wp-tests composite action
thelovekesh Feb 24, 2024
ae4391e
Update wp tests setup script path
thelovekesh Mar 20, 2024
f319d67
Update PHP Unit tests workflow
thelovekesh Mar 21, 2024
b7098e8
Update PHP Unit tests workflow for PL plugin
thelovekesh Mar 21, 2024
7326514
Update PHP Unit tests workflow for standalone plugins
thelovekesh Mar 21, 2024
4dff72d
Add tests bootstrap helper functions
thelovekesh Mar 22, 2024
ed013da
Update PL plugin tests bootstrap file
thelovekesh Mar 22, 2024
7ec118b
Move auto-sizes tests to plugins/auto-sizes/tests
thelovekesh Mar 22, 2024
0bc071f
Move dominant-color-images tests to plugins/dominant-color-images/tests
thelovekesh Mar 22, 2024
95477f6
Move embed-optimizer tests to plugins/embed-optimizer/tests
thelovekesh Mar 22, 2024
a89b584
Move speculation-rules tests to plugins/speculation-rules/tests
thelovekesh Mar 22, 2024
23c78c6
Move webp-uploads tests to plugins/webp-uploads/tests
thelovekesh Mar 22, 2024
2fc36f0
Update PL PHPUnit config
thelovekesh Mar 22, 2024
8f2db86
Add PHPUnit config for all standalone plugins
thelovekesh Mar 22, 2024
3150c36
Remove redundant file
thelovekesh Mar 22, 2024
92cba14
Add tests bootstrap file for standalone plugins
thelovekesh Mar 22, 2024
8b5df2f
Move testcases abstract classes to respective plugin tests directory
thelovekesh Mar 22, 2024
88d6e86
Move webp-uploads PHPUnit constraints to it's tests directory
thelovekesh Mar 22, 2024
8b93bcd
Update images path
thelovekesh Mar 22, 2024
f43b497
Update dominant-color-images plugin tests
thelovekesh Mar 22, 2024
0a29cba
Add trailing dot
thelovekesh Mar 22, 2024
2b5a6e3
Update webp-uploads plugin tests
thelovekesh Mar 22, 2024
ba366f2
Rename webp-uploads tests/helpers to tests/data
thelovekesh Mar 22, 2024
7bc326e
Autoload tests files
thelovekesh Mar 22, 2024
5273312
Remove redundant PHPUnit constraints file
thelovekesh Mar 22, 2024
19f25d8
Rename testdata to data and remove modules tests/data
thelovekesh Mar 22, 2024
45b9687
Move site health tests helpers to data directory
thelovekesh Mar 22, 2024
26b2c77
Update global data/images path in test cases
thelovekesh Mar 22, 2024
92bee06
Update CODEOWNERS
thelovekesh Mar 22, 2024
5abb8f7
Update tests environment matrix
thelovekesh Mar 22, 2024
e341854
Fix typo
thelovekesh Mar 22, 2024
b472c00
Update CODEOWNERS
thelovekesh Mar 27, 2024
7d49c26
Revert PHPUnit tests workflow migration to install-wp-tests.sh
thelovekesh Mar 27, 2024
c91cff8
Move optimization-detective tests to plugins/optimization-detective/t…
thelovekesh Mar 27, 2024
517286c
Remove composer autoloading from tests
thelovekesh Mar 27, 2024
01a47d1
Add PHPUnit config for optimization-detective
thelovekesh Mar 27, 2024
a5d95e6
Update ignoreFiles to include tests in plugins builds
thelovekesh Mar 27, 2024
4c5c45f
Move helper files to data directory
thelovekesh Mar 27, 2024
01a64be
Revert autloading for composer dependencies
thelovekesh Mar 27, 2024
4f53252
Load helpers for webp-uplaods while bootstraping tests
thelovekesh Mar 27, 2024
0fbf6dc
Load helpers for dominant-color-images while bootstraping tests
thelovekesh Mar 27, 2024
0533572
Fix tests suffix
thelovekesh Mar 27, 2024
18bb970
Move tests scripts from composer to npm
thelovekesh Mar 27, 2024
90e161b
Update tests commands in workflows
thelovekesh Mar 27, 2024
2237ba0
Remove unused tests group
thelovekesh Mar 27, 2024
62cdaae
Update multisite tests command
thelovekesh Mar 27, 2024
c8fa1fd
Remove multisite.xml
thelovekesh Mar 27, 2024
5d74c29
Fix test:php:multisite command
thelovekesh Mar 27, 2024
ebb7d8f
Remove multisite.xml from workflow paths
thelovekesh Mar 27, 2024
1b7f334
Fix admin path in CODEOWNERS
thelovekesh Mar 28, 2024
51b4a9b
Fix WP src directory path
thelovekesh Mar 29, 2024
8baa7b6
Add cross-env package
thelovekesh Apr 8, 2024
482b822
Add info format
thelovekesh Apr 10, 2024
7b55708
Add PHPUnit tests runner script
thelovekesh Apr 10, 2024
fbd4b9a
Update test:php scripts
thelovekesh Apr 10, 2024
d5300d6
Update plugins multisite tests command
thelovekesh Apr 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ insert_final_newline = false
quote_type = single
indent_style = space
indent_size = 2
quote_type = single

[.github/CODEOWNERS]
indent_style = space
27 changes: 11 additions & 16 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Documentation/Infrastructure
/admin @mukeshpanchal27 @felixarntz
/tests/admin @mukeshpanchal27 @felixarntz
/.github @mukeshpanchal27 @felixarntz
/bin @mukeshpanchal27 @felixarntz
/.github @mukeshpanchal27 @felixarntz @thelovekesh

# Admin: Performance Lab
/includes/admin @mukeshpanchal27 @felixarntz
/tests/includes/admin @mukeshpanchal27 @felixarntz

# Site Health: WebP Support Health Check
/includes/site-health/webp-support @adamsilverstein
Expand All @@ -14,28 +16,21 @@
# Site Health: Enqueued Assets Health Check
/includes/site-health/audit-enqueued-assets @manuelRod
/tests/includes/site-health/audit-enqueued-assets @manuelRod
/tests/testdata/modules/site-health/audit-enqueued-assets @manuelRod

# Plugin: Auto-sizes for Lazy-Loaded Images
/plugins/auto-sizes @joemcgill
/tests/plugins/auto-sizes @joemcgill

# Plugin: Speculative Loading
/plugins/speculation-rules @felixarntz
/tests/plugins/speculation-rules @felixarntz

# Plugin: Modern Image Formats
/plugins/webp-uploads @adamsilverstein @felixarntz
/tests/plugins/webp-uploads @adamsilverstein @felixarntz

# Plugin: Image Placeholders
/plugins/dominant-color-images @pbearne @spacedmonkey
/tests/plugins/dominant-color-images @pbearne @spacedmonkey

# Plugin: Embed Optimizer
/plugins/embed-optimizer @adamsilverstein @westonruter
/tests/plugins/embed-optimizer @adamsilverstein @westonruter

# Plugin: Optimization Detective
/plugins/optimization-detective @westonruter @felixarntz
/tests/plugins/optimization-detective @westonruter @felixarntz

# Plugin: Speculative Loading
/plugins/speculation-rules @felixarntz

# Plugin: Modern Image Formats
/plugins/webp-uploads @adamsilverstein @felixarntz
12 changes: 5 additions & 7 deletions .github/workflows/php-test-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ on:
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- 'tests/multisite.xml'
- 'composer.json'
- 'composer.lock'
pull_request:
Expand All @@ -25,7 +24,6 @@ on:
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- 'tests/multisite.xml'
- 'composer.json'
- 'composer.lock'
types:
Expand All @@ -52,10 +50,10 @@ jobs:
WP_ENV_PHP_VERSION: ${{ matrix.php }}
WP_ENV_CORE: ${{ matrix.wp == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wp ) }}
steps:
- uses: styfle/cancel-workflow-action@0.12.1
- uses: actions/checkout@v4
- uses: styfle/cancel-workflow-action@0.11.0
- uses: actions/checkout@v3
- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@v4
uses: actions/setup-node@v3
Comment on lines -55 to +56
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be reverted as trunk now have latest dependancy.

with:
node-version-file: '.nvmrc'
cache: npm
Expand All @@ -71,6 +69,6 @@ jobs:
- name: Composer update
run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer update --no-interaction
- name: Running single site unit tests for plugins
run: npm run test-php-plugins
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you removed multisite.xml, Could you remove tests/multisite.xml?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did that in bd66bb9

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean we should remove that file reference from workflow file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh okay. Done in 61eb092.

run: npm run test:php:plugins
- name: Running multisite unit tests for plugins
run: npm run test-php-multisite-plugins
run: npm run test:php:plugins:multisite
12 changes: 5 additions & 7 deletions .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ on:
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- 'tests/multisite.xml'
- 'composer.json'
- 'composer.lock'
pull_request:
Expand All @@ -25,7 +24,6 @@ on:
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- 'tests/multisite.xml'
- 'composer.json'
- 'composer.lock'
types:
Expand Down Expand Up @@ -53,10 +51,10 @@ jobs:
WP_ENV_PHP_VERSION: ${{ matrix.php }}
WP_ENV_CORE: ${{ matrix.wp == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wp ) }}
steps:
- uses: styfle/cancel-workflow-action@0.12.1
- uses: actions/checkout@v4
- uses: styfle/cancel-workflow-action@0.11.0
- uses: actions/checkout@v3
- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@v4
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm
Expand All @@ -72,6 +70,6 @@ jobs:
- name: Composer update
run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer update --no-interaction
- name: Running single site unit tests
run: npm run test-php
run: npm run test:php
- name: Running multisite unit tests
run: npm run test-php-multisite
run: npm run test:php:multisite
89 changes: 89 additions & 0 deletions bin/phpunit/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* External dependencies
*/
const path = require( 'path' );
const { spawnSync } = require( 'child_process' );

/**
* Internal dependencies
*/
const { plugins } = require( '../../plugins.json' );
const { formats } = require( '../plugin/lib/logger' );

const args = process.argv.slice( 2 );
const { WPP_PLUGIN, WPP_MULTISITE } = process.env;
const pluginBasePath = path.resolve( __dirname, '../../' );
const pluginBaseName = path.basename( pluginBasePath );
const pluginsDir = path.resolve( pluginBasePath, 'plugins' );
const phpunitBin = path.resolve( pluginBasePath, 'vendor/bin/phpunit' );
const wpEnvBin = path.resolve( pluginBasePath, 'node_modules/.bin/wp-env' );
const wpPluginsDir = `/var/www/html/wp-content/plugins/${ pluginBaseName }`;

const _plugins = []; // Store absolute paths to plugins.

if ( WPP_PLUGIN ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thelovekesh Unrelated to the ongoing discussion in #1012: If we implement new JS tooling scripts like this, I think they should be incorporated into the existing foundation in bin/plugin. It uses commander for a full CLI suite, which has some benefits like built-in help / documentation functionality and error handling infrastructure. This could be reused rather than implementing standalone commands like this.

if (
'performance-lab' !== WPP_PLUGIN &&
! plugins.includes( WPP_PLUGIN )
) {
// eslint-disable-next-line no-console
console.error(
formats.error(
`The plugin ${ WPP_PLUGIN } is not a valid plugin managed as part of this project.`
)
);
Comment on lines +29 to +34
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we utilize log from require( '../plugin/lib/logger' )?

Suggested change
// eslint-disable-next-line no-console
console.error(
formats.error(
`The plugin ${ WPP_PLUGIN } is not a valid plugin managed as part of this project.`
)
);
log(
formats.error(
`The plugin ${ WPP_PLUGIN } is not a valid plugin managed as part of this project.`
)
);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think better to use console.error() as it goes to STDERR instead of STDOUT.

Otherwise, this could be added to logger as an alias in the same way that was done for console.log.


process.exit( 1 );
}

if ( 'performance-lab' === WPP_PLUGIN ) {
_plugins.push( pluginBasePath );
} else {
_plugins.push( path.resolve( pluginsDir, WPP_PLUGIN ) );
}
} else {
plugins.forEach( ( plugin ) => {
_plugins.push( path.resolve( pluginsDir, plugin ) );
} );
}

const wpEnvRunArgs = {}; // Store plugin name with args provided to wp-env run command.

_plugins.forEach( ( plugin ) => {
const command = [
'run',
'tests-cli',
`--env-cwd=${ plugin.replace( pluginBasePath, wpPluginsDir ) }`,
];

if ( WPP_MULTISITE ) {
command.push( 'env', 'WP_MULTISITE=1' );
}

command.push( phpunitBin.replace( pluginBasePath, wpPluginsDir ) );

if ( WPP_MULTISITE ) {
command.push( '--exclude-group', 'ms-excluded' );
}

if ( args.length ) {
command.push( ...args );
}

wpEnvRunArgs[ path.basename( plugin ) ] = command;
} );

for ( const [ plugin, command ] of Object.entries( wpEnvRunArgs ) ) {
if ( Object.keys( wpEnvRunArgs ).length > 1 ) {
// eslint-disable-next-line no-console
console.log( formats.info( `\n> Running tests for ${ plugin }` ) );
}

// Execute tests synchronously for the sake of async fs.stat in loop.
// fs.stat is used by wp-env to determine if `/snap` is available on user's system.
const _process = spawnSync( wpEnvBin, command, { stdio: 'inherit' } );

if ( _process.signal ) {
process.exit( 1 );
}
}
2 changes: 2 additions & 0 deletions bin/plugin/lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const title = chalk.bold;
const error = chalk.bold.red;
const warning = chalk.bold.keyword( 'orange' );
const success = chalk.bold.green;
const info = chalk.bold.blue;

const log = console.log; // eslint-disable-line no-console

Expand All @@ -17,5 +18,6 @@ module.exports = {
error,
warning,
success,
info,
},
};
46 changes: 2 additions & 44 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"post-install-cmd": "if php -r 'exit( version_compare( phpversion(), \"8.1\", \">=\" ) ? 0 : 1 );'; then composer --working-dir=build-cs install --no-interaction; else echo 'Skipping composer install for build-cs since not on PHP 8.1+. You are running: '; php -v; fi",
"post-update-cmd": "if php -r 'exit( version_compare( phpversion(), \"8.1\", \">=\" ) ? 0 : 1 );'; then composer --working-dir=build-cs update --no-interaction; else echo 'Skipping composer update for build-cs since not on PHP 8.1+. You are running: '; php -v; fi",
"phpstan": "build-cs/vendor/bin/phpstan analyse --memory-limit=2048M",
"phpunit": "phpunit --verbose",
"format": "build-cs/vendor/bin/phpcbf --report-summary --report-source",
"lint": "build-cs/vendor/bin/phpcs",
"lint:all": [
Expand All @@ -41,56 +42,13 @@
"lint:embed-optimizer": "@lint -- ./plugins/embed-optimizer --standard=./plugins/embed-optimizer/phpcs.xml.dist",
"lint:optimization-detective": "@lint -- ./plugins/optimization-detective --standard=./plugins/optimization-detective/phpcs.xml.dist",
"lint:speculation-rules": "@lint -- ./plugins/speculation-rules --standard=./plugins/speculation-rules/phpcs.xml.dist",
"lint:webp-uploads": "@lint -- ./plugins/webp-uploads --standard=./plugins/webp-uploads/phpcs.xml.dist",
"test": "phpunit --verbose --testsuite performance-lab",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove all of the test scripts from composer? I think it would be better if scripts that rely on PHP functionality were maintained in the composer.json and provide a node script that referenced composer than moving all of these over to the package.json file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joemcgill @felixarntz In conjunction with both this and #1065 (comment), I have added a node script to run PHPUnit tests in 0ba78d9 and added the scripts in package.json due to some NPM specific features.

Now the commands works like:

npm run test:php # Run tests for PL plugin
npm run test:php:plugins # Run tests for all plugins
npm run test:php:plugins --plugin=foo # Run tests for foo plugin
npm run test:php:plugins --plugin=foo -- --phpunit-args # Run tests for foo plugin and pass args to PHPUnit.
// ... and same as above for mutlsite just need to append :multisite in commands.

Please LMKWYT.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice. Previously in order to run just the tests for Optimization Detective, I would do this:

npm run wp-env run tests-cli bash

And then in the container:

cd wp-content/plugins/performance/
composer run-script test:optimization-detective # (run as many times as needed)

Great to have a command to run just one plugin's tests:

npm run test:php:plugins --plugin=optimization-detective

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more advantage is, that you can now pass args to PHPUnit by escaping once only like:

npm run test:php:plugins --plugin=optimization-detective -- --filter=Foo_Tests

is makes it more better IMO.

"test-multisite": "phpunit -c tests/multisite.xml --verbose --testsuite performance-lab",
"test:all": [
"@test",
"@test:plugins"
],
"test-multisite:all": [
"@test-multisite",
"@test-multisite:plugins"
],
"test:plugins": [
"@test:auto-sizes",
"@test:dominant-color-images",
"@test:embed-optimizer",
"@test:optimization-detective",
"@test:speculation-rules",
"@test:webp-uploads"
],
"test-multisite:plugins": [
"@test-multisite:auto-sizes",
"@test-multisite:dominant-color-images",
"@test-multisite:embed-optimizer",
"@test-multisite:optimization-detective",
"@test-multisite:speculation-rules",
"@test-multisite:webp-uploads"
],
"test:auto-sizes": "phpunit --verbose --testsuite auto-sizes",
"test-multisite:auto-sizes": "phpunit -c tests/multisite.xml --verbose --testsuite auto-sizes",
"test:dominant-color-images": "phpunit --verbose --testsuite dominant-color-images",
"test-multisite:dominant-color-images": "phpunit -c tests/multisite.xml --verbose --testsuite dominant-color-images",
"test:embed-optimizer": "phpunit --verbose --testsuite embed-optimizer",
"test-multisite:embed-optimizer": "phpunit -c tests/multisite.xml --verbose --testsuite embed-optimizer",
"test:optimization-detective": "phpunit --verbose --testsuite optimization-detective",
"test-multisite:optimization-detective": "phpunit -c tests/multisite.xml --verbose --testsuite optimization-detective",
"test:speculation-rules": "phpunit --verbose --testsuite speculation-rules",
"test-multisite:speculation-rules": "phpunit -c tests/multisite.xml --verbose --testsuite speculation-rules",
"test:webp-uploads": "phpunit --verbose --testsuite webp-uploads",
"test-multisite:webp-uploads": "phpunit -c tests/multisite.xml --verbose --testsuite webp-uploads"
"lint:webp-uploads": "@lint -- ./plugins/webp-uploads --standard=./plugins/webp-uploads/phpcs.xml.dist"
},
"config": {
"allow-plugins": {
"composer/installers": true,
"phpstan/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"autoload-dev": {
"psr-4": {
"PerformanceLab\\Tests\\": "tests/utils"
}
}
}
69 changes: 69 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading