Skip to content

Commit

Permalink
test: add
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jul 14, 2021
1 parent 3cc424b commit 2c60e03
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/api/CLI.test.js
Expand Up @@ -1699,4 +1699,34 @@ describe("CLI API", () => {
expect(command.helpInformation()).toContain("--no-boolean Negated description");
});
});

describe("custom help output", () => {
let consoleSpy;
let exitSpy;

beforeEach(async () => {
consoleSpy = jest.spyOn(global.console, "log");
exitSpy = jest.spyOn(process, "exit").mockImplementation(() => {});

cli.program.option("--color [value]", "any color", "blue");
await new Promise((resolve, reject) => {
try {
cli.run(["help", "--color"], { from: "user" });
resolve();
} catch (error) {
reject(error);
}
});
});

afterEach(async () => {
consoleSpy.mockRestore();
exitSpy.mockRestore();
});

it("should display help information", () => {
expect(exitSpy).toHaveBeenCalledWith(0);
expect(consoleSpy.mock.calls).toMatchSnapshot();
});
});
});
31 changes: 31 additions & 0 deletions test/api/__snapshots__/CLI.test.js.snap.webpack4
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CLI API custom help output should display help information 1`] = `
Array [
Array [
"Usage: webpack --color [value]",
],
Array [
"Description: any color",
],
Array [
"Default value: \\"blue\\"",
],
Array [
"",
],
Array [
"To see list of all supported commands and options run 'webpack --help=verbose'.
",
],
Array [
"Webpack documentation: https://webpack.js.org/.",
],
Array [
"CLI documentation: https://webpack.js.org/api/cli/.",
],
Array [
"Made with ♥ by the webpack team.",
],
]
`;
31 changes: 31 additions & 0 deletions test/api/__snapshots__/CLI.test.js.snap.webpack5
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CLI API custom help output should display help information 1`] = `
Array [
Array [
"Usage: webpack --color [value]",
],
Array [
"Description: any color",
],
Array [
"Default value: \\"blue\\"",
],
Array [
"",
],
Array [
"To see list of all supported commands and options run 'webpack --help=verbose'.
",
],
Array [
"Webpack documentation: https://webpack.js.org/.",
],
Array [
"CLI documentation: https://webpack.js.org/api/cli/.",
],
Array [
"Made with ♥ by the webpack team.",
],
]
`;

0 comments on commit 2c60e03

Please sign in to comment.