Repository navigation
Expand file tree
/
Copy pathCommandLineHelp.test.ts
More file actions
50 lines (41 loc) · 1.78 KB
/
Copy pathCommandLineHelp.test.ts
File metadata and controls
50 lines (41 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { AnsiEscape, Terminal, StringBufferTerminalProvider } from '@rushstack/terminal';
import type { CommandLineParser } from '@rushstack/ts-command-line';
import { ExplorerCommandLineParser } from '../explorer/ExplorerCommandLineParser';
import { LintCommandLineParser } from '../lint/LintCommandLineParser';
describe('CommandLineHelp', () => {
let terminal: Terminal;
let terminalProvider: StringBufferTerminalProvider;
beforeEach(() => {
terminalProvider = new StringBufferTerminalProvider();
terminal = new Terminal(terminalProvider);
// ts-command-line calls process.exit() which interferes with Jest
jest.spyOn(process, 'exit').mockImplementation((code) => {
throw new Error(`Test code called process.exit(${code})`);
});
});
afterEach(() => {
expect(terminalProvider.getAllOutputAsChunks({ asLines: true })).toMatchSnapshot('terminal output');
});
describe.each([
{
name: 'ExplorerCommandLineParser',
createParser: () => new ExplorerCommandLineParser(terminal)
},
{
name: 'LintCommandLineParser',
createParser: () => new LintCommandLineParser(terminal)
}
])('$name', ({ createParser }) => {
it(`prints the help`, async () => {
const parser: CommandLineParser = createParser();
const globalHelpText: string = AnsiEscape.formatForTests(parser.renderHelpText());
expect(globalHelpText).toMatchSnapshot('global help');
for (const action of parser.actions) {
const actionHelpText: string = AnsiEscape.formatForTests(action.renderHelpText());
expect(actionHelpText).toMatchSnapshot(action.actionName);
}
});
});
});