Add help shortcut regression test
This commit is contained in:
parent
4108a84d88
commit
dd8ca32903
42
tests/cli-help-shortcuts.test.ts
Normal file
42
tests/cli-help-shortcuts.test.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
process.env.MCPORTER_DISABLE_AUTORUN = '1';
|
||||
const cliModulePromise = import('../src/cli.js');
|
||||
|
||||
describe('mcporter help shortcuts (hidden)', () => {
|
||||
let previousNoForceExit: string | undefined;
|
||||
|
||||
beforeEach(() => {
|
||||
previousNoForceExit = process.env.MCPORTER_NO_FORCE_EXIT;
|
||||
process.env.MCPORTER_NO_FORCE_EXIT = '1';
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
process.exitCode = undefined;
|
||||
if (previousNoForceExit === undefined) {
|
||||
delete process.env.MCPORTER_NO_FORCE_EXIT;
|
||||
} else {
|
||||
process.env.MCPORTER_NO_FORCE_EXIT = previousNoForceExit;
|
||||
}
|
||||
});
|
||||
|
||||
const cases: Array<{ args: string[]; expectSnippet: string }> = [
|
||||
{ args: ['call', '--help'], expectSnippet: 'Usage: mcporter call' },
|
||||
{ args: ['call', 'help'], expectSnippet: 'Usage: mcporter call' },
|
||||
{ args: ['auth', '--help'], expectSnippet: 'Usage: mcporter auth' },
|
||||
{ args: ['auth', 'help'], expectSnippet: 'Usage: mcporter auth' },
|
||||
{ args: ['list', '--help'], expectSnippet: 'Usage: mcporter list' },
|
||||
{ args: ['list', 'help'], expectSnippet: 'Usage: mcporter list' },
|
||||
];
|
||||
|
||||
it.each(cases)('prints help for %j', async ({ args, expectSnippet }) => {
|
||||
const { runCli } = await cliModulePromise;
|
||||
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
await runCli(args);
|
||||
|
||||
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining(expectSnippet));
|
||||
expect(process.exitCode).toBe(0);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user