Skip to content

Commit f140f2a

Browse files
authored
test: add snapshot for cli flags (#3132)
1 parent 09fa827 commit f140f2a

File tree

55 files changed

+2387
-75
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2387
-75
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Options:
6868
--config-name <value...> Name of the configuration to use.
6969
-m, --merge Merge two or more configurations using 'webpack-merge'.
7070
--env <value...> Environment passed to the configuration when it is a function.
71+
--node-env <value> Sets process.env.NODE_ENV to the specified value.
7172
--progress [value] Print compilation progress during build.
7273
-j, --json [value] Prints result as JSON or store it in a file.
7374
-d, --devtool <value> Determine source maps to use.
@@ -79,6 +80,7 @@ Options:
7980
--stats [value] It instructs webpack on how to treat the stats e.g. verbose.
8081
--no-stats Disable stats output.
8182
-t, --target <value...> Sets the build target e.g. node.
83+
--no-target Negative 'target' option.
8284
--watch-options-stdin Stop watching when stdin stream has ended.
8385
--no-watch-options-stdin Do not stop watching when stdin stream has ended.
8486
--host <value> The hostname/ip address the server will bind to.
@@ -92,6 +94,7 @@ Options:
9294
--http2 Use HTTP/2, must be used with HTTPS.
9395
--no-http2 Do not use HTTP/2.
9496
--bonjour Broadcasts the server via ZeroConf networking on start.
97+
--no-bonjour Negative 'bonjour' option.
9598
--client-progress Print compilation progress in percentage in the browser.
9699
--client-overlay Show a full-screen overlay in the browser when there are compiler errors or warnings.
97100
--no-client-overlay Do not show a full-screen overlay in the browser when there are compiler errors or warnings.

globalSetupTest.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
// eslint-disable-next-line import/no-extraneous-dependencies
44
const tcpPortUsed = require('tcp-port-used');
5+
const { version } = require('webpack');
56
const ports = require('./test/ports-map');
67

8+
console.log(`\n Running tests for webpack @${version} \n`);
9+
710
async function validatePorts() {
811
const samples = [];
912

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
],
1111
moduleFileExtensions: ['js', 'json'],
1212
testMatch: ['**/test/**/*.test.js'],
13+
snapshotResolver: '<rootDir>/test/helpers/snapshotResolver.js',
1314
setupFilesAfterEnv: ['<rootDir>/setupTest.js'],
1415
globalSetup: '<rootDir>/globalSetupTest.js',
1516
testRunner: 'jest-circus/runner',
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Validation validation should fail validation for invalid \`hot\` configuration 1`] = `
4+
"Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
5+
- configuration.hot should be one of these:
6+
boolean | \\"only\\"
7+
Details:
8+
* configuration.hot should be a boolean.
9+
* configuration.hot should be \\"only\\"."
10+
`;
11+
12+
exports[`Validation validation should fail validation for invalid \`needClientEntry\` configuration 1`] = `
13+
"Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
14+
- configuration.client.needClientEntry should be one of these:
15+
boolean | function
16+
Details:
17+
* configuration.client.needClientEntry should be a boolean.
18+
* configuration.client.needClientEntry should be an instance of function."
19+
`;
20+
21+
exports[`Validation validation should fail validation for invalid \`needHotEntry\` configuration 1`] = `
22+
"Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
23+
- configuration.client.needHotEntry should be one of these:
24+
boolean | function
25+
Details:
26+
* configuration.client.needHotEntry should be a boolean.
27+
* configuration.client.needHotEntry should be an instance of function."
28+
`;
29+
30+
exports[`Validation validation should fail validation for invalid \`static\` configuration 1`] = `
31+
"Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
32+
- configuration.static should be one of these:
33+
boolean | non-empty string | object { directory?, staticOptions?, publicPath?, serveIndex?, watch? } | [non-empty string | object { directory?, staticOptions?, publicPath?, serveIndex?, watch? }, ...] (should not have fewer than 1 item)
34+
Details:
35+
* configuration.static[0] should be one of these:
36+
non-empty string | object { directory?, staticOptions?, publicPath?, serveIndex?, watch? }
37+
Details:
38+
* configuration.static[0] should be a non-empty string.
39+
* configuration.static[0] should be an object:
40+
object { directory?, staticOptions?, publicPath?, serveIndex?, watch? }"
41+
`;
42+
43+
exports[`Validation validation should fail validation for no additional properties 1`] = `
44+
"Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
45+
- configuration has an unknown property 'additional'. These properties are valid:
46+
object { bonjour?, client?, compress?, dev?, firewall?, headers?, historyApiFallback?, host?, hot?, http2?, https?, liveReload?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, port?, proxy?, public?, setupExitSignals?, static?, transportMode?, watchFiles? }"
47+
`;

test/cli/__snapshots__/cli.test.js.snap

Lines changed: 0 additions & 74 deletions
This file was deleted.
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`CLI --host :: (IPv6): stderr 1`] = `
4+
"<i> [webpack-dev-server] Project is running at:
5+
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
6+
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
7+
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
8+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
9+
`;
10+
11+
exports[`CLI --host ::1 (IPv6): stderr 1`] = `
12+
"<i> [webpack-dev-server] Project is running at:
13+
<i> [webpack-dev-server] Loopback: http://[::1]:<port>/
14+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
15+
`;
16+
17+
exports[`CLI --host <IPv4>: stderr 1`] = `
18+
"<i> [webpack-dev-server] Project is running at:
19+
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
20+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
21+
`;
22+
23+
exports[`CLI --host <local-ip>: stderr 1`] = `
24+
"<i> [webpack-dev-server] Project is running at:
25+
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
26+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
27+
`;
28+
29+
exports[`CLI --host <local-ipv4>: stderr 1`] = `
30+
"<i> [webpack-dev-server] Project is running at:
31+
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
32+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
33+
`;
34+
35+
exports[`CLI --host 0.0.0.0 (IPv4): stderr 1`] = `
36+
"<i> [webpack-dev-server] Project is running at:
37+
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
38+
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
39+
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
40+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
41+
`;
42+
43+
exports[`CLI --host 0:0:0:0:0:FFFF:7F00:0001 (IPv6): stderr 1`] = `
44+
"<i> [webpack-dev-server] Project is running at:
45+
<i> [webpack-dev-server] On Your Network (IPv4): http://127.0.0.1:<port>/
46+
<i> [webpack-dev-server] On Your Network (IPv6): http://[::ffff:127.0.0.1]:<port>/
47+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
48+
`;
49+
50+
exports[`CLI --host 127.0.0.1 (IPv4): stderr 1`] = `
51+
"<i> [webpack-dev-server] Project is running at:
52+
<i> [webpack-dev-server] Loopback: http://127.0.0.1:<port>/
53+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
54+
`;
55+
56+
exports[`CLI --host and --port are unspecified: stderr 1`] = `
57+
"<i> [webpack-dev-server] Project is running at:
58+
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
59+
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
60+
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
61+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
62+
`;
63+
64+
exports[`CLI --host localhost --port 9999: stderr 1`] = `
65+
"<i> [webpack-dev-server] Project is running at:
66+
<i> [webpack-dev-server] Loopback: http://localhost:<port>/, http://127.0.0.1:<port>/
67+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
68+
`;
69+
70+
exports[`CLI --host localhost: stderr 1`] = `
71+
"<i> [webpack-dev-server] Project is running at:
72+
<i> [webpack-dev-server] Loopback: http://localhost:<port>/, http://127.0.0.1:<port>/
73+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
74+
`;
75+
76+
exports[`CLI should generate correct cli flags 1`] = `
77+
"Usage: webpack serve|s [entries...] [options]
78+
79+
Run the webpack dev server.
80+
81+
Options:
82+
-c, --config <value...> Provide path to a webpack configuration file e.g.
83+
./webpack.config.js.
84+
--config-name <value...> Name of the configuration to use.
85+
-m, --merge Merge two or more configurations using
86+
'webpack-merge'.
87+
--env <value...> Environment passed to the configuration when it is
88+
a function.
89+
--node-env <value> Sets process.env.NODE_ENV to the specified value.
90+
--progress [value] Print compilation progress during build.
91+
-j, --json [value] Prints result as JSON or store it in a file.
92+
--entry <value...> The entry point(s) of your application e.g.
93+
./src/main.js.
94+
-o, --output-path <value> Output location of the file generated by webpack
95+
e.g. ./dist/.
96+
-t, --target <value> Sets the build target e.g. node.
97+
-d, --devtool <value> Determine source maps to use.
98+
--mode <value> Defines the mode to pass to webpack.
99+
--name <value> Name of the configuration. Used when loading
100+
multiple configurations.
101+
--stats [value] It instructs webpack on how to treat the stats
102+
e.g. verbose.
103+
--no-stats Disable stats output.
104+
--watch-options-stdin Stop watching when stdin stream has ended.
105+
--no-watch-options-stdin Do not stop watching when stdin stream has ended.
106+
--host <value> The hostname/ip address the server will bind to.
107+
--port <value> The port server will listen to.
108+
--static [value...] A directory to serve static content from.
109+
--no-static Negative 'static' option.
110+
--live-reload Enables live reloading on changing files.
111+
--no-live-reload Disables live reloading on changing files.
112+
--https Use HTTPS protocol.
113+
--no-https Do not use HTTPS protocol.
114+
--http2 Use HTTP/2, must be used with HTTPS.
115+
--no-http2 Do not use HTTP/2.
116+
--bonjour Broadcasts the server via ZeroConf networking on
117+
start.
118+
--no-bonjour Negative 'bonjour' option.
119+
--client-progress Print compilation progress in percentage in the
120+
browser.
121+
--no-client-progress Negative 'client-progress' option.
122+
--client-overlay Show a full-screen overlay in the browser when
123+
there are compiler errors or warnings.
124+
--no-client-overlay Do not show a full-screen overlay in the browser
125+
when there are compiler errors or warnings.
126+
--setup-exit-signals Close and exit the process on SIGINT and SIGTERM.
127+
--no-setup-exit-signals Do not close and exit the process on SIGNIT and
128+
SIGTERM.
129+
--open [value...] Open the default browser.
130+
--no-open Do not open the default browser.
131+
--open-app <value> Open specified browser.
132+
--open-target [value...] Open specified route in browser.
133+
--no-open-target Do not open specified route in browser.
134+
--client-logging <value> Log level in the browser (none, error, warn, info,
135+
log, verbose).
136+
--history-api-fallback Fallback to /index.html for Single Page
137+
Applications.
138+
--no-history-api-fallback Do not fallback to /index.html for Single Page
139+
Applications.
140+
--compress Enable gzip compression.
141+
--no-compress Disable gzip compression.
142+
--public <value> The public hostname/ip address of the server.
143+
--firewall [value...] Enable firewall or set hosts that are allowed to
144+
access the dev server.
145+
--no-firewall Disable firewall.
146+
--watch-files <value...> Watch static files for file changes.
147+
148+
Global options:
149+
--color Enable colors on console.
150+
--no-color Disable colors on console.
151+
-v, --version Output the version number of 'webpack',
152+
'webpack-cli' and 'webpack-dev-server' and
153+
commands.
154+
-h, --help [verbose] Display help for commands and options.
155+
156+
To see list of all supported commands and options run 'webpack --help=verbose'.
157+
158+
Webpack documentation: https://webpack.js.org/.
159+
CLI documentation: https://webpack.js.org/api/cli/.
160+
Made with ♥ by the webpack team."
161+
`;

0 commit comments

Comments
 (0)