Skip to content
Merged
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
34 changes: 34 additions & 0 deletions utils/cacheControl.theme-contrast.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { describe, it, expect } from 'vitest';
import { buildCacheControlHeader } from './cacheControl';

describe('cacheControl - Dark and Light Prefers-Color-Scheme Visual Cohesion', () => {
it('returns the default s-maxage header when no options are provided', () => {
const header = buildCacheControlHeader({});
expect(header).toBe('s-maxage=3600, stale-while-revalidate=86400');
});

it('returns a no-store directive when bypass is true, overriding all other options', () => {
const header = buildCacheControlHeader({
bypass: true,
secondsToMidnight: 5000,
isHistoricalYear: true,
});
expect(header).toBe('no-cache, no-store, must-revalidate');
});

it('returns an immutable cache header when isHistoricalYear is set', () => {
const header = buildCacheControlHeader({ isHistoricalYear: true });
expect(header).toBe('public, s-maxage=31536000, immutable');
});

it('includes secondsToMidnight in the s-maxage when provided without bypass or historical', () => {
const header = buildCacheControlHeader({ secondsToMidnight: 7200 });
expect(header).toMatch(/^public, s-maxage=7200,/);
expect(header).toContain('stale-while-revalidate=86400');
});

it('handles secondsToMidnight of zero correctly, producing s-maxage=0', () => {
const header = buildCacheControlHeader({ secondsToMidnight: 0 });
expect(header).toBe('public, s-maxage=0, stale-while-revalidate=86400');
});
});
Loading