mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-07 07:55:13 +02:00
refactor(cli): extract buildKtxProgram for reuse outside runCommanderKtxCli
This commit is contained in:
parent
80f298d652
commit
cdcfd21e95
2 changed files with 100 additions and 28 deletions
54
packages/cli/src/cli-program.test.ts
Normal file
54
packages/cli/src/cli-program.test.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import type { Command } from '@commander-js/extra-typings';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { buildKtxProgram } from './cli-program.js';
|
||||
import type { KtxCliIo, KtxCliPackageInfo } from './cli-runtime.js';
|
||||
|
||||
function stubIo(): KtxCliIo {
|
||||
return {
|
||||
stdout: { isTTY: false, columns: 80, write: () => {} },
|
||||
stderr: { write: () => {} },
|
||||
};
|
||||
}
|
||||
|
||||
function stubPackageInfo(): KtxCliPackageInfo {
|
||||
return { name: '@ktx/cli', version: '0.0.0-test', contextPackageName: '@ktx/context' };
|
||||
}
|
||||
|
||||
describe('buildKtxProgram', () => {
|
||||
it('returns a Command named "ktx" with all registered top-level subcommands', () => {
|
||||
const program: Command = buildKtxProgram({
|
||||
io: stubIo(),
|
||||
deps: {},
|
||||
packageInfo: stubPackageInfo(),
|
||||
runInit: async () => 0,
|
||||
});
|
||||
|
||||
expect(program.name()).toBe('ktx');
|
||||
const topLevel = program.commands.map((command) => command.name()).sort();
|
||||
for (const expected of ['setup', 'connection', 'ingest', 'sl', 'dev']) {
|
||||
expect(topLevel).toContain(expected);
|
||||
}
|
||||
});
|
||||
|
||||
it('does not parse argv or invoke action handlers', () => {
|
||||
let wrote = '';
|
||||
const io: KtxCliIo = {
|
||||
stdout: {
|
||||
isTTY: false,
|
||||
columns: 80,
|
||||
write: (chunk) => {
|
||||
wrote += chunk;
|
||||
},
|
||||
},
|
||||
stderr: {
|
||||
write: (chunk) => {
|
||||
wrote += chunk;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
buildKtxProgram({ io, deps: {}, packageInfo: stubPackageInfo(), runInit: async () => 0 });
|
||||
|
||||
expect(wrote).toBe('');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue