File tree 4 files changed +93
-1
lines changed
4 files changed +93
-1
lines changed Original file line number Diff line number Diff line change @@ -1357,7 +1357,7 @@ class WebpackCLI {
1357
1357
this . logger . raw ( `${ bold ( "Description:" ) } ${ option . description } ` ) ;
1358
1358
}
1359
1359
1360
- if ( ! option . negate && options . defaultValue ) {
1360
+ if ( ! option . negate && option . defaultValue ) {
1361
1361
this . logger . raw (
1362
1362
`${ bold ( "Default value:" ) } ${ JSON . stringify ( option . defaultValue ) } ` ,
1363
1363
) ;
Original file line number Diff line number Diff line change @@ -1699,4 +1699,34 @@ describe("CLI API", () => {
1699
1699
expect ( command . helpInformation ( ) ) . toContain ( "--no-boolean Negated description" ) ;
1700
1700
} ) ;
1701
1701
} ) ;
1702
+
1703
+ describe ( "custom help output" , ( ) => {
1704
+ let consoleSpy ;
1705
+ let exitSpy ;
1706
+
1707
+ beforeEach ( async ( ) => {
1708
+ consoleSpy = jest . spyOn ( global . console , "log" ) ;
1709
+ exitSpy = jest . spyOn ( process , "exit" ) . mockImplementation ( ( ) => { } ) ;
1710
+
1711
+ cli . program . option ( "--color [value]" , "any color" , "blue" ) ;
1712
+ await new Promise ( ( resolve , reject ) => {
1713
+ try {
1714
+ cli . run ( [ "help" , "--color" ] , { from : "user" } ) ;
1715
+ resolve ( ) ;
1716
+ } catch ( error ) {
1717
+ reject ( error ) ;
1718
+ }
1719
+ } ) ;
1720
+ } ) ;
1721
+
1722
+ afterEach ( async ( ) => {
1723
+ consoleSpy . mockRestore ( ) ;
1724
+ exitSpy . mockRestore ( ) ;
1725
+ } ) ;
1726
+
1727
+ it ( "should display help information" , ( ) => {
1728
+ expect ( exitSpy ) . toHaveBeenCalledWith ( 0 ) ;
1729
+ expect ( consoleSpy . mock . calls ) . toMatchSnapshot ( ) ;
1730
+ } ) ;
1731
+ } ) ;
1702
1732
} ) ;
Original file line number Diff line number Diff line change
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`CLI API custom help output should display help information 1`] = `
4
+ Array [
5
+ Array [
6
+ "[1mUsage[22m: webpack --color [value]",
7
+ ],
8
+ Array [
9
+ "[1mDescription:[22m any color",
10
+ ],
11
+ Array [
12
+ "[1mDefault value:[22m \\"blue\\"",
13
+ ],
14
+ Array [
15
+ "",
16
+ ],
17
+ Array [
18
+ "To see list of all supported commands and options run 'webpack --help=verbose'.
19
+ ",
20
+ ],
21
+ Array [
22
+ "[1mWebpack documentation:[22m https://webpack.js.org/.",
23
+ ],
24
+ Array [
25
+ "[1mCLI documentation:[22m https://webpack.js.org/api/cli/.",
26
+ ],
27
+ Array [
28
+ "[1mMade with ♥ by the webpack team[22m.",
29
+ ],
30
+ ]
31
+ `;
Original file line number Diff line number Diff line change
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`CLI API custom help output should display help information 1`] = `
4
+ Array [
5
+ Array [
6
+ "[1mUsage[22m: webpack --color [value]",
7
+ ],
8
+ Array [
9
+ "[1mDescription:[22m any color",
10
+ ],
11
+ Array [
12
+ "[1mDefault value:[22m \\"blue\\"",
13
+ ],
14
+ Array [
15
+ "",
16
+ ],
17
+ Array [
18
+ "To see list of all supported commands and options run 'webpack --help=verbose'.
19
+ ",
20
+ ],
21
+ Array [
22
+ "[1mWebpack documentation:[22m https://webpack.js.org/.",
23
+ ],
24
+ Array [
25
+ "[1mCLI documentation:[22m https://webpack.js.org/api/cli/.",
26
+ ],
27
+ Array [
28
+ "[1mMade with ♥ by the webpack team[22m.",
29
+ ],
30
+ ]
31
+ `;
You can’t perform that action at this time.
0 commit comments