Skip to content

Commit ebad439

Browse files
committed
Fix PHP coverage mu-plugin loading and graceful exit
1 parent 7893f00 commit ebad439

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

.wp-env.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"tests": {
66
"mappings": {
77
"wp-content/plugins/secure-custom-fields": ".",
8-
"wp-content/plugins/scf-test-plugins": "./tests/e2e/plugins"
8+
"wp-content/plugins/scf-test-plugins": "./tests/e2e/plugins",
9+
"wp-content/mu-plugins/php-coverage-collector.php": "./tests/e2e/mu-plugins/php-coverage-collector.php"
910
}
1011
}
1112
}

scripts/merge-php-coverage.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,23 @@ function parseArgs() {
5050
/**
5151
* Read all coverage JSON files from the coverage directory.
5252
*
53-
* @return {Array} Array of coverage data objects.
53+
* @return {Array|null} Array of coverage data objects, or null if none found.
5454
*/
5555
function readCoverageFiles() {
5656
if ( ! fs.existsSync( COVERAGE_DIR ) ) {
57-
console.error( `Coverage directory not found: ${ COVERAGE_DIR }` );
58-
process.exit( 1 );
57+
console.log( `No PHP coverage directory found: ${ COVERAGE_DIR }` );
58+
console.log( 'Skipping PHP coverage report generation.' );
59+
return null;
5960
}
6061

6162
const files = fs
6263
.readdirSync( COVERAGE_DIR )
6364
.filter( ( f ) => f.endsWith( '.json' ) );
6465

6566
if ( files.length === 0 ) {
66-
console.error( 'No coverage files found.' );
67-
process.exit( 1 );
67+
console.log( 'No PHP coverage files found.' );
68+
console.log( 'Skipping PHP coverage report generation.' );
69+
return null;
6870
}
6971

7072
console.log( `Found ${ files.length } coverage files.` );
@@ -307,6 +309,12 @@ function main() {
307309
console.log( 'Merging PHP coverage files...' );
308310

309311
const coverageFiles = readCoverageFiles();
312+
313+
if ( coverageFiles === null ) {
314+
// No coverage files found, exit gracefully.
315+
return;
316+
}
317+
310318
const merged = mergeCoverage( coverageFiles );
311319
const stats = calculateStats( merged );
312320

0 commit comments

Comments
 (0)