-
Notifications
You must be signed in to change notification settings - Fork 620
/
Copy pathEndToEndTest.test.ts
64 lines (54 loc) · 2.38 KB
/
EndToEndTest.test.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import type { ChildProcess } from 'node:child_process';
import { AnsiEscape } from '@rushstack/terminal';
import { Executable } from '@rushstack/node-core-library';
const TEST_CLI_PATH: string = `${__dirname}/test-cli/start`;
function runTestCliTestWithArgs(testName: string, args: string[]): void {
it(testName, async () => {
const testCliProcess: ChildProcess = Executable.spawn(process.argv0, [TEST_CLI_PATH, ...args], {
stdio: 'pipe'
});
const { stdout, stderr, exitCode, signal } = await Executable.waitForExitAsync(testCliProcess, {
encoding: 'utf8'
});
expect(stdout).toMatchSnapshot('process stdout');
expect(stderr).toMatchSnapshot('process stderr');
expect(exitCode).toMatchSnapshot('process exit code');
expect(signal).toMatchSnapshot('process signal');
});
}
describe('end-to-end test', () => {
beforeEach(() => {
// 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})`);
});
});
it(`prints the help`, async () => {
const { WidgetCommandLine } = await import('./test-cli/WidgetCommandLine');
const parser = new WidgetCommandLine();
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);
}
});
describe('execution tests', () => {
runTestCliTestWithArgs('with no args', []);
runTestCliTestWithArgs('run', ['run']);
runTestCliTestWithArgs('run --title My Title', ['run', '--title', 'My Title']);
runTestCliTestWithArgs('run --title My Title --remaining --args', [
'run',
'--title',
'My Title',
'--remaining',
'--args'
]);
runTestCliTestWithArgs('push', ['push']);
runTestCliTestWithArgs('push --force', ['push', '--force']);
runTestCliTestWithArgs('push --protocol ftp', ['push', '--protocol', 'ftp']);
runTestCliTestWithArgs('push --protocol bogus', ['push', '--protocol', 'bogus']);
});
});