Skip to content

Commit a56761e

Browse files
authored
test: enable tests for webpack-dev-server@next (#2573)
1 parent 3b4eff8 commit a56761e

35 files changed

+6903
-132
lines changed

.github/workflows/nodejs.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: yarn lint
4848

4949
build:
50-
name: Tests and Coverage - ${{ matrix.os }} - Node v${{ matrix.node-version }}, Webpack ${{ matrix.webpack-version }}
50+
name: Tests and Coverage - ${{ matrix.os }} - Node v${{ matrix.node-version }}, Webpack ${{ matrix.webpack-version }}, DevServer ${{ matrix.dev-server-version }}
5151

5252
runs-on: ${{ matrix.os }}
5353

@@ -56,6 +56,7 @@ jobs:
5656
os: [ubuntu-latest, windows-latest, macos-latest]
5757
node-version: [10.x, 12.x, 14.x]
5858
webpack-version: [4, latest]
59+
dev-server-version: [latest, next]
5960

6061
steps:
6162
- uses: actions/checkout@v2
@@ -84,6 +85,9 @@ jobs:
8485
- name: Install webpack ${{ matrix.webpack-version }}
8586
run: yarn add -W webpack@${{ matrix.webpack-version }}
8687

88+
- name: Install webpack-dev-server ${{ matrix.webpack-version }}
89+
run: yarn add -W webpack-dev-server@${{ matrix.dev-server-version }}
90+
8791
- name: Prepare environment for tests
8892
run: yarn build:ci
8993

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"execa": "^5.0.0",
6969
"get-port": "^5.1.1",
7070
"husky": "^6.0.0",
71+
"internal-ip": "^6.2.0",
7172
"jest": "^26.6.1",
7273
"jest-watch-typeahead": "^0.6.1",
7374
"lerna": "^4.0.0",
@@ -80,8 +81,8 @@
8081
"ts-jest": "^26.5.5",
8182
"ts-node": "^9.1.1",
8283
"typescript": "^4.1.3",
83-
"webpack": "^5.34.0",
84+
"webpack": "^5.35.0",
8485
"webpack-bundle-analyzer": "^4.3.0",
85-
"webpack-dev-server": "^3.11.1"
86+
"webpack-dev-server": "^3.11.2"
8687
}
8788
}

test/api/scaffold-utils.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('utils', () => {
2727
entry: 'Yes',
2828
});
2929
});
30+
3031
it('should emulate a prompt for list input', () => {
3132
expect(Input(mockSelf, 'plugins', 'what is your plugin?', 'openJSF')).toEqual({
3233
type: 'input',
@@ -35,11 +36,13 @@ describe('utils', () => {
3536
default: 'openJSF',
3637
});
3738
});
39+
3840
it('should return a default Input object value', () => {
3941
expect(Input(mockSelf, 'plugins', 'what is your plugin?', 'my-plugin', true)).toEqual({
4042
plugins: 'my-plugin',
4143
});
4244
});
45+
4346
it('should emulate a prompt for confirm', () => {
4447
expect(Confirm(mockSelf, 'context', 'what is your context?')).toEqual({
4548
name: 'context',
@@ -48,17 +51,21 @@ describe('utils', () => {
4851
type: 'confirm',
4952
});
5053
});
54+
5155
it('should make a Confirm object with yes as default', () => {
5256
expect(Confirm(mockSelf, 'context', 'what is your context?', true, true)).toEqual({
5357
context: true,
5458
});
5559
});
60+
5661
it('should make an Input object with validation', () => {
5762
expect(InputValidate(mockSelf, 'plugins', 'what is your plugin?', () => true)).toMatchSnapshot();
5863
});
64+
5965
it('should make an Input object with validation and default value', () => {
6066
expect(InputValidate(mockSelf, 'plugins', 'what is your plugin?', () => true, 'my-plugin')).toMatchSnapshot();
6167
});
68+
6269
it('should return a default Input object with validation and default value', () => {
6370
expect(InputValidate(mockSelf, 'plugins', 'what is your plugin?', () => true, 'my-plugin', true)).toEqual({
6471
plugins: 'my-plugin',

test/build/mode/mode-with-config/src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ if (process.env.NODE_ENV === "production") {
77
} else {
88
console.log("none mode");
99
}
10-

test/help/__snapshots__/help.test.js.snap.devServer4.webpack4

Lines changed: 2762 additions & 0 deletions
Large diffs are not rendered by default.

test/help/__snapshots__/help.test.js.snap.devServer4.webpack5

Lines changed: 2789 additions & 0 deletions
Large diffs are not rendered by default.

test/help/help.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
23
const { run, normalizeStderr, normalizeStdout } = require('../utils/test-utils');
34

45
describe('help', () => {

test/serve/basic/__snapshots__/serve-basic.test.js.snap.devServer3.webpack4

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ exports[`basic serve usage should log an error on unknown flag: stderr 1`] = `
55
[webpack-cli] Run 'webpack --help' to see available commands and options"
66
`;
77

8+
exports[`basic serve usage should log an error on unknown flag: stdout 1`] = `""`;
9+
810
exports[`basic serve usage should log error on using '--watch' flag with serve: stderr 1`] = `
911
"[webpack-cli] Error: Unknown option '--watch'
1012
[webpack-cli] Run 'webpack --help' to see available commands and options"
1113
`;
1214

15+
exports[`basic serve usage should log error on using '--watch' flag with serve: stdout 1`] = `""`;
16+
1317
exports[`basic serve usage should log error on using '-w' alias with serve: stderr 1`] = `
1418
"[webpack-cli] Error: Unknown option '-w'
1519
[webpack-cli] Run 'webpack --help' to see available commands and options"
1620
`;
1721

22+
exports[`basic serve usage should log error on using '-w' alias with serve: stdout 1`] = `""`;
23+
1824
exports[`basic serve usage should log used supplied config with serve: stderr 1`] = `
1925
" [webpack-cli] Compiler starting...
2026
[webpack-cli] Compiler is using config: '<cwd>/test/serve/basic/log.config.js'
@@ -30,11 +36,83 @@ exports[`basic serve usage should respect the "publicPath" option from configura
3036

3137
exports[`basic serve usage should respect the "publicPath" option from configuration: stderr 1`] = `""`;
3238

39+
exports[`basic serve usage should shoe help information for serve: stderr 1`] = `""`;
40+
41+
exports[`basic serve usage should shoe help information for serve: stdout 1`] = `
42+
"Usage: webpack serve|server|s [entries...] [options]
43+
44+
Run the webpack dev server.
45+
46+
Options:
47+
-c, --config <value...> Provide path to a webpack configuration file e.g. ./webpack.config.js.
48+
--config-name <value...> Name of the configuration to use.
49+
-m, --merge Merge two or more configurations using 'webpack-merge'.
50+
--env <value...> Environment passed to the configuration when it is a function.
51+
--node-env <value> Sets process.env.NODE_ENV to the specified value.
52+
--progress [value] Print compilation progress during build.
53+
-j, --json [value] Prints result as JSON or store it in a file.
54+
--entry <value...> The entry point(s) of your application e.g. ./src/main.js.
55+
-o, --output-path <value> Output location of the file generated by webpack e.g. ./dist/.
56+
-t, --target <value> Sets the build target e.g. node.
57+
-d, --devtool <value> Determine source maps to use.
58+
--no-devtool Do not generate source maps.
59+
--mode <value> Defines the mode to pass to webpack.
60+
--name <value> Name of the configuration. Used when loading multiple configurations.
61+
--stats [value] It instructs webpack on how to treat the stats e.g. verbose.
62+
--no-stats Disable stats output.
63+
--watch-options-stdin Stop watching when stdin stream has ended.
64+
--no-watch-options-stdin Do not stop watching when stdin stream has ended.
65+
--bonjour Broadcasts the server via ZeroConf networking on start
66+
--lazy Lazy
67+
--liveReload Enables/Disables live reloading on changing files
68+
--serveIndex Enables/Disables serveIndex middleware
69+
--inline Inline mode (set to false to disable including client scripts like livereload)
70+
--profile Print compilation profile data for progress steps
71+
--progress Print compilation progress in percentage
72+
--hot-only Do not refresh page if HMR fails
73+
--stdin close when stdin ends
74+
--open [value] Open the default browser, or optionally specify a browser name
75+
--useLocalIp Open default browser with local IP
76+
--open-page <value> Open default browser with the specified page
77+
--client-log-level <value> Log level in the browser (trace, debug, info, warn, error or silent)
78+
--https HTTPS
79+
--http2 HTTP/2, must be used with HTTPS
80+
--key <value> Path to a SSL key.
81+
--cert <value> Path to a SSL certificate.
82+
--cacert <value> Path to a SSL CA certificate.
83+
--pfx <value> Path to a SSL pfx file.
84+
--pfx-passphrase <value> Passphrase for pfx file.
85+
--content-base <value> A directory or URL to serve HTML content from.
86+
--watch-content-base Enable live-reloading of the content-base.
87+
--history-api-fallback Fallback to /index.html for Single Page Applications.
88+
--compress Enable gzip compression
89+
--port <value> The port
90+
--disable-host-check Will not check the host
91+
--socket <value> Socket to listen
92+
--public <value> The public hostname/ip address of the server
93+
--host <value> The hostname/ip address the server will bind to
94+
--allowed-hosts <value...> A list of hosts that are allowed to access the dev server, separated by spaces
95+
96+
Global options:
97+
--color Enable colors on console.
98+
--no-color Disable colors on console.
99+
-v, --version Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
100+
-h, --help [verbose] Display help for commands and options.
101+
102+
To see list of all supported commands and options run 'webpack --help=verbose'.
103+
104+
Webpack documentation: https://webpack.js.org/.
105+
CLI documentation: https://webpack.js.org/api/cli/.
106+
Made with ♥ by the webpack team."
107+
`;
108+
33109
exports[`basic serve usage should throw error when same ports in multicompiler: stderr 1`] = `
34110
"[webpack-cli] Error: Unique ports must be specified for each devServer option in your webpack configuration. Alternatively, run only 1 devServer config using the --config-name flag to specify your desired config.
35111
at stack"
36112
`;
37113

114+
exports[`basic serve usage should throw error when same ports in multicompiler: stdout 1`] = `""`;
115+
38116
exports[`basic serve usage should work and log warning on the \`watch option in a configuration: stderr 1`] = `"[webpack-cli] No need to use the 'serve' command together with '{ watch: true }' configuration, it does not make sense."`;
39117

40118
exports[`basic serve usage should work in multi compiler mode: stderr 1`] = `""`;
@@ -70,6 +148,8 @@ exports[`basic serve usage should work with the "--output-public-path" option: s
70148
[webpack-cli] Run 'webpack --help' to see available commands and options"
71149
`;
72150

151+
exports[`basic serve usage should work with the "--output-public-path" option: stdout 1`] = `""`;
152+
73153
exports[`basic serve usage should work with the "--port" option: stderr 1`] = `""`;
74154

75155
exports[`basic serve usage should work with the "--stats verbose" option: stderr 1`] = `""`;

test/serve/basic/__snapshots__/serve-basic.test.js.snap.devServer3.webpack5

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ exports[`basic serve usage should log an error on unknown flag: stderr 1`] = `
55
[webpack-cli] Run 'webpack --help' to see available commands and options"
66
`;
77

8+
exports[`basic serve usage should log an error on unknown flag: stdout 1`] = `""`;
9+
810
exports[`basic serve usage should log error on using '--watch' flag with serve: stderr 1`] = `
911
"[webpack-cli] Error: Unknown option '--watch'
1012
[webpack-cli] Run 'webpack --help' to see available commands and options"
1113
`;
1214

15+
exports[`basic serve usage should log error on using '--watch' flag with serve: stdout 1`] = `""`;
16+
1317
exports[`basic serve usage should log error on using '-w' alias with serve: stderr 1`] = `
1418
"[webpack-cli] Error: Unknown option '-w'
1519
[webpack-cli] Run 'webpack --help' to see available commands and options"
1620
`;
1721

22+
exports[`basic serve usage should log error on using '-w' alias with serve: stdout 1`] = `""`;
23+
1824
exports[`basic serve usage should log used supplied config with serve: stderr 1`] = `
1925
" [webpack-cli] Compiler starting...
2026
[webpack-cli] Compiler is using config: '<cwd>/test/serve/basic/log.config.js'
@@ -30,11 +36,84 @@ exports[`basic serve usage should respect the "publicPath" option from configura
3036

3137
exports[`basic serve usage should respect the "publicPath" option from configuration: stderr 1`] = `""`;
3238

39+
exports[`basic serve usage should shoe help information for serve: stderr 1`] = `""`;
40+
41+
exports[`basic serve usage should shoe help information for serve: stdout 1`] = `
42+
"Usage: webpack serve|server|s [entries...] [options]
43+
44+
Run the webpack dev server.
45+
46+
Options:
47+
-c, --config <value...> Provide path to a webpack configuration file e.g. ./webpack.config.js.
48+
--config-name <value...> Name of the configuration to use.
49+
-m, --merge Merge two or more configurations using 'webpack-merge'.
50+
--env <value...> Environment passed to the configuration when it is a function.
51+
--node-env <value> Sets process.env.NODE_ENV to the specified value.
52+
--progress [value] Print compilation progress during build.
53+
-j, --json [value] Prints result as JSON or store it in a file.
54+
-d, --devtool <value> Determine source maps to use.
55+
--no-devtool Do not generate source maps.
56+
--entry <value...> The entry point(s) of your application e.g. ./src/main.js.
57+
--mode <value> Defines the mode to pass to webpack.
58+
--name <value> Name of the configuration. Used when loading multiple configurations.
59+
-o, --output-path <value> Output location of the file generated by webpack e.g. ./dist/.
60+
--stats [value] It instructs webpack on how to treat the stats e.g. verbose.
61+
--no-stats Disable stats output.
62+
-t, --target <value...> Sets the build target e.g. node.
63+
--no-target Negative 'target' option.
64+
--watch-options-stdin Stop watching when stdin stream has ended.
65+
--no-watch-options-stdin Do not stop watching when stdin stream has ended.
66+
--bonjour Broadcasts the server via ZeroConf networking on start
67+
--lazy Lazy
68+
--liveReload Enables/Disables live reloading on changing files
69+
--serveIndex Enables/Disables serveIndex middleware
70+
--inline Inline mode (set to false to disable including client scripts like livereload)
71+
--profile Print compilation profile data for progress steps
72+
--progress Print compilation progress in percentage
73+
--hot-only Do not refresh page if HMR fails
74+
--stdin close when stdin ends
75+
--open [value] Open the default browser, or optionally specify a browser name
76+
--useLocalIp Open default browser with local IP
77+
--open-page <value> Open default browser with the specified page
78+
--client-log-level <value> Log level in the browser (trace, debug, info, warn, error or silent)
79+
--https HTTPS
80+
--http2 HTTP/2, must be used with HTTPS
81+
--key <value> Path to a SSL key.
82+
--cert <value> Path to a SSL certificate.
83+
--cacert <value> Path to a SSL CA certificate.
84+
--pfx <value> Path to a SSL pfx file.
85+
--pfx-passphrase <value> Passphrase for pfx file.
86+
--content-base <value> A directory or URL to serve HTML content from.
87+
--watch-content-base Enable live-reloading of the content-base.
88+
--history-api-fallback Fallback to /index.html for Single Page Applications.
89+
--compress Enable gzip compression
90+
--port <value> The port
91+
--disable-host-check Will not check the host
92+
--socket <value> Socket to listen
93+
--public <value> The public hostname/ip address of the server
94+
--host <value> The hostname/ip address the server will bind to
95+
--allowed-hosts <value...> A list of hosts that are allowed to access the dev server, separated by spaces
96+
97+
Global options:
98+
--color Enable colors on console.
99+
--no-color Disable colors on console.
100+
-v, --version Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
101+
-h, --help [verbose] Display help for commands and options.
102+
103+
To see list of all supported commands and options run 'webpack --help=verbose'.
104+
105+
Webpack documentation: https://webpack.js.org/.
106+
CLI documentation: https://webpack.js.org/api/cli/.
107+
Made with ♥ by the webpack team."
108+
`;
109+
33110
exports[`basic serve usage should throw error when same ports in multicompiler: stderr 1`] = `
34111
"[webpack-cli] Error: Unique ports must be specified for each devServer option in your webpack configuration. Alternatively, run only 1 devServer config using the --config-name flag to specify your desired config.
35112
at stack"
36113
`;
37114

115+
exports[`basic serve usage should throw error when same ports in multicompiler: stdout 1`] = `""`;
116+
38117
exports[`basic serve usage should work and log warning on the \`watch option in a configuration: stderr 1`] = `"[webpack-cli] No need to use the 'serve' command together with '{ watch: true }' configuration, it does not make sense."`;
39118

40119
exports[`basic serve usage should work in multi compiler mode: stderr 1`] = `""`;

0 commit comments

Comments
 (0)