Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Measure Code Coverage #2434

Merged
merged 31 commits into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0b6c24b
Measure code coverage on CI
swissspidy May 27, 2019
b4bb637
Disable Xdebug when not needed
swissspidy May 27, 2019
dabe9b7
Simplify maybe_disable_xdebug
swissspidy May 27, 2019
1f218fc
Specify coverageDirectory for JS unit tests
swissspidy May 27, 2019
16a2177
Actually require php-coveralls/php-coveralls
swissspidy May 27, 2019
0c71d08
Simplify xdebug / coveralls logic
swissspidy May 27, 2019
419e7c6
Fix typo
swissspidy May 27, 2019
5c14875
Try codecov
swissspidy May 29, 2019
aefaa2e
Merge branch 'develop' into add/coveralls
swissspidy May 29, 2019
9c95938
Trigger build
swissspidy May 29, 2019
46119b9
Tweak coveragePathIgnorePatterns
swissspidy May 29, 2019
629a94e
Abort with clear message on CI if dependencies are not satisfied
swissspidy May 29, 2019
712e5a4
Merge branch 'develop' into add/coveralls
swissspidy May 29, 2019
d034fd0
Use exit code on CI instead of return
swissspidy May 29, 2019
3b27c05
Run missing JS build for coverage job
swissspidy May 29, 2019
3a2f867
Add missing echo
westonruter May 29, 2019
60ba172
Use latest WP for code coverage analysis
swissspidy May 29, 2019
92cd9c5
Add missing echo
swissspidy May 29, 2019
460075d
Explicitly collect JS coverage data
swissspidy May 29, 2019
5e58769
Fix invalid covers annotations
swissspidy May 29, 2019
debc120
Pass file name to codecov
swissspidy May 29, 2019
8b5e13a
Remove logging entry in phpunit
swissspidy May 30, 2019
f3b4bba
Try overriding function from dev-lib
swissspidy May 30, 2019
4dd8139
Debug: Try creating clover.xml in root folder
swissspidy May 30, 2019
89cffd3
Ignore bin directory from code coverage
swissspidy May 31, 2019
6ba5188
Check for PHP_SAPI as well
swissspidy May 31, 2019
c8c39f9
Change back path to clover.xml
swissspidy May 31, 2019
6913434
Use absolute path to clover.xml file
swissspidy May 31, 2019
9fbaca5
Disable phpcs false positive
swissspidy May 31, 2019
338d13a
Add some debugging commands
swissspidy May 31, 2019
140e6b3
Remove duplicated -f flag 🤦‍♂️
swissspidy May 31, 2019
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
8 changes: 8 additions & 0 deletions .dev-lib
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

DEFAULT_BASE_BRANCH=develop
ASSETS_DIR=wp-assets
PROJECT_SLUG=amp
Expand Down Expand Up @@ -26,3 +28,9 @@ function after_wp_install {
echo "done"
fi
}

function coverage_clover {
if [[ ! -z $RUN_PHPUNIT_COVERAGE ]]; then
echo --coverage-clover build/logs/clover.xml
fi
}
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ install:
- export DEV_LIB_PATH=vendor/xwp/wp-dev-lib/scripts
- source "$DEV_LIB_PATH/travis.install.sh"

before_script:
- phpenv config-rm xdebug.ini || echo "xdebug.ini does not exist."

script:
- npm run build:js
- source "$DEV_LIB_PATH/travis.script.sh"
Expand All @@ -48,12 +51,14 @@ jobs:
fast_finish: true
allow_failures:
- stage: bleeding-edge
- stage: coverage
include:
- stage: lint
name: Lint (PHP, JavaScript, and configuration files)
php: "7.3"
env: WP_VERSION=latest DEV_LIB_ONLY=phpsyntax
before_script:
- phpenv config-rm xdebug.ini || echo "xdebug.ini does not exist."
- composer require --dev localheinz/composer-normalize --ignore-platform-reqs
script:
- source "$DEV_LIB_PATH/travis.script.sh"
Expand Down Expand Up @@ -110,6 +115,20 @@ jobs:
php: "7.3"
env: WP_VERSION=trunk DEV_LIB_ONLY=phpunit INSTALL_PWA_PLUGIN=1

- stage: coverage
name: PHP and JavaScript unit tests (7.3, WordPress trunk, with code coverage)
if: branch = develop
php: "7.3"
env: WP_VERSION=latest DEV_LIB_ONLY=phpunit INSTALL_PWA_PLUGIN=1 RUN_PHPUNIT_COVERAGE=1
before_script:
- echo "Running unit tests with code coverage..."
script:
- npm run build:js
- source "$DEV_LIB_PATH/travis.script.sh"
- bash <(curl -s https://codecov.io/bash) -cF php -f /tmp/wordpress/src/wp-content/plugins/amp/build/logs/clover.xml
- npm run test:js -- --collectCoverage
- bash <(curl -s https://codecov.io/bash) -cF javascript -f build/logs/lcov.info

- stage: deploy
if: type = push AND fork = false AND ( branch =~ ^[a-z][a-z0-9-]{0,10}$ OR branch =~ ^[0-9]+\.[0-9]+$ ) AND NOT branch IN ( live, test, dev, settings, team, support, debug, multidev, files, tags, billing )
php: "7.1"
Expand Down
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module.exports = function( grunt ) {
const versionAppend = new Date().toISOString().replace( /\.\d+/, '' ).replace( /-|:/g, '' ) + '-' + commitHash;

const paths = lsOutput.trim().split( /\n/ ).filter( function( file ) {
return ! /^(blocks|\.|bin|([^/]+)+\.(md|json|xml)|Gruntfile\.js|postcss\.config\.js|tests|wp-assets|readme\.md|composer\..*|patches|webpack.*|assets\/src|docker-compose\.yml|babel\.config\.js)/.test( file );
return ! /^(blocks|\.|bin|([^/]+)+\.(md|json|xml)|Gruntfile\.js|postcss\.config\.js|tests|wp-assets|readme\.md|composer\..*|patches|webpack.*|assets\/src|docker-compose\.yml|babel\.config\.js|codecov\.yml)/.test( file );
} );

paths.push( 'vendor/autoload.php' );
Expand Down
11 changes: 10 additions & 1 deletion amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,24 @@ function _amp_show_load_errors_admin_notice() {
// Abort if dependencies are not satisfied.
if ( ! empty( $_amp_load_errors->errors ) ) {
add_action( 'admin_notices', '_amp_show_load_errors_admin_notice' );
if ( defined( 'WP_CLI' ) && WP_CLI ) {

if ( ( defined( 'WP_CLI' ) && WP_CLI ) || 'true' === getenv( 'CI' ) || 'cli' === PHP_SAPI ) {
$messages = array( __( 'AMP plugin unable to initialize.', 'amp' ) );
foreach ( array_keys( $_amp_load_errors->errors ) as $error_code ) {
$messages = array_merge( $messages, $_amp_load_errors->get_error_messages( $error_code ) );
}
$message = implode( "\n * ", $messages );
$message = str_replace( array( '<code>', '</code>' ), '`', $message );

if ( ! class_exists( 'WP_CLI' ) ) {
echo "$message\n"; // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped

exit( 1 );
}

WP_CLI::warning( $message );
}

return;
}

Expand Down
12 changes: 12 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
coverage:
status:
patch: false
changes: false
project:
default:
target: auto

comment: off

ignore:
- "/bin"
3 changes: 3 additions & 0 deletions tests/unit/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ module.exports = {
'<rootDir>/build',
'.*/e2e/.*',
],
coveragePathIgnorePatterns: [ '/node_modules/', '<rootDir>/build/', '<rootDir>/assets/src/test/helpers/' ],
coverageReporters: [ 'lcov' ],
coverageDirectory: '<rootDir>/build/logs',
};
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ public function test_filter_the_title_in_post_list_table() {
/**
* Test render_post_filters.
*
* @covers \AMP_Validation_Error_Taxonomy::render_post_filters()
* @covers \AMP_Validated_URL_Post_Type::render_post_filters()
*/
public function test_render_post_filters() {
set_current_screen( 'edit.php' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ public function test_filter_posts_where_for_validation_error_status() {
/**
* Test summarize_validation_errors.
*
* @covers AMP_Validation_Manager::summarize_validation_errors()
* @covers AMP_Validation_Error_Taxonomy::summarize_validation_errors()
*/
public function test_summarize_validation_errors() {
$attribute_node_name = 'button';
Expand Down