mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-28 08:49:38 +02:00
Initial open-source release
This commit is contained in:
commit
1a42152e6f
1199 changed files with 257054 additions and 0 deletions
60
packages/cli/src/io/mode.test.ts
Normal file
60
packages/cli/src/io/mode.test.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import type { KloCliIo } from '../cli-runtime.js';
|
||||
import { resolveOutputMode } from './mode.js';
|
||||
|
||||
function ioWith(isTTY: boolean | undefined): KloCliIo {
|
||||
return {
|
||||
stdout: { isTTY, write: () => {} },
|
||||
stderr: { write: () => {} },
|
||||
};
|
||||
}
|
||||
|
||||
describe('resolveOutputMode', () => {
|
||||
it('uses explicit value when provided', () => {
|
||||
expect(resolveOutputMode({ explicit: 'pretty', io: ioWith(false), env: {} })).toBe('pretty');
|
||||
expect(resolveOutputMode({ explicit: 'plain', io: ioWith(true), env: {} })).toBe('plain');
|
||||
expect(resolveOutputMode({ explicit: 'json', io: ioWith(true), env: {} })).toBe('json');
|
||||
});
|
||||
|
||||
it('json:true takes precedence over explicit value', () => {
|
||||
expect(resolveOutputMode({ explicit: 'pretty', json: true, io: ioWith(true), env: {} })).toBe('json');
|
||||
});
|
||||
|
||||
it('throws on unknown explicit value', () => {
|
||||
expect(() => resolveOutputMode({ explicit: 'fancy', io: ioWith(true), env: {} })).toThrow(/Invalid --output/);
|
||||
});
|
||||
|
||||
it('honors KLO_OUTPUT env var when no explicit value', () => {
|
||||
expect(resolveOutputMode({ io: ioWith(true), env: { KLO_OUTPUT: 'plain' } })).toBe('plain');
|
||||
expect(resolveOutputMode({ io: ioWith(false), env: { KLO_OUTPUT: 'pretty' } })).toBe('pretty');
|
||||
expect(resolveOutputMode({ io: ioWith(false), env: { KLO_OUTPUT: 'json' } })).toBe('json');
|
||||
});
|
||||
|
||||
it('throws on unknown KLO_OUTPUT', () => {
|
||||
expect(() => resolveOutputMode({ io: ioWith(true), env: { KLO_OUTPUT: 'fancy' } })).toThrow(/Invalid KLO_OUTPUT/);
|
||||
});
|
||||
|
||||
it('returns plain when CI is set to a truthy value', () => {
|
||||
expect(resolveOutputMode({ io: ioWith(true), env: { CI: 'true' } })).toBe('plain');
|
||||
expect(resolveOutputMode({ io: ioWith(true), env: { CI: '1' } })).toBe('plain');
|
||||
});
|
||||
|
||||
it('ignores CI when set to a falsy value', () => {
|
||||
expect(resolveOutputMode({ io: ioWith(true), env: { CI: '' } })).toBe('pretty');
|
||||
expect(resolveOutputMode({ io: ioWith(true), env: { CI: '0' } })).toBe('pretty');
|
||||
expect(resolveOutputMode({ io: ioWith(true), env: { CI: 'false' } })).toBe('pretty');
|
||||
});
|
||||
|
||||
it('returns pretty when stdout is a TTY and CI is not set', () => {
|
||||
expect(resolveOutputMode({ io: ioWith(true), env: {} })).toBe('pretty');
|
||||
});
|
||||
|
||||
it('returns plain when stdout is not a TTY', () => {
|
||||
expect(resolveOutputMode({ io: ioWith(false), env: {} })).toBe('plain');
|
||||
expect(resolveOutputMode({ io: ioWith(undefined), env: {} })).toBe('plain');
|
||||
});
|
||||
|
||||
it('explicit value beats KLO_OUTPUT env var', () => {
|
||||
expect(resolveOutputMode({ explicit: 'json', io: ioWith(true), env: { KLO_OUTPUT: 'plain' } })).toBe('json');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue