Skip to content

Commit

Permalink
test: enable tests for webpack-dev-server@next (#2573)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Apr 23, 2021
1 parent 3b4eff8 commit a56761e
Show file tree
Hide file tree
Showing 35 changed files with 6,903 additions and 132 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/nodejs.yml
Expand Up @@ -47,7 +47,7 @@ jobs:
run: yarn lint

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

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

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

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -84,6 +85,9 @@ jobs:
- name: Install webpack ${{ matrix.webpack-version }}
run: yarn add -W webpack@${{ matrix.webpack-version }}

- name: Install webpack-dev-server ${{ matrix.webpack-version }}
run: yarn add -W webpack-dev-server@${{ matrix.dev-server-version }}

- name: Prepare environment for tests
run: yarn build:ci

Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -68,6 +68,7 @@
"execa": "^5.0.0",
"get-port": "^5.1.1",
"husky": "^6.0.0",
"internal-ip": "^6.2.0",
"jest": "^26.6.1",
"jest-watch-typeahead": "^0.6.1",
"lerna": "^4.0.0",
Expand All @@ -80,8 +81,8 @@
"ts-jest": "^26.5.5",
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"webpack": "^5.34.0",
"webpack": "^5.35.0",
"webpack-bundle-analyzer": "^4.3.0",
"webpack-dev-server": "^3.11.1"
"webpack-dev-server": "^3.11.2"
}
}
7 changes: 7 additions & 0 deletions test/api/scaffold-utils.test.js
Expand Up @@ -27,6 +27,7 @@ describe('utils', () => {
entry: 'Yes',
});
});

it('should emulate a prompt for list input', () => {
expect(Input(mockSelf, 'plugins', 'what is your plugin?', 'openJSF')).toEqual({
type: 'input',
Expand All @@ -35,11 +36,13 @@ describe('utils', () => {
default: 'openJSF',
});
});

it('should return a default Input object value', () => {
expect(Input(mockSelf, 'plugins', 'what is your plugin?', 'my-plugin', true)).toEqual({
plugins: 'my-plugin',
});
});

it('should emulate a prompt for confirm', () => {
expect(Confirm(mockSelf, 'context', 'what is your context?')).toEqual({
name: 'context',
Expand All @@ -48,17 +51,21 @@ describe('utils', () => {
type: 'confirm',
});
});

it('should make a Confirm object with yes as default', () => {
expect(Confirm(mockSelf, 'context', 'what is your context?', true, true)).toEqual({
context: true,
});
});

it('should make an Input object with validation', () => {
expect(InputValidate(mockSelf, 'plugins', 'what is your plugin?', () => true)).toMatchSnapshot();
});

it('should make an Input object with validation and default value', () => {
expect(InputValidate(mockSelf, 'plugins', 'what is your plugin?', () => true, 'my-plugin')).toMatchSnapshot();
});

it('should return a default Input object with validation and default value', () => {
expect(InputValidate(mockSelf, 'plugins', 'what is your plugin?', () => true, 'my-plugin', true)).toEqual({
plugins: 'my-plugin',
Expand Down
1 change: 0 additions & 1 deletion test/build/mode/mode-with-config/src/index.js
Expand Up @@ -7,4 +7,3 @@ if (process.env.NODE_ENV === "production") {
} else {
console.log("none mode");
}

2,762 changes: 2,762 additions & 0 deletions test/help/__snapshots__/help.test.js.snap.devServer4.webpack4

Large diffs are not rendered by default.

2,789 changes: 2,789 additions & 0 deletions test/help/__snapshots__/help.test.js.snap.devServer4.webpack5

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/help/help.test.js
@@ -1,4 +1,5 @@
'use strict';

const { run, normalizeStderr, normalizeStdout } = require('../utils/test-utils');

describe('help', () => {
Expand Down
Expand Up @@ -5,16 +5,22 @@ exports[`basic serve usage should log an error on unknown flag: stderr 1`] = `
[webpack-cli] Run 'webpack --help' to see available commands and options"
`;

exports[`basic serve usage should log an error on unknown flag: stdout 1`] = `""`;

exports[`basic serve usage should log error on using '--watch' flag with serve: stderr 1`] = `
"[webpack-cli] Error: Unknown option '--watch'
[webpack-cli] Run 'webpack --help' to see available commands and options"
`;

exports[`basic serve usage should log error on using '--watch' flag with serve: stdout 1`] = `""`;

exports[`basic serve usage should log error on using '-w' alias with serve: stderr 1`] = `
"[webpack-cli] Error: Unknown option '-w'
[webpack-cli] Run 'webpack --help' to see available commands and options"
`;

exports[`basic serve usage should log error on using '-w' alias with serve: stdout 1`] = `""`;

exports[`basic serve usage should log used supplied config with serve: stderr 1`] = `
" [webpack-cli] Compiler starting...
[webpack-cli] Compiler is using config: '<cwd>/test/serve/basic/log.config.js'
Expand All @@ -30,11 +36,83 @@ exports[`basic serve usage should respect the "publicPath" option from configura

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

exports[`basic serve usage should shoe help information for serve: stderr 1`] = `""`;

exports[`basic serve usage should shoe help information for serve: stdout 1`] = `
"Usage: webpack serve|server|s [entries...] [options]

Run the webpack dev server.

Options:
-c, --config <value...> Provide path to a webpack configuration file e.g. ./webpack.config.js.
--config-name <value...> Name of the configuration to use.
-m, --merge Merge two or more configurations using 'webpack-merge'.
--env <value...> Environment passed to the configuration when it is a function.
--node-env <value> Sets process.env.NODE_ENV to the specified value.
--progress [value] Print compilation progress during build.
-j, --json [value] Prints result as JSON or store it in a file.
--entry <value...> The entry point(s) of your application e.g. ./src/main.js.
-o, --output-path <value> Output location of the file generated by webpack e.g. ./dist/.
-t, --target <value> Sets the build target e.g. node.
-d, --devtool <value> Determine source maps to use.
--no-devtool Do not generate source maps.
--mode <value> Defines the mode to pass to webpack.
--name <value> Name of the configuration. Used when loading multiple configurations.
--stats [value] It instructs webpack on how to treat the stats e.g. verbose.
--no-stats Disable stats output.
--watch-options-stdin Stop watching when stdin stream has ended.
--no-watch-options-stdin Do not stop watching when stdin stream has ended.
--bonjour Broadcasts the server via ZeroConf networking on start
--lazy Lazy
--liveReload Enables/Disables live reloading on changing files
--serveIndex Enables/Disables serveIndex middleware
--inline Inline mode (set to false to disable including client scripts like livereload)
--profile Print compilation profile data for progress steps
--progress Print compilation progress in percentage
--hot-only Do not refresh page if HMR fails
--stdin close when stdin ends
--open [value] Open the default browser, or optionally specify a browser name
--useLocalIp Open default browser with local IP
--open-page <value> Open default browser with the specified page
--client-log-level <value> Log level in the browser (trace, debug, info, warn, error or silent)
--https HTTPS
--http2 HTTP/2, must be used with HTTPS
--key <value> Path to a SSL key.
--cert <value> Path to a SSL certificate.
--cacert <value> Path to a SSL CA certificate.
--pfx <value> Path to a SSL pfx file.
--pfx-passphrase <value> Passphrase for pfx file.
--content-base <value> A directory or URL to serve HTML content from.
--watch-content-base Enable live-reloading of the content-base.
--history-api-fallback Fallback to /index.html for Single Page Applications.
--compress Enable gzip compression
--port <value> The port
--disable-host-check Will not check the host
--socket <value> Socket to listen
--public <value> The public hostname/ip address of the server
--host <value> The hostname/ip address the server will bind to
--allowed-hosts <value...> A list of hosts that are allowed to access the dev server, separated by spaces

Global options:
--color Enable colors on console.
--no-color Disable colors on console.
-v, --version Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
-h, --help [verbose] Display help for commands and options.

To see list of all supported commands and options run 'webpack --help=verbose'.

Webpack documentation: https://webpack.js.org/.
CLI documentation: https://webpack.js.org/api/cli/.
Made with ♥ by the webpack team."
`;

exports[`basic serve usage should throw error when same ports in multicompiler: stderr 1`] = `
"[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.
at stack"
`;

exports[`basic serve usage should throw error when same ports in multicompiler: stdout 1`] = `""`;

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."`;

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

exports[`basic serve usage should work with the "--output-public-path" option: stdout 1`] = `""`;

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

exports[`basic serve usage should work with the "--stats verbose" option: stderr 1`] = `""`;
Expand Down
Expand Up @@ -5,16 +5,22 @@ exports[`basic serve usage should log an error on unknown flag: stderr 1`] = `
[webpack-cli] Run 'webpack --help' to see available commands and options"
`;

exports[`basic serve usage should log an error on unknown flag: stdout 1`] = `""`;

exports[`basic serve usage should log error on using '--watch' flag with serve: stderr 1`] = `
"[webpack-cli] Error: Unknown option '--watch'
[webpack-cli] Run 'webpack --help' to see available commands and options"
`;

exports[`basic serve usage should log error on using '--watch' flag with serve: stdout 1`] = `""`;

exports[`basic serve usage should log error on using '-w' alias with serve: stderr 1`] = `
"[webpack-cli] Error: Unknown option '-w'
[webpack-cli] Run 'webpack --help' to see available commands and options"
`;

exports[`basic serve usage should log error on using '-w' alias with serve: stdout 1`] = `""`;

exports[`basic serve usage should log used supplied config with serve: stderr 1`] = `
" [webpack-cli] Compiler starting...
[webpack-cli] Compiler is using config: '<cwd>/test/serve/basic/log.config.js'
Expand All @@ -30,11 +36,84 @@ exports[`basic serve usage should respect the "publicPath" option from configura

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

exports[`basic serve usage should shoe help information for serve: stderr 1`] = `""`;

exports[`basic serve usage should shoe help information for serve: stdout 1`] = `
"Usage: webpack serve|server|s [entries...] [options]

Run the webpack dev server.

Options:
-c, --config <value...> Provide path to a webpack configuration file e.g. ./webpack.config.js.
--config-name <value...> Name of the configuration to use.
-m, --merge Merge two or more configurations using 'webpack-merge'.
--env <value...> Environment passed to the configuration when it is a function.
--node-env <value> Sets process.env.NODE_ENV to the specified value.
--progress [value] Print compilation progress during build.
-j, --json [value] Prints result as JSON or store it in a file.
-d, --devtool <value> Determine source maps to use.
--no-devtool Do not generate source maps.
--entry <value...> The entry point(s) of your application e.g. ./src/main.js.
--mode <value> Defines the mode to pass to webpack.
--name <value> Name of the configuration. Used when loading multiple configurations.
-o, --output-path <value> Output location of the file generated by webpack e.g. ./dist/.
--stats [value] It instructs webpack on how to treat the stats e.g. verbose.
--no-stats Disable stats output.
-t, --target <value...> Sets the build target e.g. node.
--no-target Negative 'target' option.
--watch-options-stdin Stop watching when stdin stream has ended.
--no-watch-options-stdin Do not stop watching when stdin stream has ended.
--bonjour Broadcasts the server via ZeroConf networking on start
--lazy Lazy
--liveReload Enables/Disables live reloading on changing files
--serveIndex Enables/Disables serveIndex middleware
--inline Inline mode (set to false to disable including client scripts like livereload)
--profile Print compilation profile data for progress steps
--progress Print compilation progress in percentage
--hot-only Do not refresh page if HMR fails
--stdin close when stdin ends
--open [value] Open the default browser, or optionally specify a browser name
--useLocalIp Open default browser with local IP
--open-page <value> Open default browser with the specified page
--client-log-level <value> Log level in the browser (trace, debug, info, warn, error or silent)
--https HTTPS
--http2 HTTP/2, must be used with HTTPS
--key <value> Path to a SSL key.
--cert <value> Path to a SSL certificate.
--cacert <value> Path to a SSL CA certificate.
--pfx <value> Path to a SSL pfx file.
--pfx-passphrase <value> Passphrase for pfx file.
--content-base <value> A directory or URL to serve HTML content from.
--watch-content-base Enable live-reloading of the content-base.
--history-api-fallback Fallback to /index.html for Single Page Applications.
--compress Enable gzip compression
--port <value> The port
--disable-host-check Will not check the host
--socket <value> Socket to listen
--public <value> The public hostname/ip address of the server
--host <value> The hostname/ip address the server will bind to
--allowed-hosts <value...> A list of hosts that are allowed to access the dev server, separated by spaces

Global options:
--color Enable colors on console.
--no-color Disable colors on console.
-v, --version Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
-h, --help [verbose] Display help for commands and options.

To see list of all supported commands and options run 'webpack --help=verbose'.

Webpack documentation: https://webpack.js.org/.
CLI documentation: https://webpack.js.org/api/cli/.
Made with ♥ by the webpack team."
`;

exports[`basic serve usage should throw error when same ports in multicompiler: stderr 1`] = `
"[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.
at stack"
`;

exports[`basic serve usage should throw error when same ports in multicompiler: stdout 1`] = `""`;

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."`;

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

0 comments on commit a56761e

Please sign in to comment.