mirror of
https://github.com/Kaelio/ktx.git
synced 2026-07-19 11:41:02 +02:00
test: split cli tests from source tree
This commit is contained in:
parent
7d79d4e38e
commit
4619217804
496 changed files with 2582 additions and 952 deletions
|
|
@ -1,60 +0,0 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import type { KtxCliIo } from '../cli-runtime.js';
|
||||
import { resolveOutputMode } from './mode.js';
|
||||
|
||||
function ioWith(isTTY: boolean | undefined): KtxCliIo {
|
||||
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 KTX_OUTPUT env var when no explicit value', () => {
|
||||
expect(resolveOutputMode({ io: ioWith(true), env: { KTX_OUTPUT: 'plain' } })).toBe('plain');
|
||||
expect(resolveOutputMode({ io: ioWith(false), env: { KTX_OUTPUT: 'pretty' } })).toBe('pretty');
|
||||
expect(resolveOutputMode({ io: ioWith(false), env: { KTX_OUTPUT: 'json' } })).toBe('json');
|
||||
});
|
||||
|
||||
it('throws on unknown KTX_OUTPUT', () => {
|
||||
expect(() => resolveOutputMode({ io: ioWith(true), env: { KTX_OUTPUT: 'fancy' } })).toThrow(/Invalid KTX_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 KTX_OUTPUT env var', () => {
|
||||
expect(resolveOutputMode({ explicit: 'json', io: ioWith(true), env: { KTX_OUTPUT: 'plain' } })).toBe('json');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue