Make WordPress Core

Changeset 59356


Ignore:
Timestamp:
11/05/2024 07:59:49 PM (5 weeks ago)
Author:
desrosj
Message:

Build/Test Tools: Add script for generating code coverage report.

This adds documentation for how to generate code coverage reports to the README.md file.

test:coverage has also been added as an npm script to make it easier to generate a report using the local Docker environment. The script will generate an HTML, PHP, and text report file.

Props pbearne, hellofromTonya, netweb.
Fixes #53414.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        1919/docker-compose.override.yml
        2020.env
         21coverage
  • trunk/.gitignore

    r59146 r59356  
    4343/artifacts
    4444/setup.log
     45/coverage
    4546
    4647# Files and folders that get created in wp-content
  • trunk/README.md

    r57987 r59356  
    9595```
    9696
     97#### Generating a code coverage report
     98PHP code coverage reports are [generated daily](https://github.com/WordPress/wordpress-develop/actions/workflows/test-coverage.yml) and [submitted to Codecov.io](https://app.codecov.io/gh/WordPress/wordpress-develop).
     99
     100After the local Docker environment has [been installed and started](#to-start-the-development-environment-for-the-first-time), the following command can be used to generate a code coverage report.
     101
     102```
     103npm run test:coverage
     104```
     105
     106The command will generate three coverage reports in HTML, PHP, and text formats, saving them in the `coverage` folder.
     107
     108**Note:** xDebug is required to generate a code coverage report, which can slow down PHPUnit significantly. Passing selection-based options such as `--group` or `--filter` can decrease the overall time required but will result in an incomplete report.
     109
    97110#### To restart the development environment
    98111
  • trunk/package.json

    r59347 r59356  
    191191        "test:performance": "wp-scripts test-playwright --config tests/performance/playwright.config.js",
    192192        "test:php": "node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit",
     193        "test:coverage": "npm run test:php -- --coverage-html ./coverage/html/ --coverage-php ./coverage/php/report.php --coverage-text=./coverage/text/report.txt",
    193194        "test:e2e": "wp-scripts test-playwright --config tests/e2e/playwright.config.js",
    194195        "test:visual": "wp-scripts test-playwright --config tests/visual-regression/playwright.config.js",
  • trunk/tools/local-env/scripts/docker.js

    r59279 r59356  
    88const composeFiles = local_env_utils.get_compose_files();
    99
     10if (process.argv.includes('--coverage-html')) {
     11    process.env.LOCAL_PHP_XDEBUG = 'true';
     12    process.env.LOCAL_PHP_XDEBUG_MODE = 'coverage';
     13}
     14
    1015// Execute any docker compose command passed to this script.
    1116execSync( 'docker compose ' + composeFiles + ' ' + process.argv.slice( 2 ).join( ' ' ), { stdio: 'inherit' } );
Note: See TracChangeset for help on using the changeset viewer.