Skip to content

Commit fe89427

Browse files
authored
Merge pull request #2035 from hbhalodia/feat/issue-2031
Effective asset cache headers audit should not fail when on local/development environments
2 parents e741539 + f56f9d6 commit fe89427

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@
2222
* @return array{direct: array<string, array{label: string, test: string}>} Amended tests.
2323
*/
2424
function perflab_effective_asset_cache_headers_add_test( array $tests ): array {
25-
$tests['direct']['effective_asset_cache_headers'] = array(
26-
'label' => __( 'Effective Caching Headers', 'performance-lab' ),
27-
'test' => 'perflab_effective_asset_cache_headers_assets_test',
28-
);
25+
/*
26+
* Static assets are expected to not have effective cache headers in non-production environments.
27+
*
28+
* GH Issue: https://github.com/WordPress/performance/issues/2031
29+
*/
30+
if ( ! in_array( wp_get_environment_type(), array( 'local', 'development' ), true ) ) {
31+
$tests['direct']['effective_asset_cache_headers'] = array(
32+
'label' => __( 'Effective Caching Headers', 'performance-lab' ),
33+
'test' => 'perflab_effective_asset_cache_headers_assets_test',
34+
);
35+
}
36+
2937
return $tests;
3038
}
3139
add_filter( 'site_status_tests', 'perflab_effective_asset_cache_headers_add_test' );

plugins/performance-lab/tests/includes/site-health/effective-asset-cache-headers/test-effective-asset-cache-headers.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ public function test_perflab_effective_asset_cache_headers_add_test(): void {
4040

4141
$tests = perflab_effective_asset_cache_headers_add_test( $tests );
4242

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

4846
/**

0 commit comments

Comments
 (0)