mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-12-01 20:39:26 -06:00
Fix serving of favicons
This commit is contained in:
@@ -108,22 +108,3 @@ export async function setupStaticMiddleware(options: ServerOptions, router: Rout
|
||||
|
||||
return createDefaultPugRequireHandler(options.staticRoot, staticManifest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the appropriate favicon filename based on the environment
|
||||
* @param isDevMode - Whether the app is running in development mode
|
||||
* @param env - The environment names array
|
||||
* @returns The favicon filename to use
|
||||
*/
|
||||
export function getFaviconFilename(isDevMode: boolean, env?: string[]): string {
|
||||
if (isDevMode) {
|
||||
return 'favicon-dev.ico';
|
||||
}
|
||||
if (env?.includes('beta')) {
|
||||
return 'favicon-beta.ico';
|
||||
}
|
||||
if (env?.includes('staging')) {
|
||||
return 'favicon-staging.ico';
|
||||
}
|
||||
return 'favicon.ico';
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import {describe, expect, it, vi} from 'vitest';
|
||||
import {createDefaultPugRequireHandler, getFaviconFilename} from '../../lib/app/static-assets.js';
|
||||
import {createDefaultPugRequireHandler} from '../../lib/app/static-assets.js';
|
||||
|
||||
// Mock the logger
|
||||
vi.mock('../../lib/logger.js', () => ({
|
||||
@@ -108,40 +108,4 @@ describe('Static assets', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFaviconFilename', () => {
|
||||
it('should prioritize dev environment over other environments', () => {
|
||||
// Dev mode favicon should be used regardless of environment flags
|
||||
expect(getFaviconFilename(true, [])).toContain('dev');
|
||||
expect(getFaviconFilename(true, ['beta'])).toContain('dev');
|
||||
expect(getFaviconFilename(true, ['staging'])).toContain('dev');
|
||||
expect(getFaviconFilename(true, ['beta', 'staging'])).toContain('dev');
|
||||
});
|
||||
|
||||
it('should select appropriate favicon based on environment', () => {
|
||||
// Test specific environments when not in dev mode
|
||||
const environments = [
|
||||
{env: ['beta'], expected: 'beta'},
|
||||
{env: ['staging'], expected: 'staging'},
|
||||
{env: [], expected: 'favicon.ico'},
|
||||
];
|
||||
|
||||
for (const {env, expected} of environments) {
|
||||
const result = getFaviconFilename(false, env);
|
||||
if (expected === 'favicon.ico') {
|
||||
expect(result).toBe(expected);
|
||||
} else {
|
||||
expect(result).toContain(expected);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('should handle environment arrays with mixed values', () => {
|
||||
// When multiple environments are specified, there should be a consistent priority
|
||||
expect(getFaviconFilename(false, ['beta', 'staging'])).toContain('beta');
|
||||
expect(getFaviconFilename(false, ['staging', 'beta'])).toContain('beta');
|
||||
expect(getFaviconFilename(false, ['other', 'beta'])).toContain('beta');
|
||||
expect(getFaviconFilename(false, ['other', 'staging'])).toContain('staging');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user