Skip to content

Prevent effective asset cache headers audit from running on local/development environments #2035

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

Merged
merged 7 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@
* @return array{direct: array<string, array{label: string, test: string}>} Amended tests.
*/
function perflab_effective_asset_cache_headers_add_test( array $tests ): array {
$tests['direct']['effective_asset_cache_headers'] = array(
'label' => __( 'Effective Caching Headers', 'performance-lab' ),
'test' => 'perflab_effective_asset_cache_headers_assets_test',
);
/*
* Static assets are expected to not have effective cache headers in non-production environments.
*
* GH Issue: https://github.com/WordPress/performance/issues/2031
*/
if ( ! in_array( wp_get_environment_type(), array( 'local', 'development' ), true ) ) {
$tests['direct']['effective_asset_cache_headers'] = array(
'label' => __( 'Effective Caching Headers', 'performance-lab' ),
'test' => 'perflab_effective_asset_cache_headers_assets_test',
);

Check warning on line 34 in plugins/performance-lab/includes/site-health/effective-asset-cache-headers/hooks.php

View check run for this annotation

Codecov / codecov/patch

plugins/performance-lab/includes/site-health/effective-asset-cache-headers/hooks.php#L31-L34

Added lines #L31 - L34 were not covered by tests
}

return $tests;
}
add_filter( 'site_status_tests', 'perflab_effective_asset_cache_headers_add_test' );
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public function test_perflab_effective_asset_cache_headers_add_test(): void {

$tests = perflab_effective_asset_cache_headers_add_test( $tests );

$this->assertArrayHasKey( 'effective_asset_cache_headers', $tests['direct'] );
$this->assertEquals( 'Effective Caching Headers', $tests['direct']['effective_asset_cache_headers']['label'] );
$this->assertEquals( 'perflab_effective_asset_cache_headers_assets_test', $tests['direct']['effective_asset_cache_headers']['test'] );
$this->assertArrayNotHasKey( 'effective_asset_cache_headers', $tests['direct'] );
}

/**
Expand Down
Loading