wip
This commit is contained in:
63
tests/unit/website/getAppMode.test.ts
Normal file
63
tests/unit/website/getAppMode.test.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
|
||||
import { getAppMode, AppMode } from '../../../apps/website/lib/mode';
|
||||
|
||||
const ORIGINAL_NODE_ENV = process.env.NODE_ENV;
|
||||
|
||||
describe('getAppMode', () => {
|
||||
const originalEnv = process.env;
|
||||
|
||||
beforeEach(() => {
|
||||
process.env = { ...originalEnv };
|
||||
process.env.NODE_ENV = 'production';
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
process.env = originalEnv;
|
||||
process.env.NODE_ENV = ORIGINAL_NODE_ENV;
|
||||
});
|
||||
|
||||
it('returns "pre-launch" when NEXT_PUBLIC_GRIDPILOT_MODE is undefined', () => {
|
||||
delete process.env.NEXT_PUBLIC_GRIDPILOT_MODE;
|
||||
|
||||
const mode = getAppMode();
|
||||
|
||||
expect(mode).toBe<AppMode>('pre-launch');
|
||||
});
|
||||
|
||||
it('returns "pre-launch" when NEXT_PUBLIC_GRIDPILOT_MODE is explicitly set to "pre-launch"', () => {
|
||||
process.env.NEXT_PUBLIC_GRIDPILOT_MODE = 'pre-launch';
|
||||
|
||||
const mode = getAppMode();
|
||||
|
||||
expect(mode).toBe<AppMode>('pre-launch');
|
||||
});
|
||||
|
||||
it('returns "alpha" when NEXT_PUBLIC_GRIDPILOT_MODE is set to "alpha"', () => {
|
||||
process.env.NEXT_PUBLIC_GRIDPILOT_MODE = 'alpha';
|
||||
|
||||
const mode = getAppMode();
|
||||
|
||||
expect(mode).toBe<AppMode>('alpha');
|
||||
});
|
||||
|
||||
it('falls back to "pre-launch" and logs when NEXT_PUBLIC_GRIDPILOT_MODE is invalid in production', () => {
|
||||
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
process.env.NEXT_PUBLIC_GRIDPILOT_MODE = 'invalid-mode';
|
||||
|
||||
const mode = getAppMode();
|
||||
|
||||
expect(mode).toBe<AppMode>('pre-launch');
|
||||
expect(consoleError).toHaveBeenCalled();
|
||||
|
||||
consoleError.mockRestore();
|
||||
});
|
||||
|
||||
it('throws in development when NEXT_PUBLIC_GRIDPILOT_MODE is invalid', () => {
|
||||
process.env.NODE_ENV = 'development';
|
||||
process.env.NEXT_PUBLIC_GRIDPILOT_MODE = 'invalid-mode';
|
||||
|
||||
expect(() => getAppMode()).toThrowError(/Invalid NEXT_PUBLIC_GRIDPILOT_MODE/);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user