diff --git a/.eslintrc.js b/.eslintrc.js index 871471d890..046d37acb2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; module.exports = { - extends: ['webpack', 'prettier'], - parser: '@babel/eslint-parser', + extends: ["webpack", "prettier"], + parser: "@babel/eslint-parser", parserOptions: { - sourceType: 'script', + sourceType: "script", ecmaVersion: 2018, }, env: { @@ -12,34 +12,34 @@ module.exports = { es6: true, }, rules: { - curly: 'error', - 'consistent-return': 'off', - 'no-param-reassign': 'off', - 'no-underscore-dangle': 'off', - 'prefer-destructuring': ['error', { object: false, array: false }], - 'prefer-rest-params': 'off', - strict: ['error', 'safe'], - 'global-require': 'off', + curly: "error", + "consistent-return": "off", + "no-param-reassign": "off", + "no-underscore-dangle": "off", + "prefer-destructuring": ["error", { object: false, array: false }], + "prefer-rest-params": "off", + strict: ["error", "safe"], + "global-require": "off", }, overrides: [ { - files: ['client-src/**/*.js'], + files: ["client-src/**/*.js"], env: { browser: true, }, }, { - files: ['test/**/*.js'], + files: ["test/**/*.js"], rules: { - 'no-console': 'off', + "no-console": "off", }, }, { files: [ - 'test/client/**/*.js', - 'test/e2e/**/*.js', - 'test/fixtures/**/*.js', - 'test/server/liveReload-option.test.js', + "test/client/**/*.js", + "test/e2e/**/*.js", + "test/fixtures/**/*.js", + "test/server/liveReload-option.test.js", ], env: { browser: true, @@ -47,12 +47,12 @@ module.exports = { }, }, { - files: ['examples/**/*.js'], + files: ["examples/**/*.js"], env: { browser: true, }, rules: { - 'no-console': 'off', + "no-console": "off", }, }, ], diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 8323e7c946..8505d9a5fd 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,10 +1,10 @@ version: 2 updates: - package-ecosystem: npm - directory: '/' + directory: "/" schedule: interval: daily - time: '04:00' + time: "04:00" timezone: Europe/Berlin open-pull-requests-limit: 10 versioning-strategy: lockfile-only diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index 5c99735800..0000000000 --- a/.prettierrc.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -module.exports = { - singleQuote: true, - overrides: [ - { - files: '*.json', - options: { - useTabs: false, - }, - }, - ], -}; diff --git a/babel.config.js b/babel.config.js index 5e587952f9..fa4dceeb7c 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; module.exports = (api) => { api.cache(true); @@ -6,18 +6,18 @@ module.exports = (api) => { return { presets: [ [ - '@babel/preset-env', + "@babel/preset-env", { targets: { - node: '0.12', + node: "0.12", }, }, ], ], - plugins: ['@babel/plugin-transform-object-assign'], + plugins: ["@babel/plugin-transform-object-assign"], env: { test: { - plugins: ['@babel/plugin-transform-runtime'], + plugins: ["@babel/plugin-transform-runtime"], }, }, }; diff --git a/bin/cli-flags.js b/bin/cli-flags.js index af058c1253..153e0b353f 100644 --- a/bin/cli-flags.js +++ b/bin/cli-flags.js @@ -1,823 +1,823 @@ -'use strict'; +"use strict"; module.exports = { - 'allowed-hosts': { + "allowed-hosts": { configs: [ { - type: 'string', + type: "string", multiple: true, description: "Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto').", - path: 'allowedHosts[]', + path: "allowedHosts[]", }, { description: "Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto').", multiple: false, - path: 'allowedHosts', - type: 'enum', - values: ['auto', 'all'], + path: "allowedHosts", + type: "enum", + values: ["auto", "all"], }, ], description: "Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto').", multiple: true, - simpleType: 'string', + simpleType: "string", }, - 'allowed-hosts-reset': { + "allowed-hosts-reset": { configs: [ { - type: 'reset', + type: "reset", multiple: false, description: "Clear all items provided in 'allowedHosts' configuration. Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto').", - path: 'allowedHosts', + path: "allowedHosts", }, ], description: "Clear all items provided in 'allowedHosts' configuration. Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto').", - simpleType: 'boolean', + simpleType: "boolean", multiple: false, }, bonjour: { configs: [ { - type: 'boolean', + type: "boolean", multiple: false, description: - 'Allows to broadcasts dev server via ZeroConf networking on start.', - path: 'bonjour', + "Allows to broadcasts dev server via ZeroConf networking on start.", + path: "bonjour", }, ], description: - 'Allows to broadcasts dev server via ZeroConf networking on start.', + "Allows to broadcasts dev server via ZeroConf networking on start.", negatedDescription: - 'Disallows to broadcasts dev server via ZeroConf networking on start.', - simpleType: 'boolean', + "Disallows to broadcasts dev server via ZeroConf networking on start.", + simpleType: "boolean", multiple: false, }, - 'client-web-socket-transport': { + "client-web-socket-transport": { configs: [ { - type: 'enum', - values: ['sockjs', 'ws'], + type: "enum", + values: ["sockjs", "ws"], multiple: false, description: - 'Allows to set custom web socket transport to communicate with dev server.', - path: 'client.webSocketTransport', + "Allows to set custom web socket transport to communicate with dev server.", + path: "client.webSocketTransport", }, { - type: 'string', + type: "string", multiple: false, description: - 'Allows to set custom web socket transport to communicate with dev server.', - path: 'client.webSocketTransport', + "Allows to set custom web socket transport to communicate with dev server.", + path: "client.webSocketTransport", }, ], description: - 'Allows to set custom web socket transport to communicate with dev server.', - simpleType: 'string', + "Allows to set custom web socket transport to communicate with dev server.", + simpleType: "string", multiple: false, }, client: { configs: [ { description: - 'Allows to specify options for client script in the browser or disable client script.', + "Allows to specify options for client script in the browser or disable client script.", multiple: false, - path: 'client', - type: 'enum', + path: "client", + type: "enum", values: [false], }, ], description: - 'Allows to specify options for client script in the browser or disable client script.', + "Allows to specify options for client script in the browser or disable client script.", multiple: false, - simpleType: 'boolean', + simpleType: "boolean", }, - 'client-logging': { + "client-logging": { configs: [ { - type: 'enum', - values: ['none', 'error', 'warn', 'info', 'log', 'verbose'], + type: "enum", + values: ["none", "error", "warn", "info", "log", "verbose"], multiple: false, description: - 'Allows to specify options for client script in the browser or disable client script.', - path: 'client.logging', + "Allows to specify options for client script in the browser or disable client script.", + path: "client.logging", }, ], description: - 'Allows to specify options for client script in the browser or disable client script.', - simpleType: 'string', + "Allows to specify options for client script in the browser or disable client script.", + simpleType: "string", multiple: false, }, - 'client-progress': { + "client-progress": { configs: [ { - type: 'boolean', + type: "boolean", multiple: false, description: - 'Prints compilation progress in percentage in the browser.', - path: 'client.progress', + "Prints compilation progress in percentage in the browser.", + path: "client.progress", }, ], - description: 'Prints compilation progress in percentage in the browser.', + description: "Prints compilation progress in percentage in the browser.", negatedDescription: - 'Does not print compilation progress in percentage in the browser.', - simpleType: 'boolean', + "Does not print compilation progress in percentage in the browser.", + simpleType: "boolean", multiple: false, }, - 'client-overlay': { + "client-overlay": { configs: [ { - type: 'boolean', + type: "boolean", multiple: false, description: - 'Enables a full-screen overlay in the browser when there are compiler errors or warnings.', - path: 'client.overlay', + "Enables a full-screen overlay in the browser when there are compiler errors or warnings.", + path: "client.overlay", }, ], description: - 'Enables a full-screen overlay in the browser when there are compiler errors or warnings.', + "Enables a full-screen overlay in the browser when there are compiler errors or warnings.", negatedDescription: - 'Disables a full-screen overlay in the browser when there are compiler errors or warnings.', - simpleType: 'boolean', + "Disables a full-screen overlay in the browser when there are compiler errors or warnings.", + simpleType: "boolean", multiple: false, }, - 'client-overlay-errors': { + "client-overlay-errors": { configs: [ { - type: 'boolean', + type: "boolean", multiple: false, description: - 'Enables a full-screen overlay in the browser when there are compiler errors.', - path: 'client.overlay.errors', + "Enables a full-screen overlay in the browser when there are compiler errors.", + path: "client.overlay.errors", }, ], description: - 'Enables a full-screen overlay in the browser when there are compiler errors.', - simpleType: 'boolean', + "Enables a full-screen overlay in the browser when there are compiler errors.", + simpleType: "boolean", multiple: false, }, - 'client-overlay-warnings': { + "client-overlay-warnings": { configs: [ { - type: 'boolean', + type: "boolean", multiple: false, description: - 'Enables a full-screen overlay in the browser when there are compiler warnings.', - path: 'client.overlay.warnings', + "Enables a full-screen overlay in the browser when there are compiler warnings.", + path: "client.overlay.warnings", }, ], description: - 'Enables a full-screen overlay in the browser when there are compiler warnings.', - simpleType: 'boolean', + "Enables a full-screen overlay in the browser when there are compiler warnings.", + simpleType: "boolean", multiple: false, }, - 'client-web-socket-url': { + "client-web-socket-url": { configs: [ { - type: 'string', + type: "string", multiple: false, description: "Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to).", - path: 'client.webSocketURL', + path: "client.webSocketURL", }, ], description: "Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to).", - simpleType: 'string', + simpleType: "string", multiple: false, }, - 'client-web-socket-url-hostname': { + "client-web-socket-url-hostname": { configs: [ { - type: 'string', + type: "string", multiple: false, description: - 'Tells clients connected to devServer to use the provided hostname.', - path: 'client.webSocketURL.hostname', + "Tells clients connected to devServer to use the provided hostname.", + path: "client.webSocketURL.hostname", }, ], description: - 'Tells clients connected to devServer to use the provided hostname.', - simpleType: 'string', + "Tells clients connected to devServer to use the provided hostname.", + simpleType: "string", multiple: false, }, - 'client-web-socket-url-port': { + "client-web-socket-url-port": { configs: [ { - type: 'number', + type: "number", multiple: false, description: - 'Tells clients connected to devServer to use the provided port.', - path: 'client.webSocketURL.port', + "Tells clients connected to devServer to use the provided port.", + path: "client.webSocketURL.port", }, { description: - 'Tells clients connected to devServer to use the provided port.', + "Tells clients connected to devServer to use the provided port.", multiple: false, - path: 'client.webSocketURL.port', - type: 'string', + path: "client.webSocketURL.port", + type: "string", }, ], description: - 'Tells clients connected to devServer to use the provided port.', - simpleType: 'string', + "Tells clients connected to devServer to use the provided port.", + simpleType: "string", multiple: false, }, - 'client-web-socket-url-pathname': { + "client-web-socket-url-pathname": { configs: [ { - type: 'string', + type: "string", multiple: false, description: - 'Tells clients connected to devServer to use the provided path to connect.', - path: 'client.webSocketURL.pathname', + "Tells clients connected to devServer to use the provided path to connect.", + path: "client.webSocketURL.pathname", }, ], description: - 'Tells clients connected to devServer to use the provided path to connect.', - simpleType: 'string', + "Tells clients connected to devServer to use the provided path to connect.", + simpleType: "string", multiple: false, }, - 'client-web-socket-url-protocol': { + "client-web-socket-url-protocol": { configs: [ { description: - 'Tells clients connected to devServer to use the provided protocol.', + "Tells clients connected to devServer to use the provided protocol.", multiple: false, - path: 'client.webSocketURL.protocol', - type: 'enum', - values: ['auto'], + path: "client.webSocketURL.protocol", + type: "enum", + values: ["auto"], }, { description: - 'Tells clients connected to devServer to use the provided protocol.', + "Tells clients connected to devServer to use the provided protocol.", multiple: false, - path: 'client.webSocketURL.protocol', - type: 'string', + path: "client.webSocketURL.protocol", + type: "string", }, ], description: - 'Tells clients connected to devServer to use the provided protocol.', + "Tells clients connected to devServer to use the provided protocol.", multiple: false, - simpleType: 'string', + simpleType: "string", }, - 'client-web-socket-url-username': { + "client-web-socket-url-username": { configs: [ { - type: 'string', + type: "string", multiple: false, description: - 'Tells clients connected to devServer to use the provided username to authenticate.', - path: 'client.webSocketURL.username', + "Tells clients connected to devServer to use the provided username to authenticate.", + path: "client.webSocketURL.username", }, ], description: - 'Tells clients connected to devServer to use the provided username to authenticate.', - simpleType: 'string', + "Tells clients connected to devServer to use the provided username to authenticate.", + simpleType: "string", multiple: false, }, - 'client-web-socket-url-password': { + "client-web-socket-url-password": { configs: [ { - type: 'string', + type: "string", multiple: false, description: - 'Tells clients connected to devServer to use the provided password to authenticate.', - path: 'client.webSocketURL.password', + "Tells clients connected to devServer to use the provided password to authenticate.", + path: "client.webSocketURL.password", }, ], description: - 'Tells clients connected to devServer to use the provided password to authenticate.', - simpleType: 'string', + "Tells clients connected to devServer to use the provided password to authenticate.", + simpleType: "string", multiple: false, }, - 'web-socket-server': { + "web-socket-server": { configs: [ { - type: 'enum', - values: [false, 'sockjs', 'ws'], + type: "enum", + values: [false, "sockjs", "ws"], multiple: false, description: "Allows to set web socket server and options (by default 'ws').", - path: 'webSocketServer', + path: "webSocketServer", }, { - type: 'string', + type: "string", multiple: false, description: "Allows to set web socket server and options (by default 'ws').", - path: 'webSocketServer', + path: "webSocketServer", }, ], description: "Allows to set web socket server and options (by default 'ws').", - simpleType: 'string', + simpleType: "string", multiple: false, }, compress: { configs: [ { - type: 'boolean', + type: "boolean", multiple: false, - description: 'Enables gzip compression for everything served.', - path: 'compress', + description: "Enables gzip compression for everything served.", + path: "compress", }, ], - description: 'Enables gzip compression for everything served.', - negatedDescription: 'Disables gzip compression for everything served.', - simpleType: 'boolean', + description: "Enables gzip compression for everything served.", + negatedDescription: "Disables gzip compression for everything served.", + simpleType: "boolean", multiple: false, }, - 'history-api-fallback': { + "history-api-fallback": { configs: [ { - type: 'boolean', + type: "boolean", multiple: false, description: "Allows to proxy requests through a specified index page (by default 'index.html'), useful for Single Page Applications that utilise the HTML5 History API.", - path: 'historyApiFallback', + path: "historyApiFallback", }, ], description: "Allows to proxy requests through a specified index page (by default 'index.html'), useful for Single Page Applications that utilise the HTML5 History API.", - simpleType: 'boolean', + simpleType: "boolean", multiple: false, }, host: { configs: [ { - type: 'string', + type: "string", multiple: false, - description: 'Allows to specify a hostname to use.', - path: 'host', + description: "Allows to specify a hostname to use.", + path: "host", }, ], - description: 'Allows to specify a hostname to use.', - simpleType: 'string', + description: "Allows to specify a hostname to use.", + simpleType: "string", multiple: false, }, hot: { configs: [ { - type: 'boolean', + type: "boolean", multiple: false, - description: 'Enables Hot Module Replacement.', - path: 'hot', + description: "Enables Hot Module Replacement.", + path: "hot", }, { - type: 'enum', - values: ['only'], + type: "enum", + values: ["only"], multiple: false, - description: 'Enables Hot Module Replacement.', - path: 'hot', + description: "Enables Hot Module Replacement.", + path: "hot", }, ], - description: 'Enables Hot Module Replacement.', - negatedDescription: 'Disables Hot Module Replacement.', - simpleType: 'string', + description: "Enables Hot Module Replacement.", + negatedDescription: "Disables Hot Module Replacement.", + simpleType: "string", multiple: false, }, http2: { configs: [ { - type: 'boolean', + type: "boolean", multiple: false, - description: 'Allows to serve over HTTP/2 using SPDY.', - path: 'http2', + description: "Allows to serve over HTTP/2 using SPDY.", + path: "http2", }, ], - description: 'Allows to serve over HTTP/2 using SPDY.', - negatedDescription: 'Does not serve over HTTP/2 using SPDY.', - simpleType: 'boolean', + description: "Allows to serve over HTTP/2 using SPDY.", + negatedDescription: "Does not serve over HTTP/2 using SPDY.", + simpleType: "boolean", multiple: false, }, https: { configs: [ { - type: 'boolean', + type: "boolean", multiple: false, description: "Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP).", - path: 'https', + path: "https", }, ], description: "Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP).", negatedDescription: "Disallows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP).", - simpleType: 'boolean', + simpleType: "boolean", multiple: false, }, - 'https-passphrase': { + "https-passphrase": { configs: [ { - type: 'string', + type: "string", multiple: false, - description: 'Passphrase for a pfx file.', - path: 'https.passphrase', + description: "Passphrase for a pfx file.", + path: "https.passphrase", }, ], - description: 'Passphrase for a pfx file.', - simpleType: 'string', + description: "Passphrase for a pfx file.", + simpleType: "string", multiple: false, }, - 'https-request-cert': { + "https-request-cert": { configs: [ { - type: 'boolean', + type: "boolean", multiple: false, - description: 'Request for an SSL certificate.', - path: 'https.requestCert', + description: "Request for an SSL certificate.", + path: "https.requestCert", }, ], - description: 'Request for an SSL certificate.', - negatedDescription: 'Does not request for an SSL certificate.', - simpleType: 'boolean', + description: "Request for an SSL certificate.", + negatedDescription: "Does not request for an SSL certificate.", + simpleType: "boolean", multiple: false, }, - 'https-cacert': { + "https-cacert": { configs: [ { - type: 'string', + type: "string", multiple: false, - description: 'Path to an SSL CA certificate.', - path: 'https.cacert', + description: "Path to an SSL CA certificate.", + path: "https.cacert", }, ], - description: 'Path to an SSL CA certificate.', - simpleType: 'string', + description: "Path to an SSL CA certificate.", + simpleType: "string", multiple: false, }, - 'https-key': { + "https-key": { configs: [ { - type: 'string', + type: "string", multiple: false, - description: 'Path to an SSL key.', - path: 'https.key', + description: "Path to an SSL key.", + path: "https.key", }, ], - description: 'Path to an SSL key.', - simpleType: 'string', + description: "Path to an SSL key.", + simpleType: "string", multiple: false, }, - 'https-pfx': { + "https-pfx": { configs: [ { - type: 'string', + type: "string", multiple: false, - description: 'Path to an SSL pfx file.', - path: 'https.pfx', + description: "Path to an SSL pfx file.", + path: "https.pfx", }, ], - description: 'Path to an SSL pfx file.', - simpleType: 'string', + description: "Path to an SSL pfx file.", + simpleType: "string", multiple: false, }, - 'https-cert': { + "https-cert": { configs: [ { - type: 'string', + type: "string", multiple: false, - description: 'Path to an SSL certificate.', - path: 'https.cert', + description: "Path to an SSL certificate.", + path: "https.cert", }, ], - description: 'Path to an SSL certificate.', - simpleType: 'string', + description: "Path to an SSL certificate.", + simpleType: "string", multiple: false, }, ipc: { configs: [ { - type: 'string', + type: "string", multiple: false, - description: 'Listen to a unix socket.', - path: 'ipc', + description: "Listen to a unix socket.", + path: "ipc", }, { - type: 'enum', + type: "enum", values: [true], multiple: false, - description: 'Listen to a unix socket.', - path: 'ipc', + description: "Listen to a unix socket.", + path: "ipc", }, ], - description: 'Listen to a unix socket.', - simpleType: 'string', + description: "Listen to a unix socket.", + simpleType: "string", multiple: false, }, - 'live-reload': { + "live-reload": { configs: [ { - type: 'boolean', + type: "boolean", multiple: false, description: - 'Enables reload/refresh the page(s) when file changes are detected (enabled by default).', - path: 'liveReload', + "Enables reload/refresh the page(s) when file changes are detected (enabled by default).", + path: "liveReload", }, ], description: - 'Enables reload/refresh the page(s) when file changes are detected (enabled by default).', + "Enables reload/refresh the page(s) when file changes are detected (enabled by default).", negatedDescription: - 'Disables reload/refresh the page(s) when file changes are detected (enabled by default)', - simpleType: 'boolean', + "Disables reload/refresh the page(s) when file changes are detected (enabled by default)", + simpleType: "boolean", multiple: false, }, open: { configs: [ { - type: 'string', + type: "string", multiple: true, description: - 'Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).', - path: 'open[]', + "Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).", + path: "open[]", }, { - type: 'boolean', + type: "boolean", multiple: false, description: - 'Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).', - path: 'open', + "Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).", + path: "open", }, ], description: - 'Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).', - negatedDescription: 'Does not open the default browser.', - simpleType: 'string', + "Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).", + negatedDescription: "Does not open the default browser.", + simpleType: "string", multiple: true, }, - 'open-target': { + "open-target": { configs: [ { - type: 'string', + type: "string", multiple: true, - description: 'Opens specified page in browser.', - path: 'open[].target', + description: "Opens specified page in browser.", + path: "open[].target", }, { - type: 'string', + type: "string", multiple: true, - description: 'Opens specified page in browser.', - path: 'open.target[]', + description: "Opens specified page in browser.", + path: "open.target[]", }, ], - description: 'Opens specified page in browser.', - negatedDescription: 'Does not open specified page in browser.', - simpleType: 'string', + description: "Opens specified page in browser.", + negatedDescription: "Does not open specified page in browser.", + simpleType: "string", multiple: true, }, - 'open-app-name': { + "open-app-name": { configs: [ { - type: 'string', + type: "string", multiple: true, - description: 'Open specified browser.', - path: 'open[].app.name', + description: "Open specified browser.", + path: "open[].app.name", }, { - type: 'string', + type: "string", multiple: true, - description: 'Open specified browser.', - path: 'open.app.name[]', + description: "Open specified browser.", + path: "open.app.name[]", }, ], - description: 'Open specified browser.', - simpleType: 'string', + description: "Open specified browser.", + simpleType: "string", multiple: true, }, - 'open-app': { + "open-app": { configs: [ { - type: 'string', + type: "string", multiple: true, - description: 'Open specified browser.', - path: 'open[].app', + description: "Open specified browser.", + path: "open[].app", }, ], - description: 'Open specified browser.', - simpleType: 'string', + description: "Open specified browser.", + simpleType: "string", multiple: true, }, - 'open-reset': { + "open-reset": { configs: [ { - type: 'reset', + type: "reset", multiple: false, description: "Clear all items provided in 'open' configuration. Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).", - path: 'open', + path: "open", }, ], description: "Clear all items provided in 'open' configuration. Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).", - simpleType: 'boolean', + simpleType: "boolean", multiple: false, }, - 'open-target-reset': { + "open-target-reset": { configs: [ { - type: 'reset', + type: "reset", multiple: false, description: "Clear all items provided in 'open.target' configuration. Opens specified page in browser.", - path: 'open.target', + path: "open.target", }, ], description: "Clear all items provided in 'open.target' configuration. Opens specified page in browser.", - simpleType: 'boolean', + simpleType: "boolean", multiple: false, }, - 'open-app-name-reset': { + "open-app-name-reset": { configs: [ { - type: 'reset', + type: "reset", multiple: false, description: "Clear all items provided in 'open.app.name' configuration. Open specified browser.", - path: 'open.app.name', + path: "open.app.name", }, ], description: "Clear all items provided in 'open.app.name' configuration. Open specified browser.", - simpleType: 'boolean', + simpleType: "boolean", multiple: false, }, port: { configs: [ { - type: 'number', + type: "number", multiple: false, - description: 'Allows to specify a port to use.', - path: 'port', + description: "Allows to specify a port to use.", + path: "port", }, { - type: 'string', + type: "string", multiple: false, - description: 'Allows to specify a port to use.', - path: 'port', + description: "Allows to specify a port to use.", + path: "port", }, { - type: 'enum', - values: ['auto'], + type: "enum", + values: ["auto"], multiple: false, - description: 'Allows to specify a port to use.', - path: 'port', + description: "Allows to specify a port to use.", + path: "port", }, ], - description: 'Allows to specify a port to use.', - simpleType: 'string', + description: "Allows to specify a port to use.", + simpleType: "string", multiple: false, }, static: { configs: [ { - type: 'string', + type: "string", multiple: true, description: "Allows to configure options for serving static files from directory (by default 'public' directory).", - path: 'static[]', + path: "static[]", }, { - type: 'boolean', + type: "boolean", multiple: false, description: "Allows to configure options for serving static files from directory (by default 'public' directory).", - path: 'static', + path: "static", }, ], description: "Allows to configure options for serving static files from directory (by default 'public' directory).", - simpleType: 'string', + simpleType: "string", multiple: true, }, - 'static-directory': { + "static-directory": { configs: [ { - type: 'string', + type: "string", multiple: true, - description: 'Directory for static contents.', - path: 'static[].directory', + description: "Directory for static contents.", + path: "static[].directory", }, ], - description: 'Directory for static contents.', - simpleType: 'string', + description: "Directory for static contents.", + simpleType: "string", multiple: true, }, - 'static-public-path': { + "static-public-path": { configs: [ { - type: 'string', + type: "string", multiple: true, description: - 'The static files will be available in the browser under this public path.', - path: 'static[].publicPath', + "The static files will be available in the browser under this public path.", + path: "static[].publicPath", }, { - type: 'string', + type: "string", multiple: true, description: - 'The static files will be available in the browser under this public path.', - path: 'static.publicPath[]', + "The static files will be available in the browser under this public path.", + path: "static.publicPath[]", }, ], description: - 'The static files will be available in the browser under this public path.', - simpleType: 'string', + "The static files will be available in the browser under this public path.", + simpleType: "string", multiple: true, }, - 'static-serve-index': { + "static-serve-index": { configs: [ { - type: 'boolean', + type: "boolean", multiple: true, description: - 'Tells dev server to use serveIndex middleware when enabled.', - path: 'static[].serveIndex', + "Tells dev server to use serveIndex middleware when enabled.", + path: "static[].serveIndex", }, ], - description: 'Tells dev server to use serveIndex middleware when enabled.', + description: "Tells dev server to use serveIndex middleware when enabled.", negatedDescription: - 'Does not tell dev server to use serveIndex middleware.', - simpleType: 'boolean', + "Does not tell dev server to use serveIndex middleware.", + simpleType: "boolean", multiple: true, }, - 'static-watch': { + "static-watch": { configs: [ { - type: 'boolean', + type: "boolean", multiple: true, - description: 'Watches for files in static content directory.', - path: 'static[].watch', + description: "Watches for files in static content directory.", + path: "static[].watch", }, ], - description: 'Watches for files in static content directory.', - negatedDescription: 'Does not watch for files in static content directory.', - simpleType: 'boolean', + description: "Watches for files in static content directory.", + negatedDescription: "Does not watch for files in static content directory.", + simpleType: "boolean", multiple: true, }, - 'static-reset': { + "static-reset": { configs: [ { - type: 'reset', + type: "reset", multiple: false, description: "Clear all items provided in 'static' configuration. Allows to configure options for serving static files from directory (by default 'public' directory).", - path: 'static', + path: "static", }, ], description: "Clear all items provided in 'static' configuration. Allows to configure options for serving static files from directory (by default 'public' directory).", - simpleType: 'boolean', + simpleType: "boolean", multiple: false, }, - 'static-public-path-reset': { + "static-public-path-reset": { configs: [ { - type: 'reset', + type: "reset", multiple: false, description: "Clear all items provided in 'static.publicPath' configuration. The static files will be available in the browser under this public path.", - path: 'static.publicPath', + path: "static.publicPath", }, ], description: "Clear all items provided in 'static.publicPath' configuration. The static files will be available in the browser under this public path.", - simpleType: 'boolean', + simpleType: "boolean", multiple: false, }, - 'watch-files': { + "watch-files": { configs: [ { - type: 'string', + type: "string", multiple: true, description: - 'Allows to configure list of globs/directories/files to watch for file changes.', - path: 'watchFiles[]', + "Allows to configure list of globs/directories/files to watch for file changes.", + path: "watchFiles[]", }, ], description: - 'Allows to configure list of globs/directories/files to watch for file changes.', - simpleType: 'string', + "Allows to configure list of globs/directories/files to watch for file changes.", + simpleType: "string", multiple: true, }, - 'watch-files-reset': { + "watch-files-reset": { configs: [ { - type: 'reset', + type: "reset", multiple: false, description: "Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes.", - path: 'watchFiles', + path: "watchFiles", }, ], description: "Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes.", - simpleType: 'boolean', + simpleType: "boolean", multiple: false, }, }; diff --git a/bin/process-arguments.js b/bin/process-arguments.js index a87c1b04f0..b961d956e0 100644 --- a/bin/process-arguments.js +++ b/bin/process-arguments.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const path = require('path'); +const path = require("path"); // Based on https://github.com/webpack/webpack/blob/master/lib/cli.js // Please do not modify it @@ -12,13 +12,13 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => { return { value: config }; } - const parts = schemaPath.split('.'); + const parts = schemaPath.split("."); const property = parts.pop(); let current = config; let i = 0; for (const part of parts) { - const isArray = part.endsWith('[]'); + const isArray = part.endsWith("[]"); const name = isArray ? part.slice(0, -2) : part; let value = current[name]; @@ -31,8 +31,8 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => { } else if (!Array.isArray(value)) { return { problem: { - type: 'unexpected-non-array-in-path', - path: parts.slice(0, i).join('.'), + type: "unexpected-non-array-in-path", + path: parts.slice(0, i).join("."), }, }; } else { @@ -52,11 +52,11 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => { // eslint-disable-next-line no-undefined if (value[x] === undefined) { value[x] = {}; - } else if (value[x] === null || typeof value[x] !== 'object') { + } else if (value[x] === null || typeof value[x] !== "object") { return { problem: { - type: 'unexpected-non-object-in-path', - path: parts.slice(0, i).join('.'), + type: "unexpected-non-object-in-path", + path: parts.slice(0, i).join("."), }, }; } @@ -67,11 +67,11 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => { } else if (value === undefined) { // eslint-disable-next-line no-multi-assign value = current[name] = {}; - } else if (value === null || typeof value !== 'object') { + } else if (value === null || typeof value !== "object") { return { problem: { - type: 'unexpected-non-object-in-path', - path: parts.slice(0, i).join('.'), + type: "unexpected-non-object-in-path", + path: parts.slice(0, i).join("."), }, }; } @@ -83,7 +83,7 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => { const value = current[property]; - if (property.endsWith('[]')) { + if (property.endsWith("[]")) { const name = property.slice(0, -2); // eslint-disable-next-line no-shadow const value = current[name]; @@ -121,10 +121,10 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => { // eslint-disable-next-line no-undefined if (value[x] === undefined) { value[x] = {}; - } else if (value[x] === null || typeof value[x] !== 'object') { + } else if (value[x] === null || typeof value[x] !== "object") { return { problem: { - type: 'unexpected-non-object-in-path', + type: "unexpected-non-object-in-path", path: schemaPath, }, }; @@ -143,47 +143,47 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => { const parseValueForArgumentConfig = (argConfig, value) => { // eslint-disable-next-line default-case switch (argConfig.type) { - case 'string': - if (typeof value === 'string') { + case "string": + if (typeof value === "string") { return value; } break; - case 'path': - if (typeof value === 'string') { + case "path": + if (typeof value === "string") { return path.resolve(value); } break; - case 'number': - if (typeof value === 'number') { + case "number": + if (typeof value === "number") { return value; } - if (typeof value === 'string' && /^[+-]?\d*(\.\d*)[eE]\d+$/) { + if (typeof value === "string" && /^[+-]?\d*(\.\d*)[eE]\d+$/) { const n = +value; if (!isNaN(n)) return n; } break; - case 'boolean': - if (typeof value === 'boolean') { + case "boolean": + if (typeof value === "boolean") { return value; } - if (value === 'true') { + if (value === "true") { return true; } - if (value === 'false') { + if (value === "false") { return false; } break; - case 'RegExp': + case "RegExp": if (value instanceof RegExp) { return value; } - if (typeof value === 'string') { + if (typeof value === "string") { // cspell:word yugi const match = /^\/(.*)\/([yugi]*)$/.exec(value); @@ -193,7 +193,7 @@ const parseValueForArgumentConfig = (argConfig, value) => { } break; - case 'enum': + case "enum": if (argConfig.values.includes(value)) { return value; } @@ -203,7 +203,7 @@ const parseValueForArgumentConfig = (argConfig, value) => { } break; - case 'reset': + case "reset": if (value === true) { return []; } @@ -216,14 +216,14 @@ const getExpectedValue = (argConfig) => { switch (argConfig.type) { default: return argConfig.type; - case 'boolean': - return 'true | false'; - case 'RegExp': - return 'regular expression (example: /ab?c*/)'; - case 'enum': - return argConfig.values.map((v) => `${v}`).join(' | '); - case 'reset': - return 'true (will reset the previous value to an empty array)'; + case "boolean": + return "true | false"; + case "RegExp": + return "regular expression (example: /ab?c*/)"; + case "enum": + return argConfig.values.map((v) => `${v}`).join(" | "); + case "reset": + return "true (will reset the previous value to an empty array)"; } }; @@ -247,7 +247,7 @@ const processArgumentConfig = (argConfig, config, value, index) => { // eslint-disable-next-line no-undefined if (index !== undefined && !argConfig.multiple) { return { - type: 'multiple-values-unexpected', + type: "multiple-values-unexpected", path: argConfig.path, }; } @@ -257,7 +257,7 @@ const processArgumentConfig = (argConfig, config, value, index) => { // eslint-disable-next-line no-undefined if (parsed === undefined) { return { - type: 'invalid-value', + type: "invalid-value", path: argConfig.path, expected: getExpectedValue(argConfig), }; @@ -280,8 +280,8 @@ const processArguments = (args, config, values) => { if (!arg) { problems.push({ - type: 'unknown-argument', - path: '', + type: "unknown-argument", + path: "", argument: key, }); diff --git a/bin/webpack-dev-server.js b/bin/webpack-dev-server.js index f5d923f41d..c499ea1c49 100755 --- a/bin/webpack-dev-server.js +++ b/bin/webpack-dev-server.js @@ -2,7 +2,7 @@ /* Based on webpack/bin/webpack.js */ /* eslint-disable no-console */ -'use strict'; +"use strict"; /** * @param {string} command process to run @@ -10,18 +10,18 @@ * @returns {Promise} promise */ const runCommand = (command, args) => { - const cp = require('child_process'); + const cp = require("child_process"); return new Promise((resolve, reject) => { const executedCommand = cp.spawn(command, args, { - stdio: 'inherit', + stdio: "inherit", shell: true, }); - executedCommand.on('error', (error) => { + executedCommand.on("error", (error) => { reject(error); }); - executedCommand.on('exit', (code) => { + executedCommand.on("exit", (code) => { if (code === 0) { resolve(); } else { @@ -40,15 +40,15 @@ const isInstalled = (packageName) => { return true; } - const path = require('path'); - const fs = require('graceful-fs'); + const path = require("path"); + const fs = require("graceful-fs"); let dir = __dirname; do { try { if ( - fs.statSync(path.join(dir, 'node_modules', packageName)).isDirectory() + fs.statSync(path.join(dir, "node_modules", packageName)).isDirectory() ) { return true; } @@ -69,7 +69,7 @@ const runCli = (cli) => { if (cli.preprocess) { cli.preprocess(); } - const path = require('path'); + const path = require("path"); const pkgPath = require.resolve(`${cli.package}/package.json`); // eslint-disable-next-line import/no-dynamic-require const pkg = require(pkgPath); @@ -89,20 +89,20 @@ const runCli = (cli) => { /** @type {CliOption} */ const cli = { - name: 'webpack-cli', - package: 'webpack-cli', - binName: 'webpack-cli', - installed: isInstalled('webpack-cli'), - url: 'https://github.com/webpack/webpack-cli', + name: "webpack-cli", + package: "webpack-cli", + binName: "webpack-cli", + installed: isInstalled("webpack-cli"), + url: "https://github.com/webpack/webpack-cli", preprocess() { - process.argv.splice(2, 0, 'serve'); + process.argv.splice(2, 0, "serve"); }, }; if (!cli.installed) { - const path = require('path'); - const fs = require('graceful-fs'); - const readLine = require('readline'); + const path = require("path"); + const fs = require("graceful-fs"); + const readLine = require("readline"); const notify = `CLI for webpack must be installed.\n ${cli.name} (${cli.url})\n`; @@ -110,19 +110,19 @@ if (!cli.installed) { let packageManager; - if (fs.existsSync(path.resolve(process.cwd(), 'yarn.lock'))) { - packageManager = 'yarn'; - } else if (fs.existsSync(path.resolve(process.cwd(), 'pnpm-lock.yaml'))) { - packageManager = 'pnpm'; + if (fs.existsSync(path.resolve(process.cwd(), "yarn.lock"))) { + packageManager = "yarn"; + } else if (fs.existsSync(path.resolve(process.cwd(), "pnpm-lock.yaml"))) { + packageManager = "pnpm"; } else { - packageManager = 'npm'; + packageManager = "npm"; } - const installOptions = [packageManager === 'yarn' ? 'add' : 'install', '-D']; + const installOptions = [packageManager === "yarn" ? "add" : "install", "-D"]; console.error( `We will use "${packageManager}" to install the CLI via "${packageManager} ${installOptions.join( - ' ' + " " )} ${cli.package}".` ); @@ -140,12 +140,12 @@ if (!cli.installed) { questionInterface.question(question, (answer) => { questionInterface.close(); - const normalizedAnswer = answer.toLowerCase().startsWith('y'); + const normalizedAnswer = answer.toLowerCase().startsWith("y"); if (!normalizedAnswer) { console.error( "You need to install 'webpack-cli' to use webpack via CLI.\n" + - 'You can also install the CLI manually.' + "You can also install the CLI manually." ); return; @@ -155,7 +155,7 @@ if (!cli.installed) { console.log( `Installing '${ cli.package - }' (running '${packageManager} ${installOptions.join(' ')} ${ + }' (running '${packageManager} ${installOptions.join(" ")} ${ cli.package }')...` ); diff --git a/client-src/clients/SockJSClient.js b/client-src/clients/SockJSClient.js index 5fd1b7f39b..fbeb949829 100644 --- a/client-src/clients/SockJSClient.js +++ b/client-src/clients/SockJSClient.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const SockJS = require('../modules/sockjs-client'); -const { log } = require('../utils/log'); +const SockJS = require("../modules/sockjs-client"); +const { log } = require("../utils/log"); module.exports = class SockJSClient { constructor(url) { // SockJS requires `http` and `https` protocols this.sock = new SockJS( - url.replace(/^ws:/i, 'http:').replace(/^wss:/i, 'https:') + url.replace(/^ws:/i, "http:").replace(/^wss:/i, "https:") ); this.sock.onerror = (error) => { log.error(error); diff --git a/client-src/clients/WebsocketClient.js b/client-src/clients/WebsocketClient.js index 404f80f5a3..a6dc56bbc2 100644 --- a/client-src/clients/WebsocketClient.js +++ b/client-src/clients/WebsocketClient.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const { log } = require('../utils/log'); +const { log } = require("../utils/log"); module.exports = class WebsocketClient { constructor(url) { diff --git a/client-src/index.js b/client-src/index.js index 7cb4c1860f..037905c43c 100644 --- a/client-src/index.js +++ b/client-src/index.js @@ -1,18 +1,18 @@ -'use strict'; +"use strict"; /* global __resourceQuery WorkerGlobalScope */ -const webpackHotLog = require('webpack/hot/log'); -const stripAnsi = require('./modules/strip-ansi'); -const parseURL = require('./utils/parseURL'); -const socket = require('./socket'); -const overlay = require('./overlay'); -const { log, setLogLevel } = require('./utils/log'); -const sendMessage = require('./utils/sendMessage'); -const reloadApp = require('./utils/reloadApp'); -const createSocketURL = require('./utils/createSocketURL'); - -const status = { isUnloading: false, currentHash: '' }; +const webpackHotLog = require("webpack/hot/log"); +const stripAnsi = require("./modules/strip-ansi"); +const parseURL = require("./utils/parseURL"); +const socket = require("./socket"); +const overlay = require("./overlay"); +const { log, setLogLevel } = require("./utils/log"); +const sendMessage = require("./utils/sendMessage"); +const reloadApp = require("./utils/reloadApp"); +const createSocketURL = require("./utils/createSocketURL"); + +const status = { isUnloading: false, currentHash: "" }; const options = { hot: false, liveReload: false, @@ -29,7 +29,7 @@ if (parsedResourceQuery.logging) { function setAllLogLevel(level) { // This is needed because the HMR logger operate separately from dev server logger webpackHotLog.setLogLevel( - level === 'verbose' || level === 'log' ? 'info' : level + level === "verbose" || level === "log" ? "info" : level ); setLogLevel(level); } @@ -38,45 +38,45 @@ if (options.logging) { setAllLogLevel(options.logging); } -self.addEventListener('beforeunload', () => { +self.addEventListener("beforeunload", () => { status.isUnloading = true; }); const onSocketMessage = { hot() { - if (parsedResourceQuery.hot === 'false') { + if (parsedResourceQuery.hot === "false") { return; } options.hot = true; - log.info('Hot Module Replacement enabled.'); + log.info("Hot Module Replacement enabled."); }, liveReload() { - if (parsedResourceQuery['live-reload'] === 'false') { + if (parsedResourceQuery["live-reload"] === "false") { return; } options.liveReload = true; - log.info('Live Reloading enabled.'); + log.info("Live Reloading enabled."); }, invalid() { - log.info('App updated. Recompiling...'); + log.info("App updated. Recompiling..."); // Fixes #1042. overlay doesn't clear if errors are fixed but warnings remain. if (options.overlay) { overlay.hide(); } - sendMessage('Invalid'); + sendMessage("Invalid"); }, hash(hash) { status.currentHash = hash; }, logging: setAllLogLevel, overlay(value) { - if (typeof document === 'undefined') { + if (typeof document === "undefined") { return; } @@ -85,28 +85,28 @@ const onSocketMessage = { progress(progress) { options.progress = progress; }, - 'progress-update': function progressUpdate(data) { + "progress-update": function progressUpdate(data) { if (options.progress) { log.info( - `${data.pluginName ? `[${data.pluginName}] ` : ''}${data.percent}% - ${ + `${data.pluginName ? `[${data.pluginName}] ` : ""}${data.percent}% - ${ data.msg }.` ); } - sendMessage('Progress', data); + sendMessage("Progress", data); }, - 'still-ok': function stillOk() { - log.info('Nothing changed.'); + "still-ok": function stillOk() { + log.info("Nothing changed."); if (options.overlay) { overlay.hide(); } - sendMessage('StillOk'); + sendMessage("StillOk"); }, ok() { - sendMessage('Ok'); + sendMessage("Ok"); if (options.overlay) { overlay.hide(); @@ -119,44 +119,44 @@ const onSocketMessage = { reloadApp(options, status); }, // TODO: remove in v5 in favor of 'static-changed' - 'content-changed': function contentChanged(file) { + "content-changed": function contentChanged(file) { log.info( `${ - file ? `"${file}"` : 'Content' + file ? `"${file}"` : "Content" } from static directory was changed. Reloading...` ); self.location.reload(); }, - 'static-changed': function staticChanged(file) { + "static-changed": function staticChanged(file) { log.info( `${ - file ? `"${file}"` : 'Content' + file ? `"${file}"` : "Content" } from static directory was changed. Reloading...` ); self.location.reload(); }, warnings(warnings) { - log.warn('Warnings while compiling.'); + log.warn("Warnings while compiling."); const strippedWarnings = warnings.map((warning) => stripAnsi(warning.message ? warning.message : warning) ); - sendMessage('Warnings', strippedWarnings); + sendMessage("Warnings", strippedWarnings); for (let i = 0; i < strippedWarnings.length; i++) { log.warn(strippedWarnings[i]); } const needShowOverlay = - typeof options.overlay === 'boolean' + typeof options.overlay === "boolean" ? options.overlay : options.overlay && options.overlay.warnings; if (needShowOverlay) { - overlay.show(warnings, 'warnings'); + overlay.show(warnings, "warnings"); } if (options.initial) { @@ -166,25 +166,25 @@ const onSocketMessage = { reloadApp(options, status); }, errors(errors) { - log.error('Errors while compiling. Reload prevented.'); + log.error("Errors while compiling. Reload prevented."); const strippedErrors = errors.map((error) => stripAnsi(error.message ? error.message : error) ); - sendMessage('Errors', strippedErrors); + sendMessage("Errors", strippedErrors); for (let i = 0; i < strippedErrors.length; i++) { log.error(strippedErrors[i]); } const needShowOverlay = - typeof options.overlay === 'boolean' + typeof options.overlay === "boolean" ? options.overlay : options.overlay && options.overlay.errors; if (needShowOverlay) { - overlay.show(errors, 'errors'); + overlay.show(errors, "errors"); } options.initial = false; @@ -193,9 +193,9 @@ const onSocketMessage = { log.error(error); }, close() { - log.error('Disconnected!'); + log.error("Disconnected!"); - sendMessage('Close'); + sendMessage("Close"); }, }; diff --git a/client-src/modules/logger/SyncBailHookFake.js b/client-src/modules/logger/SyncBailHookFake.js index 9545e8c41f..ae6e5321de 100644 --- a/client-src/modules/logger/SyncBailHookFake.js +++ b/client-src/modules/logger/SyncBailHookFake.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; /** * Client stub for tapable SyncBailHook diff --git a/client-src/modules/logger/index.js b/client-src/modules/logger/index.js index 02c3765ae6..8e484b53b0 100644 --- a/client-src/modules/logger/index.js +++ b/client-src/modules/logger/index.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -module.exports = require('webpack/lib/logging/runtime'); +module.exports = require("webpack/lib/logging/runtime"); diff --git a/client-src/modules/sockjs-client/index.js b/client-src/modules/sockjs-client/index.js index 846dfd8a32..c36b6e878c 100644 --- a/client-src/modules/sockjs-client/index.js +++ b/client-src/modules/sockjs-client/index.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; // eslint-disable-next-line import/no-extraneous-dependencies -module.exports = require('sockjs-client'); +module.exports = require("sockjs-client"); diff --git a/client-src/modules/strip-ansi/index.js b/client-src/modules/strip-ansi/index.js index 4f9976e5b5..66c0f03433 100644 --- a/client-src/modules/strip-ansi/index.js +++ b/client-src/modules/strip-ansi/index.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -module.exports = require('strip-ansi').default; +module.exports = require("strip-ansi").default; diff --git a/client-src/overlay.js b/client-src/overlay.js index e8947fee59..10e3e66433 100644 --- a/client-src/overlay.js +++ b/client-src/overlay.js @@ -1,22 +1,22 @@ -'use strict'; +"use strict"; // The error overlay is inspired (and mostly copied) from Create React App (https://github.com/facebookincubator/create-react-app) // They, in turn, got inspired by webpack-hot-middleware (https://github.com/glenjamin/webpack-hot-middleware). -const ansiHTML = require('ansi-html'); -const { encode } = require('html-entities'); +const ansiHTML = require("ansi-html"); +const { encode } = require("html-entities"); const colors = { - reset: ['transparent', 'transparent'], - black: '181818', - red: 'E36049', - green: 'B3CB74', - yellow: 'FFD080', - blue: '7CAFC2', - magenta: '7FACCA', - cyan: 'C3C2EF', - lightgrey: 'EBE7E3', - darkgrey: '6D7891', + reset: ["transparent", "transparent"], + black: "181818", + red: "E36049", + green: "B3CB74", + yellow: "FFD080", + blue: "7CAFC2", + magenta: "7FACCA", + cyan: "C3C2EF", + lightgrey: "EBE7E3", + darkgrey: "6D7891", }; let iframeContainerElement; @@ -26,62 +26,62 @@ let onLoadQueue = []; ansiHTML.setColors(colors); function createContainer() { - iframeContainerElement = document.createElement('iframe'); - iframeContainerElement.id = 'webpack-dev-server-client-overlay'; - iframeContainerElement.src = 'about:blank'; - iframeContainerElement.style.position = 'fixed'; + iframeContainerElement = document.createElement("iframe"); + iframeContainerElement.id = "webpack-dev-server-client-overlay"; + iframeContainerElement.src = "about:blank"; + iframeContainerElement.style.position = "fixed"; iframeContainerElement.style.left = 0; iframeContainerElement.style.top = 0; iframeContainerElement.style.right = 0; iframeContainerElement.style.bottom = 0; - iframeContainerElement.style.width = '100vw'; - iframeContainerElement.style.height = '100vh'; - iframeContainerElement.style.border = 'none'; + iframeContainerElement.style.width = "100vw"; + iframeContainerElement.style.height = "100vh"; + iframeContainerElement.style.border = "none"; iframeContainerElement.style.zIndex = 9999999999; iframeContainerElement.onload = () => { containerElement = - iframeContainerElement.contentDocument.createElement('div'); - containerElement.id = 'webpack-dev-server-client-overlay-div'; - containerElement.style.position = 'fixed'; - containerElement.style.boxSizing = 'border-box'; + iframeContainerElement.contentDocument.createElement("div"); + containerElement.id = "webpack-dev-server-client-overlay-div"; + containerElement.style.position = "fixed"; + containerElement.style.boxSizing = "border-box"; containerElement.style.left = 0; containerElement.style.top = 0; containerElement.style.right = 0; containerElement.style.bottom = 0; - containerElement.style.width = '100vw'; - containerElement.style.height = '100vh'; - containerElement.style.backgroundColor = 'rgba(0, 0, 0, 0.85)'; - containerElement.style.color = '#E8E8E8'; - containerElement.style.fontFamily = 'Menlo, Consolas, monospace'; - containerElement.style.fontSize = 'large'; - containerElement.style.padding = '2rem'; - containerElement.style.lineHeight = '1.2'; - containerElement.style.whiteSpace = 'pre-wrap'; - containerElement.style.overflow = 'auto'; - - const headerElement = document.createElement('span'); - - headerElement.innerText = 'Compiled with problems:'; - - const closeButtonElement = document.createElement('button'); - - closeButtonElement.innerText = 'X'; - closeButtonElement.style.background = 'transparent'; - closeButtonElement.style.border = 'none'; - closeButtonElement.style.fontSize = '20px'; - closeButtonElement.style.fontWeight = 'bold'; - closeButtonElement.style.color = 'white'; - closeButtonElement.style.cursor = 'pointer'; - closeButtonElement.style.cssFloat = 'right'; - closeButtonElement.style.styleFloat = 'right'; - closeButtonElement.addEventListener('click', () => { + containerElement.style.width = "100vw"; + containerElement.style.height = "100vh"; + containerElement.style.backgroundColor = "rgba(0, 0, 0, 0.85)"; + containerElement.style.color = "#E8E8E8"; + containerElement.style.fontFamily = "Menlo, Consolas, monospace"; + containerElement.style.fontSize = "large"; + containerElement.style.padding = "2rem"; + containerElement.style.lineHeight = "1.2"; + containerElement.style.whiteSpace = "pre-wrap"; + containerElement.style.overflow = "auto"; + + const headerElement = document.createElement("span"); + + headerElement.innerText = "Compiled with problems:"; + + const closeButtonElement = document.createElement("button"); + + closeButtonElement.innerText = "X"; + closeButtonElement.style.background = "transparent"; + closeButtonElement.style.border = "none"; + closeButtonElement.style.fontSize = "20px"; + closeButtonElement.style.fontWeight = "bold"; + closeButtonElement.style.color = "white"; + closeButtonElement.style.cursor = "pointer"; + closeButtonElement.style.cssFloat = "right"; + closeButtonElement.style.styleFloat = "right"; + closeButtonElement.addEventListener("click", () => { hide(); }); containerElement.appendChild(headerElement); containerElement.appendChild(closeButtonElement); - containerElement.appendChild(document.createElement('br')); - containerElement.appendChild(document.createElement('br')); + containerElement.appendChild(document.createElement("br")); + containerElement.appendChild(document.createElement("br")); iframeContainerElement.contentDocument.body.appendChild(containerElement); @@ -130,10 +130,10 @@ function hide() { function show(messages, type) { ensureOverlayExists(() => { messages.forEach((message) => { - const entryElement = document.createElement('div'); - const typeElement = document.createElement('span'); + const entryElement = document.createElement("div"); + const typeElement = document.createElement("span"); - typeElement.innerText = type === 'warnings' ? 'Warning:' : 'Error:'; + typeElement.innerText = type === "warnings" ? "Warning:" : "Error:"; typeElement.style.color = `#${colors.red}`; // Make it look similar to our terminal. @@ -142,12 +142,12 @@ function show(messages, type) { const messageTextNode = document.createTextNode(text); entryElement.appendChild(typeElement); - entryElement.appendChild(document.createElement('br')); - entryElement.appendChild(document.createElement('br')); + entryElement.appendChild(document.createElement("br")); + entryElement.appendChild(document.createElement("br")); entryElement.appendChild(messageTextNode); - entryElement.appendChild(document.createElement('br')); - entryElement.appendChild(document.createElement('br')); - entryElement.appendChild(document.createElement('br')); + entryElement.appendChild(document.createElement("br")); + entryElement.appendChild(document.createElement("br")); + entryElement.appendChild(document.createElement("br")); containerElement.appendChild(entryElement); }); diff --git a/client-src/socket.js b/client-src/socket.js index 383e851975..f30c731bc1 100644 --- a/client-src/socket.js +++ b/client-src/socket.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; /* global __webpack_dev_server_client__ */ /* eslint-disable @@ -7,10 +7,10 @@ // this WebsocketClient is here as a default fallback, in case the client is not injected const Client = - typeof __webpack_dev_server_client__ !== 'undefined' + typeof __webpack_dev_server_client__ !== "undefined" ? __webpack_dev_server_client__ : // eslint-disable-next-line import/no-unresolved - require('./clients/WebsocketClient'); + require("./clients/WebsocketClient"); let retries = 0; let client = null; diff --git a/client-src/utils/createSocketURL.js b/client-src/utils/createSocketURL.js index d0ebbf25f9..8963fd1984 100644 --- a/client-src/utils/createSocketURL.js +++ b/client-src/utils/createSocketURL.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const url = require('url'); +const url = require("url"); // We handle legacy API that is Node.js specific, and a newer API that implements the same WHATWG URL Standard used by web browsers // Please look at https://nodejs.org/api/url.html#url_url_strings_and_url_objects @@ -10,7 +10,7 @@ function createSocketURL(parsedURL) { // Node.js module parses it as `::` // `new URL(urlString, [baseURLstring])` parses it as '[::]' const isInAddrAny = - hostname === '0.0.0.0' || hostname === '::' || hostname === '[::]'; + hostname === "0.0.0.0" || hostname === "::" || hostname === "[::]"; // why do we need this check? // hostname n/a for file protocol (example, when using electron, ionic) @@ -18,27 +18,27 @@ function createSocketURL(parsedURL) { if ( isInAddrAny && self.location.hostname && - self.location.protocol.indexOf('http') === 0 + self.location.protocol.indexOf("http") === 0 ) { hostname = self.location.hostname; } - let socketURLProtocol = parsedURL.protocol || 'ws:'; + let socketURLProtocol = parsedURL.protocol || "ws:"; // When https is used in the app, secure web sockets are always necessary because the browser doesn't accept non-secure web sockets. if ( - socketURLProtocol === 'auto:' || - (hostname && isInAddrAny && self.location.protocol === 'https:') + socketURLProtocol === "auto:" || + (hostname && isInAddrAny && self.location.protocol === "https:") ) { socketURLProtocol = self.location.protocol; } socketURLProtocol = socketURLProtocol.replace( /^(?:http|.+-extension|file)/i, - 'ws' + "ws" ); - let socketURLAuth = ''; + let socketURLAuth = ""; // `new URL(urlString, [baseURLstring])` doesn't have `auth` property // Parse authentication credentials in case we need them @@ -49,7 +49,7 @@ function createSocketURL(parsedURL) { // we only include password if the username is not empty. if (parsedURL.password) { // Result: : - socketURLAuth = socketURLAuth.concat(':', parsedURL.password); + socketURLAuth = socketURLAuth.concat(":", parsedURL.password); } } @@ -64,19 +64,19 @@ function createSocketURL(parsedURL) { const socketURLHostname = ( hostname || self.location.hostname || - 'localhost' - ).replace(/^\[(.*)\]$/, '$1'); + "localhost" + ).replace(/^\[(.*)\]$/, "$1"); let socketURLPort = parsedURL.port; - if (!socketURLPort || socketURLPort === '0') { + if (!socketURLPort || socketURLPort === "0") { socketURLPort = self.location.port; } // If path is provided it'll be passed in via the resourceQuery as a // query param so it has to be parsed out of the querystring in order for the // client to open the socket to the correct location. - let socketURLPathname = '/ws'; + let socketURLPathname = "/ws"; if (parsedURL.pathname && !parsedURL.fromCurrentScript) { socketURLPathname = parsedURL.pathname; diff --git a/client-src/utils/getCurrentScriptSource.js b/client-src/utils/getCurrentScriptSource.js index 737b16fc27..7f01dd18ff 100644 --- a/client-src/utils/getCurrentScriptSource.js +++ b/client-src/utils/getCurrentScriptSource.js @@ -1,28 +1,28 @@ -'use strict'; +"use strict"; function getCurrentScriptSource() { // `document.currentScript` is the most accurate way to find the current script, // but is not supported in all browsers. if (document.currentScript) { - return document.currentScript.getAttribute('src'); + return document.currentScript.getAttribute("src"); } // Fallback to getting all scripts running in the document. const scriptElements = document.scripts || []; const scriptElementsWithSrc = Array.prototype.filter.call( scriptElements, - (element) => element.getAttribute('src') + (element) => element.getAttribute("src") ); if (scriptElementsWithSrc.length > 0) { const currentScript = scriptElementsWithSrc[scriptElementsWithSrc.length - 1]; - return currentScript.getAttribute('src'); + return currentScript.getAttribute("src"); } // Fail as there was no script to use. - throw new Error('[webpack-dev-server] Failed to get current script source.'); + throw new Error("[webpack-dev-server] Failed to get current script source."); } module.exports = getCurrentScriptSource; diff --git a/client-src/utils/log.js b/client-src/utils/log.js index 2436686383..260e67fa75 100644 --- a/client-src/utils/log.js +++ b/client-src/utils/log.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; -const logger = require('../modules/logger'); +const logger = require("../modules/logger"); -const name = 'webpack-dev-server'; +const name = "webpack-dev-server"; // default level is set on the client side, so it does not need // to be set by the CLI or API -const defaultLevel = 'info'; +const defaultLevel = "info"; function setLogLevel(level) { logger.configureDefaultLogger({ level }); diff --git a/client-src/utils/parseURL.js b/client-src/utils/parseURL.js index effcc0f78b..45000a3de0 100644 --- a/client-src/utils/parseURL.js +++ b/client-src/utils/parseURL.js @@ -1,16 +1,16 @@ -'use strict'; +"use strict"; -const url = require('url'); -const getCurrentScriptSource = require('./getCurrentScriptSource'); +const url = require("url"); +const getCurrentScriptSource = require("./getCurrentScriptSource"); function parseURL(resourceQuery) { let options = {}; - if (typeof resourceQuery === 'string' && resourceQuery !== '') { - const searchParams = resourceQuery.substr(1).split('&'); + if (typeof resourceQuery === "string" && resourceQuery !== "") { + const searchParams = resourceQuery.substr(1).split("&"); for (let i = 0; i < searchParams.length; i++) { - const pair = searchParams[i].split('='); + const pair = searchParams[i].split("="); options[pair[0]] = decodeURIComponent(pair[1]); } diff --git a/client-src/utils/reloadApp.js b/client-src/utils/reloadApp.js index 12bfc5bbbe..6151f9cf3c 100644 --- a/client-src/utils/reloadApp.js +++ b/client-src/utils/reloadApp.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const { log } = require('./log'); +const { log } = require("./log"); function reloadApp({ hot, liveReload }, { isUnloading, currentHash }) { if (isUnloading) { @@ -10,26 +10,26 @@ function reloadApp({ hot, liveReload }, { isUnloading, currentHash }) { function applyReload(rootWindow, intervalId) { clearInterval(intervalId); - log.info('App updated. Reloading...'); + log.info("App updated. Reloading..."); rootWindow.location.reload(); } const search = self.location.search.toLowerCase(); - const allowToHot = search.indexOf('webpack-dev-server-hot=false') === -1; + const allowToHot = search.indexOf("webpack-dev-server-hot=false") === -1; const allowToLiveReload = - search.indexOf('webpack-dev-server-live-reload=false') === -1; + search.indexOf("webpack-dev-server-live-reload=false") === -1; if (hot && allowToHot) { - log.info('App hot update...'); + log.info("App hot update..."); - const hotEmitter = require('webpack/hot/emitter'); + const hotEmitter = require("webpack/hot/emitter"); - hotEmitter.emit('webpackHotUpdate', currentHash); + hotEmitter.emit("webpackHotUpdate", currentHash); - if (typeof self !== 'undefined' && self.window) { + if (typeof self !== "undefined" && self.window) { // broadcast update to window - self.postMessage(`webpackHotUpdate${currentHash}`, '*'); + self.postMessage(`webpackHotUpdate${currentHash}`, "*"); } } // allow refreshing the page only if liveReload isn't disabled @@ -38,7 +38,7 @@ function reloadApp({ hot, liveReload }, { isUnloading, currentHash }) { // use parent window for reload (in case we're in an iframe with no valid src) const intervalId = self.setInterval(() => { - if (rootWindow.location.protocol !== 'about:') { + if (rootWindow.location.protocol !== "about:") { // reload immediately if protocol is valid applyReload(rootWindow, intervalId); } else { diff --git a/client-src/utils/sendMessage.js b/client-src/utils/sendMessage.js index d36ee17a25..62f75a310e 100644 --- a/client-src/utils/sendMessage.js +++ b/client-src/utils/sendMessage.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; /* global __resourceQuery WorkerGlobalScope */ // Send messages to the outside, so plugins can consume it. function sendMsg(type, data) { if ( - typeof self !== 'undefined' && - (typeof WorkerGlobalScope === 'undefined' || + typeof self !== "undefined" && + (typeof WorkerGlobalScope === "undefined" || !(self instanceof WorkerGlobalScope)) ) { - self.postMessage({ type: `webpack${type}`, data }, '*'); + self.postMessage({ type: `webpack${type}`, data }, "*"); } } diff --git a/client-src/webpack.config.js b/client-src/webpack.config.js index 812b2ab572..a2eaad25fc 100644 --- a/client-src/webpack.config.js +++ b/client-src/webpack.config.js @@ -1,24 +1,24 @@ -'use strict'; +"use strict"; -const path = require('path'); -const webpack = require('webpack'); -const { merge } = require('webpack-merge'); +const path = require("path"); +const webpack = require("webpack"); +const { merge } = require("webpack-merge"); const baseForModules = { devtool: false, - mode: 'development', + mode: "development", output: { - path: path.resolve(__dirname, '../client/modules'), - libraryTarget: 'commonjs2', + path: path.resolve(__dirname, "../client/modules"), + libraryTarget: "commonjs2", }, - target: webpack.webpack ? ['web', 'es5'] : 'web', + target: webpack.webpack ? ["web", "es5"] : "web", module: { rules: [ { test: /\.js$/, use: [ { - loader: 'babel-loader', + loader: "babel-loader", }, ], }, @@ -28,9 +28,9 @@ const baseForModules = { module.exports = [ merge(baseForModules, { - entry: path.join(__dirname, 'modules/logger/index.js'), + entry: path.join(__dirname, "modules/logger/index.js"), output: { - filename: 'logger/index.js', + filename: "logger/index.js", }, module: { rules: [ @@ -38,9 +38,9 @@ module.exports = [ test: /\.js$/, use: [ { - loader: 'babel-loader', + loader: "babel-loader", options: { - plugins: ['@babel/plugin-transform-object-assign'], + plugins: ["@babel/plugin-transform-object-assign"], }, }, ], @@ -54,22 +54,22 @@ module.exports = [ }), new webpack.NormalModuleReplacementPlugin( /^tapable\/lib\/SyncBailHook/, - path.join(__dirname, 'modules/logger/SyncBailHookFake.js') + path.join(__dirname, "modules/logger/SyncBailHookFake.js") ), ], }), merge(baseForModules, { - entry: path.join(__dirname, 'modules/strip-ansi/index.js'), + entry: path.join(__dirname, "modules/strip-ansi/index.js"), output: { - filename: 'strip-ansi/index.js', + filename: "strip-ansi/index.js", }, }), merge(baseForModules, { - entry: path.join(__dirname, 'modules/sockjs-client/index.js'), + entry: path.join(__dirname, "modules/sockjs-client/index.js"), output: { - filename: 'sockjs-client/index.js', - library: 'SockJS', - libraryTarget: 'umd', + filename: "sockjs-client/index.js", + library: "SockJS", + libraryTarget: "umd", globalObject: "(typeof self !== 'undefined' ? self : this)", }, }), diff --git a/commitlint.config.js b/commitlint.config.js index 84dab2e23c..6d691b7681 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,5 +1,5 @@ -'use strict'; +"use strict"; module.exports = { - extends: ['@commitlint/config-conventional'], + extends: ["@commitlint/config-conventional"], }; diff --git a/examples/.assets/layout.html b/examples/.assets/layout.html index 8486072ee0..5be419cd91 100644 --- a/examples/.assets/layout.html +++ b/examples/.assets/layout.html @@ -17,7 +17,7 @@

webpack-dev-server

diff --git a/examples/.assets/style.css b/examples/.assets/style.css index c9005789e9..cc3f726c7d 100644 --- a/examples/.assets/style.css +++ b/examples/.assets/style.css @@ -1,17 +1,17 @@ @font-face { - font-family: 'Geomanist'; + font-family: "Geomanist"; font-style: normal; font-weight: 600; - src: url('assets/geomanist-medium.woff2') format('woff2'), - url('assets/geomanist-medium.woff') format('woff'); + src: url("assets/geomanist-medium.woff2") format("woff2"), + url("assets/geomanist-medium.woff") format("woff"); } html, body { background-color: #f3f3f3; color: #2b3a42; - font: 400 10px 'Source Sans Pro', -apple-system, BlinkMacSystemFont, - 'Segoe UI', Helvetica, Arial, sans-serif; + font: 400 10px "Source Sans Pro", -apple-system, BlinkMacSystemFont, + "Segoe UI", Helvetica, Arial, sans-serif; height: 100%; margin: 0; padding: 0; @@ -67,7 +67,7 @@ table { code { background-color: rgba(70, 94, 105, 0.06); border-radius: 3px; - font-family: 'Source Code Pro', Consolas, 'Liberation Mono', Menlo, Courier, + font-family: "Source Code Pro", Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1.44rem; margin: 0; diff --git a/examples/api/middleware/app.js b/examples/api/middleware/app.js index ae384858b9..51cf4a396b 100644 --- a/examples/api/middleware/app.js +++ b/examples/api/middleware/app.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; diff --git a/examples/api/middleware/server.js b/examples/api/middleware/server.js index 79a2d8c509..717521f6f0 100644 --- a/examples/api/middleware/server.js +++ b/examples/api/middleware/server.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const Webpack = require('webpack'); -const WebpackDevServer = require('../../../lib/Server'); -const webpackConfig = require('./webpack.config'); +const Webpack = require("webpack"); +const WebpackDevServer = require("../../../lib/Server"); +const webpackConfig = require("./webpack.config"); const compiler = Webpack(webpackConfig); const devServerOptions = webpackConfig.devServer; const server = new WebpackDevServer(devServerOptions, compiler); -server.listen(8080, '127.0.0.1', () => { - console.log('Starting server on http://localhost:8080'); +server.listen(8080, "127.0.0.1", () => { + console.log("Starting server on http://localhost:8080"); }); diff --git a/examples/api/middleware/webpack.config.js b/examples/api/middleware/webpack.config.js index 547faee867..74e736ae9a 100644 --- a/examples/api/middleware/webpack.config.js +++ b/examples/api/middleware/webpack.config.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", output: { - filename: 'bundle.js', + filename: "bundle.js", }, stats: { colors: true, diff --git a/examples/api/simple/app.js b/examples/api/simple/app.js index 4ad52540c6..c08e6931f6 100644 --- a/examples/api/simple/app.js +++ b/examples/api/simple/app.js @@ -1,9 +1,9 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; // This results in a warning: if (!window) { diff --git a/examples/api/simple/server.js b/examples/api/simple/server.js index ebf5bd056c..98e6b199f2 100644 --- a/examples/api/simple/server.js +++ b/examples/api/simple/server.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const Webpack = require('webpack'); -const WebpackDevServer = require('../../../lib/Server'); -const webpackConfig = require('./webpack.config'); +const Webpack = require("webpack"); +const WebpackDevServer = require("../../../lib/Server"); +const webpackConfig = require("./webpack.config"); const compiler = Webpack(webpackConfig); const devServerOptions = { ...webpackConfig.devServer, open: true }; const server = new WebpackDevServer(devServerOptions, compiler); -server.listen(8080, '127.0.0.1', () => { - console.log('Starting server on http://localhost:8080'); +server.listen(8080, "127.0.0.1", () => { + console.log("Starting server on http://localhost:8080"); }); diff --git a/examples/api/simple/webpack.config.js b/examples/api/simple/webpack.config.js index 547faee867..74e736ae9a 100644 --- a/examples/api/simple/webpack.config.js +++ b/examples/api/simple/webpack.config.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", output: { - filename: 'bundle.js', + filename: "bundle.js", }, stats: { colors: true, diff --git a/examples/cli/bonjour/README.md b/examples/cli/bonjour/README.md index 2b7f2c0ad2..95f9956d75 100644 --- a/examples/cli/bonjour/README.md +++ b/examples/cli/bonjour/README.md @@ -24,9 +24,9 @@ module.exports = { /* ... */ devServer: { bonjour: { - name: 'webpack-dev-server', - type: 'https', - subtype: 'webpack', + name: "webpack-dev-server", + type: "https", + subtype: "webpack", }, }, }; diff --git a/examples/cli/bonjour/app.js b/examples/cli/bonjour/app.js index 0b5f836ed8..f8e58b3b28 100644 --- a/examples/cli/bonjour/app.js +++ b/examples/cli/bonjour/app.js @@ -1,5 +1,5 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.innerHTML = 'Please check your Zeroconf service.'; +target.innerHTML = "Please check your Zeroconf service."; diff --git a/examples/cli/bonjour/webpack.config.js b/examples/cli/bonjour/webpack.config.js index e0e5363925..43b409e9d7 100644 --- a/examples/cli/bonjour/webpack.config.js +++ b/examples/cli/bonjour/webpack.config.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", }); diff --git a/examples/cli/compression/app.js b/examples/cli/compression/app.js index ae384858b9..51cf4a396b 100644 --- a/examples/cli/compression/app.js +++ b/examples/cli/compression/app.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; diff --git a/examples/cli/compression/webpack.config.js b/examples/cli/compression/webpack.config.js index e0e5363925..43b409e9d7 100644 --- a/examples/cli/compression/webpack.config.js +++ b/examples/cli/compression/webpack.config.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", }); diff --git a/examples/cli/default/app.js b/examples/cli/default/app.js index 75a70584d5..6b9de75e76 100644 --- a/examples/cli/default/app.js +++ b/examples/cli/default/app.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; -require('./style.less'); +require("./style.less"); -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; -const img = document.createElement('img'); -img.src = '/svg.svg'; -img.style = 'width: 200px;'; +const img = document.createElement("img"); +img.src = "/svg.svg"; +img.style = "width: 200px;"; document.body.appendChild(img); diff --git a/examples/cli/default/style.less b/examples/cli/default/style.less index 6eda1495fd..eed6953f6c 100644 --- a/examples/cli/default/style.less +++ b/examples/cli/default/style.less @@ -1,3 +1,3 @@ body { - background: url(pixels.png); + background: url(pixels.png); } diff --git a/examples/cli/default/webpack.config.js b/examples/cli/default/webpack.config.js index fbe28f6d6f..f1481a31b4 100644 --- a/examples/cli/default/webpack.config.js +++ b/examples/cli/default/webpack.config.js @@ -1,22 +1,22 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", module: { rules: [ { test: /\.less$/, - use: ['style-loader', 'css-loader', 'less-loader'], + use: ["style-loader", "css-loader", "less-loader"], }, { test: /\.png$/, - loader: 'file-loader', - options: { prefix: 'img/' }, + loader: "file-loader", + options: { prefix: "img/" }, }, ], }, diff --git a/examples/cli/history-api-fallback/app.js b/examples/cli/history-api-fallback/app.js index ea9e54c872..3587f810fc 100644 --- a/examples/cli/history-api-fallback/app.js +++ b/examples/cli/history-api-fallback/app.js @@ -1,8 +1,8 @@ -'use strict'; +"use strict"; const path = document.location.pathname; -const target = document.querySelector('#target'); -const style = document.createElement('style'); +const target = document.querySelector("#target"); +const style = document.createElement("style"); const css = `table { border-radius: 0.3rem; border: 0.1rem solid #474747; @@ -36,26 +36,26 @@ document.head.appendChild(style); target.innerHTML = `Current Path: ${path}`; document.addEventListener( - 'DOMContentLoaded', + "DOMContentLoaded", () => { - if (document.querySelector('#files')) { + if (document.querySelector("#files")) { return; } const tests = [ - { url: '/', name: 'index', re: /^/i }, - { url: '/test', name: 'non-existent path', re: /^/i }, - { url: '/file.txt', name: 'existing path', re: /^file/ }, + { url: "/", name: "index", re: /^/i }, + { url: "/test", name: "non-existent path", re: /^/i }, + { url: "/file.txt", name: "existing path", re: /^file/ }, ]; - const table = document.createElement('table'); - const tbody = document.createElement('tbody'); + const table = document.createElement("table"); + const tbody = document.createElement("tbody"); - table.id = 'files'; + table.id = "files"; table.appendChild(tbody); target.parentNode.appendChild(table); tests.forEach((test) => { - const tr = document.createElement('tr'); + const tr = document.createElement("tr"); tbody.appendChild(tr); check(test.url, test.re, (res) => { tr.innerHTML = `${test.name}`; @@ -69,9 +69,9 @@ document.addEventListener( function check(url, re, cb) { const xhr = new XMLHttpRequest(); - xhr.addEventListener('load', () => { - cb(re.test(xhr.responseText) ? 'pass' : 'fail'); + xhr.addEventListener("load", () => { + cb(re.test(xhr.responseText) ? "pass" : "fail"); }); - xhr.open('GET', url); + xhr.open("GET", url); xhr.send(); } diff --git a/examples/cli/history-api-fallback/webpack.config.js b/examples/cli/history-api-fallback/webpack.config.js index 732a179662..3f4336c9d9 100644 --- a/examples/cli/history-api-fallback/webpack.config.js +++ b/examples/cli/history-api-fallback/webpack.config.js @@ -1,12 +1,12 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", devServer: { historyApiFallback: { disableDotRule: true, diff --git a/examples/cli/hmr/app.js b/examples/cli/hmr/app.js index 31bc193f1e..3dff1ef2ee 100644 --- a/examples/cli/hmr/app.js +++ b/examples/cli/hmr/app.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; -require('./example'); +require("./example"); if (module.hot) { module.hot.accept((err) => { if (err) { - console.error('Cannot apply HMR update.', err); + console.error("Cannot apply HMR update.", err); } }); } diff --git a/examples/cli/hmr/example.js b/examples/cli/hmr/example.js index c13b4db3fd..77f80b74a7 100644 --- a/examples/cli/hmr/example.js +++ b/examples/cli/hmr/example.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); target.innerHTML = - 'Modify and save /examples/hmr/example.js to update this element without reloading the page.'; + "Modify and save /examples/hmr/example.js to update this element without reloading the page."; diff --git a/examples/cli/hmr/webpack.config.js b/examples/cli/hmr/webpack.config.js index e0e5363925..43b409e9d7 100644 --- a/examples/cli/hmr/webpack.config.js +++ b/examples/cli/hmr/webpack.config.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", }); diff --git a/examples/cli/host-and-port/app.js b/examples/cli/host-and-port/app.js index ae384858b9..51cf4a396b 100644 --- a/examples/cli/host-and-port/app.js +++ b/examples/cli/host-and-port/app.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; diff --git a/examples/cli/host-and-port/webpack.config.js b/examples/cli/host-and-port/webpack.config.js index e0e5363925..43b409e9d7 100644 --- a/examples/cli/host-and-port/webpack.config.js +++ b/examples/cli/host-and-port/webpack.config.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", }); diff --git a/examples/cli/https/app.js b/examples/cli/https/app.js index ae384858b9..51cf4a396b 100644 --- a/examples/cli/https/app.js +++ b/examples/cli/https/app.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; diff --git a/examples/cli/https/webpack.config.js b/examples/cli/https/webpack.config.js index e0e5363925..43b409e9d7 100644 --- a/examples/cli/https/webpack.config.js +++ b/examples/cli/https/webpack.config.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", }); diff --git a/examples/cli/multi-compiler/app.js b/examples/cli/multi-compiler/app.js index f5e44a9844..97c93a7f44 100644 --- a/examples/cli/multi-compiler/app.js +++ b/examples/cli/multi-compiler/app.js @@ -1,9 +1,9 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; // This results in an error: // if(!window) require("test"); diff --git a/examples/cli/multi-compiler/webpack.config.js b/examples/cli/multi-compiler/webpack.config.js index f627cf9715..5c29866c7b 100644 --- a/examples/cli/multi-compiler/webpack.config.js +++ b/examples/cli/multi-compiler/webpack.config.js @@ -1,12 +1,12 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = [ setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", }), ]; diff --git a/examples/cli/node-false/app.js b/examples/cli/node-false/app.js index ae384858b9..51cf4a396b 100644 --- a/examples/cli/node-false/app.js +++ b/examples/cli/node-false/app.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; diff --git a/examples/cli/node-false/webpack.config.js b/examples/cli/node-false/webpack.config.js index 8fc7670975..69640a6933 100644 --- a/examples/cli/node-false/webpack.config.js +++ b/examples/cli/node-false/webpack.config.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", node: false, }); diff --git a/examples/cli/open-target-multiple/app1.js b/examples/cli/open-target-multiple/app1.js index 45c49c5c7b..ebef30052b 100644 --- a/examples/cli/open-target-multiple/app1.js +++ b/examples/cli/open-target-multiple/app1.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -if (window.location.href.endsWith('example1.html')) { - target.classList.add('pass'); - target.innerHTML = 'Success!'; +if (window.location.href.endsWith("example1.html")) { + target.classList.add("pass"); + target.innerHTML = "Success!"; } else { - target.classList.add('fail'); - target.innerHTML = 'Houston, we have a problem.'; + target.classList.add("fail"); + target.innerHTML = "Houston, we have a problem."; } diff --git a/examples/cli/open-target-multiple/app2.js b/examples/cli/open-target-multiple/app2.js index ca59bf8047..97d45eb054 100644 --- a/examples/cli/open-target-multiple/app2.js +++ b/examples/cli/open-target-multiple/app2.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -if (window.location.href.endsWith('example2.html')) { - target.classList.add('pass'); - target.innerHTML = 'Success!'; +if (window.location.href.endsWith("example2.html")) { + target.classList.add("pass"); + target.innerHTML = "Success!"; } else { - target.classList.add('fail'); - target.innerHTML = 'Houston, we have a problem.'; + target.classList.add("fail"); + target.innerHTML = "Houston, we have a problem."; } diff --git a/examples/cli/open-target-multiple/webpack.config.js b/examples/cli/open-target-multiple/webpack.config.js index 27a4a344c4..56028d9d71 100644 --- a/examples/cli/open-target-multiple/webpack.config.js +++ b/examples/cli/open-target-multiple/webpack.config.js @@ -1,36 +1,36 @@ -'use strict'; +"use strict"; -const HtmlWebpackPlugin = require('html-webpack-plugin'); +const HtmlWebpackPlugin = require("html-webpack-plugin"); // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = [ setup({ context: __dirname, - entry: './app1.js', + entry: "./app1.js", output: { - filename: 'app1.js', + filename: "app1.js", }, plugins: [ new HtmlWebpackPlugin({ - filename: 'example1.html', - template: '../../.assets/layout.html', - title: 'Open Target (Multiple) / Example / Page 1', + filename: "example1.html", + template: "../../.assets/layout.html", + title: "Open Target (Multiple) / Example / Page 1", }), ], }), { context: __dirname, - entry: './app2.js', + entry: "./app2.js", output: { - filename: 'app2.js', + filename: "app2.js", }, plugins: [ new HtmlWebpackPlugin({ - filename: 'example2.html', - template: '../../.assets/layout.html', - title: 'Open Target (Multiple) / Example / Page 2', + filename: "example2.html", + template: "../../.assets/layout.html", + title: "Open Target (Multiple) / Example / Page 2", }), ], }, diff --git a/examples/cli/open-target/app.js b/examples/cli/open-target/app.js index 2570c6821c..c18dc29b7c 100644 --- a/examples/cli/open-target/app.js +++ b/examples/cli/open-target/app.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -if (window.location.href.endsWith('example.html#page1')) { - target.classList.add('pass'); - target.innerHTML = 'Success!'; +if (window.location.href.endsWith("example.html#page1")) { + target.classList.add("pass"); + target.innerHTML = "Success!"; } else { - target.classList.add('fail'); - target.innerHTML = 'Houston, we have a problem.'; + target.classList.add("fail"); + target.innerHTML = "Houston, we have a problem."; } diff --git a/examples/cli/open-target/webpack.config.js b/examples/cli/open-target/webpack.config.js index 3ab61234b8..9023c59a2f 100644 --- a/examples/cli/open-target/webpack.config.js +++ b/examples/cli/open-target/webpack.config.js @@ -1,18 +1,18 @@ -'use strict'; +"use strict"; -const HtmlWebpackPlugin = require('html-webpack-plugin'); +const HtmlWebpackPlugin = require("html-webpack-plugin"); // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", plugins: [ new HtmlWebpackPlugin({ - filename: 'example.html', - template: '../../.assets/layout.html', - title: 'Open Target / Example', + filename: "example.html", + template: "../../.assets/layout.html", + title: "Open Target / Example", }), ], }); diff --git a/examples/cli/overlay/app.js b/examples/cli/overlay/app.js index ae384858b9..51cf4a396b 100644 --- a/examples/cli/overlay/app.js +++ b/examples/cli/overlay/app.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; diff --git a/examples/cli/overlay/webpack.config.js b/examples/cli/overlay/webpack.config.js index 136082d1ed..20e126f66e 100644 --- a/examples/cli/overlay/webpack.config.js +++ b/examples/cli/overlay/webpack.config.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, // create error for overlay - entry: './invalid.js', + entry: "./invalid.js", }); diff --git a/examples/cli/progress/app.js b/examples/cli/progress/app.js index ae384858b9..51cf4a396b 100644 --- a/examples/cli/progress/app.js +++ b/examples/cli/progress/app.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; diff --git a/examples/cli/progress/webpack.config.js b/examples/cli/progress/webpack.config.js index e0e5363925..43b409e9d7 100644 --- a/examples/cli/progress/webpack.config.js +++ b/examples/cli/progress/webpack.config.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", }); diff --git a/examples/cli/watch-static/README.md b/examples/cli/watch-static/README.md index f51e247c86..28fa1932dd 100644 --- a/examples/cli/watch-static/README.md +++ b/examples/cli/watch-static/README.md @@ -20,7 +20,7 @@ npx webpack serve --static assets --open module.exports = { /* ... */ devServer: { - static: ['assets', 'css'], + static: ["assets", "css"], }, }; ``` diff --git a/examples/cli/watch-static/app.js b/examples/cli/watch-static/app.js index ae384858b9..51cf4a396b 100644 --- a/examples/cli/watch-static/app.js +++ b/examples/cli/watch-static/app.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; diff --git a/examples/cli/watch-static/assets/index.html b/examples/cli/watch-static/assets/index.html index d753fde8d8..6bcb27eb2e 100644 --- a/examples/cli/watch-static/assets/index.html +++ b/examples/cli/watch-static/assets/index.html @@ -1,11 +1,11 @@ - - - - -

Static

-
- - + + + + +

Static

+
+ + diff --git a/examples/cli/watch-static/webpack.config.js b/examples/cli/watch-static/webpack.config.js index 1441be63f2..9f31452ce6 100644 --- a/examples/cli/watch-static/webpack.config.js +++ b/examples/cli/watch-static/webpack.config.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", devServer: { - static: ['assets', 'css'], + static: ["assets", "css"], }, }); diff --git a/examples/cli/web-server-socket/app.js b/examples/cli/web-server-socket/app.js index ae384858b9..51cf4a396b 100644 --- a/examples/cli/web-server-socket/app.js +++ b/examples/cli/web-server-socket/app.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; diff --git a/examples/cli/web-server-socket/webpack.config.js b/examples/cli/web-server-socket/webpack.config.js index e0e5363925..43b409e9d7 100644 --- a/examples/cli/web-server-socket/webpack.config.js +++ b/examples/cli/web-server-socket/webpack.config.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", }); diff --git a/examples/cli/web-socket-url-cli/app.js b/examples/cli/web-socket-url-cli/app.js index ae384858b9..51cf4a396b 100644 --- a/examples/cli/web-socket-url-cli/app.js +++ b/examples/cli/web-socket-url-cli/app.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; diff --git a/examples/cli/web-socket-url-cli/webpack.config.js b/examples/cli/web-socket-url-cli/webpack.config.js index e0e5363925..43b409e9d7 100644 --- a/examples/cli/web-socket-url-cli/webpack.config.js +++ b/examples/cli/web-socket-url-cli/webpack.config.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", }); diff --git a/examples/cli/web-socket-url/app.js b/examples/cli/web-socket-url/app.js index 5184108804..b5ea7b6280 100644 --- a/examples/cli/web-socket-url/app.js +++ b/examples/cli/web-socket-url/app.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); target.innerHTML = - 'Please check the ws request in devtools, it should try to connect to the protocol + server defined in the webSocketURL setting.'; + "Please check the ws request in devtools, it should try to connect to the protocol + server defined in the webSocketURL setting."; diff --git a/examples/cli/web-socket-url/index.html b/examples/cli/web-socket-url/index.html index 3186011efe..df17bc03d7 100644 --- a/examples/cli/web-socket-url/index.html +++ b/examples/cli/web-socket-url/index.html @@ -1,8 +1,7 @@ - - - - - + + + + diff --git a/examples/cli/web-socket-url/webpack.config.js b/examples/cli/web-socket-url/webpack.config.js index 87783364ce..8fe4b5d921 100644 --- a/examples/cli/web-socket-url/webpack.config.js +++ b/examples/cli/web-socket-url/webpack.config.js @@ -1,17 +1,17 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", devServer: { - host: '0.0.0.0', + host: "0.0.0.0", client: { - webSocketURL: 'ws://localhost:8080', + webSocketURL: "ws://localhost:8080", }, - allowedHosts: 'all', + allowedHosts: "all", }, }); diff --git a/examples/general/config-array/app.js b/examples/general/config-array/app.js index 30895930f6..95630d3839 100644 --- a/examples/general/config-array/app.js +++ b/examples/general/config-array/app.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; -require('./style.less'); +require("./style.less"); -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; // This results in a warning: // if(!window) require("./" + window + "parseable.js"); diff --git a/examples/general/config-array/style.less b/examples/general/config-array/style.less index 6eda1495fd..eed6953f6c 100644 --- a/examples/general/config-array/style.less +++ b/examples/general/config-array/style.less @@ -1,3 +1,3 @@ body { - background: url(pixels.png); + background: url(pixels.png); } diff --git a/examples/general/config-array/webpack.config.js b/examples/general/config-array/webpack.config.js index e5c9fcf268..6894026069 100644 --- a/examples/general/config-array/webpack.config.js +++ b/examples/general/config-array/webpack.config.js @@ -1,42 +1,42 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = [ setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", module: { rules: [ { test: /\.less$/, - use: ['style-loader', 'css-loader', 'less-loader'], + use: ["style-loader", "css-loader", "less-loader"], }, { test: /\.png$/, - loader: 'file-loader', - options: { prefix: 'img/' }, + loader: "file-loader", + options: { prefix: "img/" }, }, ], }, }), { context: __dirname, - entry: './app.js', + entry: "./app.js", output: { - filename: 'bundle2.js', + filename: "bundle2.js", }, module: { rules: [ { test: /\.less$/, - use: ['style-loader', 'css-loader', 'less-loader'], + use: ["style-loader", "css-loader", "less-loader"], }, { test: /\.png$/, - loader: 'url-loader', + loader: "url-loader", options: { limit: 100000 }, }, ], diff --git a/examples/general/config-promise/app.js b/examples/general/config-promise/app.js index 13c1efa289..048032a34a 100644 --- a/examples/general/config-promise/app.js +++ b/examples/general/config-promise/app.js @@ -1,8 +1,8 @@ -'use strict'; +"use strict"; // Change the following line and save to see the compilation status -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; diff --git a/examples/general/config-promise/index.html b/examples/general/config-promise/index.html index 2048f209a7..45e5548d39 100644 --- a/examples/general/config-promise/index.html +++ b/examples/general/config-promise/index.html @@ -1,10 +1,10 @@ - - Promise Config Example - - - -

Example: Promise Config

- + + Promise Config Example + + + +

Example: Promise Config

+ diff --git a/examples/general/config-promise/webpack.config.js b/examples/general/config-promise/webpack.config.js index 96c1965834..b849a159a8 100644 --- a/examples/general/config-promise/webpack.config.js +++ b/examples/general/config-promise/webpack.config.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = new Promise((resolve) => { resolve( setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", devServer: {}, }) ); diff --git a/examples/general/proxy-advanced/app.js b/examples/general/proxy-advanced/app.js index ae384858b9..51cf4a396b 100644 --- a/examples/general/proxy-advanced/app.js +++ b/examples/general/proxy-advanced/app.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; diff --git a/examples/general/proxy-advanced/bypass.html b/examples/general/proxy-advanced/bypass.html index 4de2719156..564f37cb8e 100644 --- a/examples/general/proxy-advanced/bypass.html +++ b/examples/general/proxy-advanced/bypass.html @@ -1,8 +1,8 @@ - -

Example: proxy advanced

+ +

Example: proxy advanced

- Bypassed proxy! - + Bypassed proxy! + diff --git a/examples/general/proxy-advanced/webpack.config.js b/examples/general/proxy-advanced/webpack.config.js index a9232895f7..215ab84a01 100644 --- a/examples/general/proxy-advanced/webpack.config.js +++ b/examples/general/proxy-advanced/webpack.config.js @@ -1,23 +1,23 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", devServer: { proxy: { - '/api': { - target: 'http://jsonplaceholder.typicode.com/', + "/api": { + target: "http://jsonplaceholder.typicode.com/", changeOrigin: true, pathRewrite: { - '^/api': '', + "^/api": "", }, bypass(req) { - if (req.url === '/api/nope') { - return '/bypass.html'; + if (req.url === "/api/nope") { + return "/bypass.html"; } }, }, diff --git a/examples/general/proxy-hot-reload/README.md b/examples/general/proxy-hot-reload/README.md index 19fb4301fe..59543c9413 100644 --- a/examples/general/proxy-hot-reload/README.md +++ b/examples/general/proxy-hot-reload/README.md @@ -18,9 +18,9 @@ While the server is running, open `proxy-config.js` and replace the following: ```js module.exports = { - target: 'http://jsonplaceholder.typicode.com/', + target: "http://jsonplaceholder.typicode.com/", pathRewrite: { - '^/api': '', + "^/api": "", }, }; ``` @@ -29,7 +29,7 @@ with: ```js module.exports = { - target: 'http://reqres.in/', + target: "http://reqres.in/", }; ``` diff --git a/examples/general/proxy-hot-reload/app.js b/examples/general/proxy-hot-reload/app.js index ae384858b9..51cf4a396b 100644 --- a/examples/general/proxy-hot-reload/app.js +++ b/examples/general/proxy-hot-reload/app.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; diff --git a/examples/general/proxy-hot-reload/proxy-config.js b/examples/general/proxy-hot-reload/proxy-config.js index 19fbf56c03..62c787bba1 100644 --- a/examples/general/proxy-hot-reload/proxy-config.js +++ b/examples/general/proxy-hot-reload/proxy-config.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; /**/ module.exports = { - target: 'http://jsonplaceholder.typicode.com/', + target: "http://jsonplaceholder.typicode.com/", pathRewrite: { - '^/api': '', + "^/api": "", }, }; /**/ diff --git a/examples/general/proxy-hot-reload/webpack.config.js b/examples/general/proxy-hot-reload/webpack.config.js index 771fba74f4..64282cf23e 100644 --- a/examples/general/proxy-hot-reload/webpack.config.js +++ b/examples/general/proxy-hot-reload/webpack.config.js @@ -1,26 +1,26 @@ -'use strict'; +"use strict"; -const fs = require('fs'); +const fs = require("fs"); // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); -const proxyConfig = require('./proxy-config'); +const { setup } = require("../../util"); +const proxyConfig = require("./proxy-config"); let proxyOptions = { - context: '/api', + context: "/api", target: proxyConfig.target, pathRewrite: proxyConfig.pathRewrite, changeOrigin: true, }; -fs.watch('./proxy-config.js', () => { - delete require.cache[require.resolve('./proxy-config')]; +fs.watch("./proxy-config.js", () => { + delete require.cache[require.resolve("./proxy-config")]; try { - const newProxyConfig = require('./proxy-config'); + const newProxyConfig = require("./proxy-config"); if (proxyOptions.target !== newProxyConfig.target) { - console.log('Proxy target changed:', newProxyConfig.target); + console.log("Proxy target changed:", newProxyConfig.target); proxyOptions = { - context: '/api', + context: "/api", target: newProxyConfig.target, pathRewrite: newProxyConfig.pathRewrite, changeOrigin: true, @@ -33,7 +33,7 @@ fs.watch('./proxy-config.js', () => { module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", devServer: { proxy: [ function proxy() { diff --git a/examples/general/proxy-simple/app.js b/examples/general/proxy-simple/app.js index ae384858b9..51cf4a396b 100644 --- a/examples/general/proxy-simple/app.js +++ b/examples/general/proxy-simple/app.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); -target.classList.add('pass'); -target.innerHTML = 'Success!'; +target.classList.add("pass"); +target.innerHTML = "Success!"; diff --git a/examples/general/proxy-simple/webpack.config.js b/examples/general/proxy-simple/webpack.config.js index b0600b6cb7..6c600f15f3 100644 --- a/examples/general/proxy-simple/webpack.config.js +++ b/examples/general/proxy-simple/webpack.config.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = setup({ context: __dirname, - entry: './app.js', + entry: "./app.js", devServer: { proxy: { - '/api': 'http://127.0.0.1:50545', + "/api": "http://127.0.0.1:50545", }, }, }); diff --git a/examples/general/universal-config/client.js b/examples/general/universal-config/client.js index 9aaa31e805..0656b3449f 100644 --- a/examples/general/universal-config/client.js +++ b/examples/general/universal-config/client.js @@ -1,25 +1,25 @@ -'use strict'; +"use strict"; -const target = document.querySelector('#target'); +const target = document.querySelector("#target"); if (!window.fetch) { - target.classList.add('fail'); - target.innerHTML = 'fetch is not supported'; + target.classList.add("fail"); + target.innerHTML = "fetch is not supported"; } else { - fetch('/server.js') + fetch("/server.js") .then((res) => { - if (res.status === 404) throw new Error('[server.js]: Not Found'); + if (res.status === 404) throw new Error("[server.js]: Not Found"); return res; }) .then((res) => res.text()) .then((res) => { if (res.includes("console.log('webpack-dev-server/server');")) { - target.classList.add('pass'); - target.innerHTML = '[client.js, server.js]: Success!'; + target.classList.add("pass"); + target.innerHTML = "[client.js, server.js]: Success!"; } }) .catch((e) => { - target.classList.add('fail'); + target.classList.add("fail"); target.innerHTML = e.message; }); } diff --git a/examples/general/universal-config/server.js b/examples/general/universal-config/server.js index 3698fe5edd..e865358b35 100644 --- a/examples/general/universal-config/server.js +++ b/examples/general/universal-config/server.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('webpack-dev-server/server'); +console.log("webpack-dev-server/server"); diff --git a/examples/general/universal-config/webpack.config.js b/examples/general/universal-config/webpack.config.js index ebd58d44ef..cbf9a8ec7c 100644 --- a/examples/general/universal-config/webpack.config.js +++ b/examples/general/universal-config/webpack.config.js @@ -1,22 +1,22 @@ -'use strict'; +"use strict"; -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = [ setup({ - mode: 'development', - entry: './client.js', + mode: "development", + entry: "./client.js", output: { - filename: 'client.js', + filename: "client.js", }, context: __dirname, }), { - mode: 'development', - target: 'node', - entry: './server.js', + mode: "development", + target: "node", + entry: "./server.js", output: { - filename: 'server.js', + filename: "server.js", }, context: __dirname, node: false, diff --git a/examples/general/webworker/web.js b/examples/general/webworker/web.js index e6fba1fb6e..058353d668 100644 --- a/examples/general/webworker/web.js +++ b/examples/general/webworker/web.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; /* eslint-env browser */ -const worker = new Worker('worker.bundle.js'); +const worker = new Worker("worker.bundle.js"); worker.onmessage = function onMessage(e) { - console.log('[MAIN]', e); + console.log("[MAIN]", e); }; worker.postMessage({ hello: 111, diff --git a/examples/general/webworker/webpack.config.js b/examples/general/webworker/webpack.config.js index fb0f02a94d..9bee0a16d3 100644 --- a/examples/general/webworker/webpack.config.js +++ b/examples/general/webworker/webpack.config.js @@ -1,21 +1,21 @@ -'use strict'; +"use strict"; // our setup function adds behind-the-scenes bits to the config that all of our // examples need -const { setup } = require('../../util'); +const { setup } = require("../../util"); module.exports = [ setup({ - devtool: 'source-map', - target: 'web', - entry: './web.js', + devtool: "source-map", + target: "web", + entry: "./web.js", }), { - devtool: 'source-map', - target: 'webworker', - entry: './worker.js', + devtool: "source-map", + target: "webworker", + entry: "./worker.js", output: { - filename: 'worker.bundle.js', + filename: "worker.bundle.js", path: __dirname, }, }, diff --git a/examples/general/webworker/worker.js b/examples/general/webworker/worker.js index a62ee769c2..febf315aae 100644 --- a/examples/general/webworker/worker.js +++ b/examples/general/webworker/worker.js @@ -1,9 +1,9 @@ -'use strict'; +"use strict"; /* eslint-env worker */ self.onmessage = function onMessage(e) { - console.log('[WORKER]', e); + console.log("[WORKER]", e); self.postMessage({ hello: 222, }); diff --git a/examples/util.js b/examples/util.js index 1e68058c4c..aa5eb3dc50 100644 --- a/examples/util.js +++ b/examples/util.js @@ -1,22 +1,22 @@ -'use strict'; +"use strict"; /* eslint-disable import/no-extraneous-dependencies */ -const path = require('path'); -const fs = require('graceful-fs'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); -const marked = require('marked'); +const path = require("path"); +const fs = require("graceful-fs"); +const HtmlWebpackPlugin = require("html-webpack-plugin"); +const marked = require("marked"); module.exports = { setup(config) { - const defaults = { mode: 'development', plugins: [], devServer: {} }; + const defaults = { mode: "development", plugins: [], devServer: {} }; if (config.entry) { - if (typeof config.entry === 'string') { + if (typeof config.entry === "string") { config.entry = path.resolve(config.entry); } else if (Array.isArray(config.entry)) { config.entry = config.entry.map((entry) => path.resolve(entry)); - } else if (typeof config.entry === 'object') { + } else if (typeof config.entry === "object") { Object.entries(config.entry).forEach(([key, value]) => { config.entry[key] = path.resolve(value); }); @@ -25,8 +25,8 @@ module.exports = { const result = { ...defaults, ...config }; const onBeforeSetupMiddleware = ({ app }) => { - app.get('/.assets/*', (req, res) => { - const filename = path.join(__dirname, '/', req.path); + app.get("/.assets/*", (req, res) => { + const filename = path.join(__dirname, "/", req.path); res.sendFile(filename); }); }; @@ -42,15 +42,15 @@ module.exports = { mangle: true, smartLists: false, silent: false, - langPrefix: 'lang-', + langPrefix: "lang-", smartypants: false, - headerPrefix: '', + headerPrefix: "", renderer, xhtml: false, }; - const readme = fs.readFileSync('README.md', 'utf-8'); + const readme = fs.readFileSync("README.md", "utf-8"); - let exampleTitle = ''; + let exampleTitle = ""; renderer.heading = function headingProxy(text, level, raw, slugger) { if (level === 1 && !exampleTitle) { @@ -66,8 +66,8 @@ module.exports = { result.plugins.push( new HtmlWebpackPlugin({ - filename: 'index.html', - template: path.join(__dirname, '.assets/layout.html'), + filename: "index.html", + template: path.join(__dirname, ".assets/layout.html"), title: exampleTitle, }) ); diff --git a/globalSetupTest.js b/globalSetupTest.js index fa14343cc9..909cbe552e 100644 --- a/globalSetupTest.js +++ b/globalSetupTest.js @@ -1,9 +1,9 @@ -'use strict'; +"use strict"; // eslint-disable-next-line import/no-extraneous-dependencies -const tcpPortUsed = require('tcp-port-used'); -const { version } = require('webpack'); -const ports = require('./test/ports-map'); +const tcpPortUsed = require("tcp-port-used"); +const { version } = require("webpack"); +const ports = require("./test/ports-map"); // eslint-disable-next-line no-console console.log(`\n Running tests for webpack @${version} \n`); @@ -16,7 +16,7 @@ async function validatePorts() { const arr = Array.isArray(value) ? value : [value]; arr.forEach((port) => { - const check = tcpPortUsed.check(port, 'localhost').then((inUse) => { + const check = tcpPortUsed.check(port, "localhost").then((inUse) => { if (inUse) { throw new Error(`${port} has already used. [${key}]`); } diff --git a/jest.config.js b/jest.config.js index 1c028ecc39..e2a685e2b5 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; module.exports = { - testURL: 'http://localhost/', + testURL: "http://localhost/", collectCoverage: false, coveragePathIgnorePatterns: [ - '/node_modules/', - '/test/', - '/client/', + "/node_modules/", + "/test/", + "/client/", ], - testPathIgnorePatterns: ['/bin/this/process-arguments.js'], - snapshotResolver: '/test/helpers/snapshotResolver.js', - setupFilesAfterEnv: ['/setupTest.js'], - globalSetup: '/globalSetupTest.js', + testPathIgnorePatterns: ["/bin/this/process-arguments.js"], + snapshotResolver: "/test/helpers/snapshotResolver.js", + setupFilesAfterEnv: ["/setupTest.js"], + globalSetup: "/globalSetupTest.js", }; diff --git a/lib/Server.js b/lib/Server.js index bba37b1e80..45554ef542 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -1,17 +1,17 @@ -'use strict'; - -const net = require('net'); -const path = require('path'); -const fs = require('fs'); -const url = require('url'); -const ipaddr = require('ipaddr.js'); -const internalIp = require('internal-ip'); -const killable = require('killable'); -const express = require('express'); -const { validate } = require('schema-utils'); -const normalizeOptions = require('./utils/normalizeOptions'); -const getCompilerConfigArray = require('./utils/getCompilerConfigArray'); -const schema = require('./options.json'); +"use strict"; + +const net = require("net"); +const path = require("path"); +const fs = require("fs"); +const url = require("url"); +const ipaddr = require("ipaddr.js"); +const internalIp = require("internal-ip"); +const killable = require("killable"); +const express = require("express"); +const { validate } = require("schema-utils"); +const normalizeOptions = require("./utils/normalizeOptions"); +const getCompilerConfigArray = require("./utils/getCompilerConfigArray"); +const schema = require("./options.json"); if (!process.env.WEBPACK_SERVE) { process.env.WEBPACK_SERVE = true; @@ -24,11 +24,11 @@ class Server { [options, compiler] = [compiler, options]; } - validate(schema, options, 'webpack Dev Server'); + validate(schema, options, "webpack Dev Server"); this.compiler = compiler; this.options = options; - this.logger = this.compiler.getInfrastructureLogger('webpack-dev-server'); + this.logger = this.compiler.getInfrastructureLogger("webpack-dev-server"); this.staticWatchers = []; // Keep track of websocket proxies for external websocket upgrade. this.webSocketProxies = []; @@ -61,7 +61,7 @@ class Server { killable(this.server); if (this.options.setupExitSignals) { - const signals = ['SIGINT', 'SIGTERM']; + const signals = ["SIGINT", "SIGTERM"]; signals.forEach((signal) => { process.on(signal, () => { @@ -77,7 +77,7 @@ class Server { // https://github.com/chimurai/http-proxy-middleware#external-websocket-upgrade // eslint-disable-next-line func-names this.webSocketProxies.forEach(function (webSocketProxy) { - this.server.on('upgrade', webSocketProxy.upgrade); + this.server.on("upgrade", webSocketProxy.upgrade); }, this); } @@ -93,22 +93,22 @@ class Server { } static getHostname(hostname) { - if (hostname === 'local-ip') { - return internalIp.v4.sync() || internalIp.v6.sync() || '0.0.0.0'; - } else if (hostname === 'local-ipv4') { - return internalIp.v4.sync() || '0.0.0.0'; - } else if (hostname === 'local-ipv6') { - return internalIp.v6.sync() || '::'; + if (hostname === "local-ip") { + return internalIp.v4.sync() || internalIp.v6.sync() || "0.0.0.0"; + } else if (hostname === "local-ipv4") { + return internalIp.v4.sync() || "0.0.0.0"; + } else if (hostname === "local-ipv6") { + return internalIp.v6.sync() || "::"; } return hostname; } static getFreePort(port) { - const pRetry = require('p-retry'); - const portfinder = require('portfinder'); + const pRetry = require("p-retry"); + const portfinder = require("portfinder"); - if (port && port !== 'auto') { + if (port && port !== "auto") { return Promise.resolve(port); } @@ -141,7 +141,7 @@ class Server { for (;;) { try { - if (fs.statSync(path.join(dir, 'package.json')).isFile()) break; + if (fs.statSync(path.join(dir, "package.json")).isFile()) break; // eslint-disable-next-line no-empty } catch (e) {} @@ -157,18 +157,18 @@ class Server { } if (!dir) { - return path.resolve(cwd, '.cache/webpack-dev-server'); - } else if (process.versions.pnp === '1') { - return path.resolve(dir, '.pnp/.cache/webpack-dev-server'); - } else if (process.versions.pnp === '3') { - return path.resolve(dir, '.yarn/.cache/webpack-dev-server'); + return path.resolve(cwd, ".cache/webpack-dev-server"); + } else if (process.versions.pnp === "1") { + return path.resolve(dir, ".pnp/.cache/webpack-dev-server"); + } else if (process.versions.pnp === "3") { + return path.resolve(dir, ".yarn/.cache/webpack-dev-server"); } - return path.resolve(dir, 'node_modules/.cache/webpack-dev-server'); + return path.resolve(dir, "node_modules/.cache/webpack-dev-server"); } applyDevServerPlugin() { - const DevServerPlugin = require('./utils/DevServerPlugin'); + const DevServerPlugin = require("./utils/DevServerPlugin"); const compilers = this.compiler.compilers || [this.compiler]; @@ -179,13 +179,13 @@ class Server { } setupProgressPlugin() { - const { ProgressPlugin } = this.compiler.webpack || require('webpack'); + const { ProgressPlugin } = this.compiler.webpack || require("webpack"); new ProgressPlugin((percent, msg, addInfo, pluginName) => { percent = Math.floor(percent * 100); if (percent === 100) { - msg = 'Compilation completed'; + msg = "Compilation completed"; } if (addInfo) { @@ -193,7 +193,7 @@ class Server { } if (this.webSocketServer) { - this.sendMessage(this.webSocketServer.clients, 'progress-update', { + this.sendMessage(this.webSocketServer.clients, "progress-update", { percent, msg, pluginName, @@ -201,7 +201,7 @@ class Server { } if (this.server) { - this.server.emit('progress-update', { percent, msg, pluginName }); + this.server.emit("progress-update", { percent, msg, pluginName }); } }).apply(this.compiler); } @@ -214,12 +214,12 @@ class Server { setupHooks() { const addHooks = (compiler) => { - compiler.hooks.invalid.tap('webpack-dev-server', () => { + compiler.hooks.invalid.tap("webpack-dev-server", () => { if (this.webSocketServer) { - this.sendMessage(this.webSocketServer.clients, 'invalid'); + this.sendMessage(this.webSocketServer.clients, "invalid"); } }); - compiler.hooks.done.tap('webpack-dev-server', (stats) => { + compiler.hooks.done.tap("webpack-dev-server", (stats) => { if (this.webSocketServer) { this.sendStats(this.webSocketServer.clients, this.getStats(stats)); } @@ -236,17 +236,17 @@ class Server { } setupHostHeaderCheck() { - this.app.all('*', (req, res, next) => { + this.app.all("*", (req, res, next) => { if (this.checkHostHeader(req.headers)) { return next(); } - res.send('Invalid Host header'); + res.send("Invalid Host header"); }); } setupDevMiddleware() { - const webpackDevMiddleware = require('webpack-dev-middleware'); + const webpackDevMiddleware = require("webpack-dev-middleware"); // middleware for serving webpack bundle this.middleware = webpackDevMiddleware( @@ -258,47 +258,47 @@ class Server { setupBuiltInRoutes() { const { app, middleware } = this; - app.get('/__webpack_dev_server__/sockjs.bundle.js', (req, res) => { - res.setHeader('Content-Type', 'application/javascript'); + app.get("/__webpack_dev_server__/sockjs.bundle.js", (req, res) => { + res.setHeader("Content-Type", "application/javascript"); - const { createReadStream } = require('graceful-fs'); - const clientPath = path.join(__dirname, '..', 'client'); + const { createReadStream } = require("graceful-fs"); + const clientPath = path.join(__dirname, "..", "client"); createReadStream( - path.join(clientPath, 'modules/sockjs-client/index.js') + path.join(clientPath, "modules/sockjs-client/index.js") ).pipe(res); }); - app.get('/webpack-dev-server/invalidate', (_req, res) => { + app.get("/webpack-dev-server/invalidate", (_req, res) => { this.invalidate(); res.end(); }); - app.get('/webpack-dev-server', (req, res) => { + app.get("/webpack-dev-server", (req, res) => { middleware.waitUntilValid((stats) => { - res.setHeader('Content-Type', 'text/html'); + res.setHeader("Content-Type", "text/html"); res.write( '' ); const statsForPrint = - typeof stats.stats !== 'undefined' + typeof stats.stats !== "undefined" ? stats.toJson().children : [stats.toJson()]; res.write(`

Assets Report:

`); statsForPrint.forEach((item, index) => { - res.write('
'); + res.write("
"); const name = - item.name || (stats.stats ? `unnamed[${index}]` : 'unnamed'); + item.name || (stats.stats ? `unnamed[${index}]` : "unnamed"); res.write(`

Compilation: ${name}

`); - res.write('
    '); + res.write("
      "); - const publicPath = item.publicPath === 'auto' ? '' : item.publicPath; + const publicPath = item.publicPath === "auto" ? "" : item.publicPath; for (const asset of item.assets) { const assetName = asset.name; @@ -311,23 +311,23 @@ class Server { ); } - res.write('
    '); - res.write('
'); + res.write(""); + res.write("
"); }); - res.end(''); + res.end(""); }); }); } setupCompressFeature() { - const compress = require('compression'); + const compress = require("compression"); this.app.use(compress()); } setupProxyFeature() { - const { createProxyMiddleware } = require('http-proxy-middleware'); + const { createProxyMiddleware } = require("http-proxy-middleware"); const getProxyMiddleware = (proxyConfig) => { const context = proxyConfig.context || proxyConfig.path; @@ -358,7 +358,7 @@ class Server { let proxyMiddleware; let proxyConfig = - typeof proxyConfigOrCallback === 'function' + typeof proxyConfigOrCallback === "function" ? proxyConfigOrCallback() : proxyConfigOrCallback; @@ -369,7 +369,7 @@ class Server { } const handle = async (req, res, next) => { - if (typeof proxyConfigOrCallback === 'function') { + if (typeof proxyConfigOrCallback === "function") { const newProxyConfig = proxyConfigOrCallback(req, res, next); if (newProxyConfig !== proxyConfig) { @@ -381,16 +381,16 @@ class Server { // - Check if we have a bypass function defined // - In case the bypass function is defined we'll retrieve the // bypassUrl from it otherwise bypassUrl would be null - const isByPassFuncDefined = typeof proxyConfig.bypass === 'function'; + const isByPassFuncDefined = typeof proxyConfig.bypass === "function"; const bypassUrl = isByPassFuncDefined ? await proxyConfig.bypass(req, res, proxyConfig) : null; - if (typeof bypassUrl === 'boolean') { + if (typeof bypassUrl === "boolean") { // skip the proxy req.url = null; next(); - } else if (typeof bypassUrl === 'string') { + } else if (typeof bypassUrl === "string") { // byPass to that url req.url = bypassUrl; next(); @@ -408,19 +408,19 @@ class Server { } setupHistoryApiFallbackFeature() { - const historyApiFallback = require('connect-history-api-fallback'); + const historyApiFallback = require("connect-history-api-fallback"); const options = - typeof this.options.historyApiFallback !== 'boolean' + typeof this.options.historyApiFallback !== "boolean" ? this.options.historyApiFallback : {}; let logger; - if (typeof options.verbose === 'undefined') { + if (typeof options.verbose === "undefined") { logger = this.logger.log.bind( this.logger, - '[connect-history-api-fallback]' + "[connect-history-api-fallback]" ); } @@ -440,14 +440,14 @@ class Server { } setupStaticServeIndexFeature() { - const serveIndex = require('serve-index'); + const serveIndex = require("serve-index"); this.options.static.forEach((staticOption) => { staticOption.publicPath.forEach((publicPath) => { if (staticOption.serveIndex) { this.app.use(publicPath, (req, res, next) => { // serve-index doesn't fallthrough non-get/head request to next middleware - if (req.method !== 'GET' && req.method !== 'HEAD') { + if (req.method !== "GET" && req.method !== "HEAD") { return next(); } @@ -478,11 +478,11 @@ class Server { if (this.options.watchFiles) { const { watchFiles } = this.options; - if (typeof watchFiles === 'string') { + if (typeof watchFiles === "string") { this.watchFiles(watchFiles, {}); } else if (Array.isArray(watchFiles)) { watchFiles.forEach((file) => { - if (typeof file === 'string') { + if (typeof file === "string") { this.watchFiles(file, {}); } else { this.watchFiles(file.paths, file.options || {}); @@ -504,11 +504,11 @@ class Server { } setupHeadersFeature() { - this.app.all('*', this.setContentHeaders.bind(this)); + this.app.all("*", this.setContentHeaders.bind(this)); } setupMagicHtmlFeature() { - this.app.get('*', this.serveMagicHtml.bind(this)); + this.app.get("*", this.serveMagicHtml.bind(this)); } setupFeatures() { @@ -538,12 +538,12 @@ class Server { this.setupStaticWatchFeature(); }, onBeforeSetupMiddleware: () => { - if (typeof this.options.onBeforeSetupMiddleware === 'function') { + if (typeof this.options.onBeforeSetupMiddleware === "function") { this.setupOnBeforeSetupMiddlewareFeature(); } }, onAfterSetupMiddleware: () => { - if (typeof this.options.onAfterSetupMiddleware === 'function') { + if (typeof this.options.onAfterSetupMiddleware === "function") { this.setupOnAfterSetupMiddlewareFeature(); } }, @@ -564,39 +564,39 @@ class Server { // compress is placed last and uses unshift so that it will be the first middleware used if (this.options.compress) { - runnableFeatures.push('compress'); + runnableFeatures.push("compress"); } if (this.options.onBeforeSetupMiddleware) { - runnableFeatures.push('onBeforeSetupMiddleware'); + runnableFeatures.push("onBeforeSetupMiddleware"); } - runnableFeatures.push('headers', 'middleware'); + runnableFeatures.push("headers", "middleware"); if (this.options.proxy) { - runnableFeatures.push('proxy', 'middleware'); + runnableFeatures.push("proxy", "middleware"); } if (this.options.static) { - runnableFeatures.push('static'); + runnableFeatures.push("static"); } if (this.options.historyApiFallback) { - runnableFeatures.push('historyApiFallback', 'middleware'); + runnableFeatures.push("historyApiFallback", "middleware"); if (this.options.static) { - runnableFeatures.push('static'); + runnableFeatures.push("static"); } } if (this.options.static) { - runnableFeatures.push('staticServeIndex', 'staticWatch'); + runnableFeatures.push("staticServeIndex", "staticWatch"); } - runnableFeatures.push('magicHtml'); + runnableFeatures.push("magicHtml"); if (this.options.onAfterSetupMiddleware) { - runnableFeatures.push('onAfterSetupMiddleware'); + runnableFeatures.push("onAfterSetupMiddleware"); } runnableFeatures.forEach((feature) => { @@ -605,17 +605,17 @@ class Server { } createServer() { - const https = require('https'); - const http = require('http'); + const https = require("https"); + const http = require("http"); if (this.options.https) { if (this.options.http2) { // TODO: we need to replace spdy with http2 which is an internal module - this.server = require('spdy').createServer( + this.server = require("spdy").createServer( { ...this.options.https, spdy: { - protocols: ['h2', 'http/1.1'], + protocols: ["h2", "http/1.1"], }, }, this.app @@ -627,7 +627,7 @@ class Server { this.server = http.createServer(this.app); } - this.server.on('error', (error) => { + this.server.on("error", (error) => { throw error; }); } @@ -637,12 +637,12 @@ class Server { let implementationFound = true; switch (typeof this.options.webSocketServer.type) { - case 'string': + case "string": // Could be 'sockjs', in the future 'ws', or a path that should be required - if (this.options.webSocketServer.type === 'sockjs') { - implementation = require('./servers/SockJSServer'); - } else if (this.options.webSocketServer.type === 'ws') { - implementation = require('./servers/WebsocketServer'); + if (this.options.webSocketServer.type === "sockjs") { + implementation = require("./servers/SockJSServer"); + } else if (this.options.webSocketServer.type === "ws") { + implementation = require("./servers/WebsocketServer"); } else { try { // eslint-disable-next-line import/no-dynamic-require @@ -652,7 +652,7 @@ class Server { } } break; - case 'function': + case "function": implementation = this.options.webSocketServer.type; break; default: @@ -662,8 +662,8 @@ class Server { if (!implementationFound) { throw new Error( "webSocketServer (webSocketServer.type) must be a string denoting a default implementation (e.g. 'ws', 'sockjs'), a full path to " + - 'a JS file which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer.js) ' + - 'via require.resolve(...), or the class itself which extends BaseServer' + "a JS file which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer.js) " + + "via require.resolve(...), or the class itself which extends BaseServer" ); } @@ -672,12 +672,12 @@ class Server { createWebSocketServer() { this.webSocketServer = new (this.getWebSocketServerImplementation())(this); - this.webSocketServer.implementation.on('connection', (client, request) => { + this.webSocketServer.implementation.on("connection", (client, request) => { const headers = // eslint-disable-next-line no-nested-ternary - typeof request !== 'undefined' + typeof request !== "undefined" ? request.headers - : typeof client.headers !== 'undefined' + : typeof client.headers !== "undefined" ? client.headers : // eslint-disable-next-line no-undefined undefined; @@ -693,27 +693,27 @@ class Server { !this.checkHostHeader(headers) || !this.checkOriginHeader(headers) ) { - this.sendMessage([client], 'error', 'Invalid Host/Origin header'); + this.sendMessage([client], "error", "Invalid Host/Origin header"); client.terminate(); return; } - if (this.options.hot === true || this.options.hot === 'only') { - this.sendMessage([client], 'hot'); + if (this.options.hot === true || this.options.hot === "only") { + this.sendMessage([client], "hot"); } if (this.options.liveReload) { - this.sendMessage([client], 'liveReload'); + this.sendMessage([client], "liveReload"); } if (this.options.client && this.options.client.progress) { - this.sendMessage([client], 'progress', this.options.client.progress); + this.sendMessage([client], "progress", this.options.client.progress); } if (this.options.client && this.options.client.overlay) { - this.sendMessage([client], 'overlay', this.options.client.overlay); + this.sendMessage([client], "overlay", this.options.client.overlay); } if (!this.stats) { @@ -725,14 +725,14 @@ class Server { } openBrowser(defaultOpenTarget) { - const isAbsoluteUrl = require('is-absolute-url'); - const open = require('open'); + const isAbsoluteUrl = require("is-absolute-url"); + const open = require("open"); Promise.all( this.options.open.map((item) => { let openTarget; - if (item.target === '') { + if (item.target === "") { openTarget = defaultOpenTarget; } else { openTarget = isAbsoluteUrl(item.target) @@ -748,11 +748,11 @@ class Server { ? ` in "${item.options.app.name}" app${ item.options.app.arguments ? ` with "${item.options.app.arguments.join( - ' ' + " " )}" arguments` - : '' + : "" }` - : '' + : "" }. If you are running in a headless environment, please do not use the "open" option or related flags like "--open", "--open-target", and "--open-app".` ); }); @@ -761,18 +761,18 @@ class Server { } runBonjour() { - const bonjour = require('bonjour')(); - const os = require('os'); + const bonjour = require("bonjour")(); + const os = require("os"); bonjour.publish({ name: `Webpack Dev Server ${os.hostname()}:${this.options.port}`, port: this.options.port, - type: this.options.https ? 'https' : 'http', - subtypes: ['webpack'], + type: this.options.https ? "https" : "http", + subtypes: ["webpack"], ...this.options.bonjour, }); - process.on('exit', () => { + process.on("exit", () => { bonjour.unpublishAll(() => { bonjour.destroy(); }); @@ -785,7 +785,7 @@ class Server { let colorsEnabled = false; - if (typeof statsOption === 'object' && statsOption.colors) { + if (typeof statsOption === "object" && statsOption.colors) { colorsEnabled = statsOption.colors; } @@ -816,10 +816,10 @@ class Server { if (this.options.ipc) { this.logger.info(`Project is running at: "${this.server.address()}"`); } else { - const protocol = this.options.https ? 'https' : 'http'; + const protocol = this.options.https ? "https" : "http"; const { address, port } = this.server.address(); const prettyPrintURL = (newHostname) => - url.format({ protocol, hostname: newHostname, port, pathname: '/' }); + url.format({ protocol, hostname: newHostname, port, pathname: "/" }); let server; let localhost; @@ -829,8 +829,8 @@ class Server { let networkUrlIPv6; if (this.options.host) { - if (this.options.host === 'localhost') { - localhost = prettyPrintURL('localhost'); + if (this.options.host === "localhost") { + localhost = prettyPrintURL("localhost"); } else { let isIP; @@ -848,8 +848,8 @@ class Server { const parsedIP = ipaddr.parse(address); - if (parsedIP.range() === 'unspecified') { - localhost = prettyPrintURL('localhost'); + if (parsedIP.range() === "unspecified") { + localhost = prettyPrintURL("localhost"); const networkIPv4 = internalIp.v4.sync(); @@ -862,24 +862,24 @@ class Server { if (networkIPv6) { networkUrlIPv6 = prettyPrintURL(networkIPv6); } - } else if (parsedIP.range() === 'loopback') { - if (parsedIP.kind() === 'ipv4') { + } else if (parsedIP.range() === "loopback") { + if (parsedIP.kind() === "ipv4") { loopbackIPv4 = prettyPrintURL(parsedIP.toString()); - } else if (parsedIP.kind() === 'ipv6') { + } else if (parsedIP.kind() === "ipv6") { loopbackIPv6 = prettyPrintURL(parsedIP.toString()); } } else { networkUrlIPv4 = - parsedIP.kind() === 'ipv6' && parsedIP.isIPv4MappedAddress() + parsedIP.kind() === "ipv6" && parsedIP.isIPv4MappedAddress() ? prettyPrintURL(parsedIP.toIPv4Address().toString()) : prettyPrintURL(address); - if (parsedIP.kind() === 'ipv6') { + if (parsedIP.kind() === "ipv6") { networkUrlIPv6 = prettyPrintURL(address); } } - this.logger.info('Project is running at:'); + this.logger.info("Project is running at:"); if (server) { this.logger.info(`Server: ${colors.info(useColor, server)}`); @@ -891,7 +891,7 @@ class Server { .concat(loopbackIPv4 ? [colors.info(useColor, loopbackIPv4)] : []) .concat(loopbackIPv6 ? [colors.info(useColor, loopbackIPv6)] : []); - this.logger.info(`Loopback: ${loopbacks.join(', ')}`); + this.logger.info(`Loopback: ${loopbacks.join(", ")}`); } if (networkUrlIPv4) { @@ -907,7 +907,7 @@ class Server { } if (this.options.open.length > 0) { - const openTarget = prettyPrintURL(this.options.host || 'localhost'); + const openTarget = prettyPrintURL(this.options.host || "localhost"); this.openBrowser(openTarget); } @@ -919,7 +919,7 @@ class Server { useColor, this.options.static .map((staticOption) => staticOption.directory) - .join(', ') + .join(", ") )}' directory` ); } @@ -928,14 +928,14 @@ class Server { this.logger.info( `404s will fallback to '${colors.info( useColor, - this.options.historyApiFallback.index || '/index.html' + this.options.historyApiFallback.index || "/index.html" )}'` ); } if (this.options.bonjour) { const bonjourProtocol = - this.options.bonjour.type || this.options.https ? 'https' : 'http'; + this.options.bonjour.type || this.options.https ? "https" : "http"; this.logger.info( `Broadcasting "${bonjourProtocol}" with subtype of "webpack" via ZeroConf DNS (Bonjour)` @@ -944,13 +944,13 @@ class Server { } listen(port, hostname, fn) { - if (typeof port === 'function') { + if (typeof port === "function") { fn = port; } if ( - typeof port !== 'undefined' && - typeof this.options.port !== 'undefined' && + typeof port !== "undefined" && + typeof this.options.port !== "undefined" && port !== this.options.port ) { this.options.port = port; @@ -965,8 +965,8 @@ class Server { } if ( - typeof hostname !== 'undefined' && - typeof this.options.host !== 'undefined' && + typeof hostname !== "undefined" && + typeof this.options.host !== "undefined" && hostname !== this.options.host ) { this.options.host = hostname; @@ -987,14 +987,14 @@ class Server { return new Promise((resolve, reject) => { const socket = new net.Socket(); - socket.on('error', (error) => { - if (error.code === 'ECONNREFUSED') { + socket.on("error", (error) => { + if (error.code === "ECONNREFUSED") { fs.unlinkSync(this.options.ipc); resolve(this.options.ipc); return; - } else if (error.code === 'ENOENT') { + } else if (error.code === "ENOENT") { resolve(this.options.ipc); return; @@ -1053,7 +1053,7 @@ class Server { fn.call(this.server, error); } - if (typeof this.options.onListening === 'function') { + if (typeof this.options.onListening === "function") { this.options.onListening(this); } }); @@ -1090,13 +1090,13 @@ class Server { // eslint-disable-next-line class-methods-use-this getStatsOption(configArray) { const isEmptyObject = (val) => - typeof val === 'object' && Object.keys(val).length === 0; + typeof val === "object" && Object.keys(val).length === 0; // in webpack@4 stats will not be defined if not provided, // but in webpack@5 it will be an empty object const statsConfig = configArray.find( (configuration) => - typeof configuration === 'object' && + typeof configuration === "object" && configuration.stats && !isEmptyObject(configuration.stats) ); @@ -1110,7 +1110,7 @@ class Server { const configArray = getCompilerConfigArray(this.compiler); const statsOption = this.getStatsOption(configArray); - if (typeof statsOption === 'object' && statsOption.warningsFilter) { + if (typeof statsOption === "object" && statsOption.warningsFilter) { stats.warningsFilter = statsOption.warningsFilter; } @@ -1125,7 +1125,7 @@ class Server { setContentHeaders(req, res, next) { let { headers } = this.options; if (headers) { - if (typeof headers === 'function') { + if (typeof headers === "function") { headers = headers(req, res, this.middleware.context); } // eslint-disable-next-line guard-for-in @@ -1138,22 +1138,22 @@ class Server { } checkHostHeader(headers) { - return this.checkHeader(headers, 'host'); + return this.checkHeader(headers, "host"); } checkOriginHeader(headers) { - return this.checkHeader(headers, 'origin'); + return this.checkHeader(headers, "origin"); } checkHeader(headers, headerToCheck) { // allow user to opt out of this security check, at their own risk // by explicitly enabling allowedHosts - if (this.options.allowedHosts === 'all') { + if (this.options.allowedHosts === "all") { return true; } if (!headerToCheck) { - headerToCheck = 'host'; + headerToCheck = "host"; } // get the Host header and extract hostname @@ -1183,7 +1183,7 @@ class Server { const isValidHostname = ipaddr.IPv4.isValid(hostname) || ipaddr.IPv6.isValid(hostname) || - hostname === 'localhost' || + hostname === "localhost" || hostname === this.options.host; if (isValidHostname) { @@ -1204,7 +1204,7 @@ class Server { // support "." as a subdomain wildcard // e.g. ".example.com" will allow "example.com", "www.example.com", "subdomain.example.com", etc - if (allowedHost[0] === '.') { + if (allowedHost[0] === ".") { // "example.com" (hostname === allowedHost.substring(1)) // "*.example.com" (hostname.endsWith(allowedHost)) if ( @@ -1220,7 +1220,7 @@ class Server { // Also allow if `client.webSocketURL.hostname` provided if ( this.options.client && - typeof this.options.client.webSocketURL !== 'undefined' + typeof this.options.client.webSocketURL !== "undefined" ) { return this.options.client.webSocketURL.hostname === hostname; } @@ -1255,7 +1255,7 @@ class Server { } // Serve a page that executes the javascript - const queries = req._parsedUrl.search || ''; + const queries = req._parsedUrl.search || ""; const responsePage = ``; res.send(responsePage); @@ -1276,23 +1276,23 @@ class Server { stats.assets.every((asset) => !asset.emitted); if (shouldEmit) { - this.sendMessage(clients, 'still-ok'); + this.sendMessage(clients, "still-ok"); return; } - this.sendMessage(clients, 'hash', stats.hash); + this.sendMessage(clients, "hash", stats.hash); if (stats.errors.length > 0 || stats.warnings.length > 0) { if (stats.warnings.length > 0) { - this.sendMessage(clients, 'warnings', stats.warnings); + this.sendMessage(clients, "warnings", stats.warnings); } if (stats.errors.length > 0) { - this.sendMessage(clients, 'errors', stats.errors); + this.sendMessage(clients, "errors", stats.errors); } } else { - this.sendMessage(clients, 'ok'); + this.sendMessage(clients, "ok"); } } @@ -1302,14 +1302,14 @@ class Server { // this isn't an elegant solution, but we'll improve it in the future // eslint-disable-next-line no-undefined const usePolling = - typeof watchOptions.usePolling !== 'undefined' + typeof watchOptions.usePolling !== "undefined" ? watchOptions.usePolling : Boolean(watchOptions.poll); const interval = // eslint-disable-next-line no-nested-ternary - typeof watchOptions.interval !== 'undefined' + typeof watchOptions.interval !== "undefined" ? watchOptions.interval - : typeof watchOptions.poll === 'number' + : typeof watchOptions.poll === "number" ? watchOptions.poll : // eslint-disable-next-line no-undefined undefined; @@ -1326,17 +1326,17 @@ class Server { interval, }; - const chokidar = require('chokidar'); + const chokidar = require("chokidar"); const watcher = chokidar.watch(watchPath, finalWatchOptions); // disabling refreshing on changing the content if (this.options.liveReload) { - watcher.on('change', (item) => { + watcher.on("change", (item) => { if (this.webSocketServer) { this.sendMessage( this.webSocketServer.clients, - 'static-changed', + "static-changed", item ); } @@ -1367,7 +1367,7 @@ const mergeExports = (obj, exports) => { enumerable: true, get: fn, }); - } else if (typeof descriptor.value === 'object') { + } else if (typeof descriptor.value === "object") { Object.defineProperty(obj, name, { configurable: false, enumerable: true, @@ -1376,7 +1376,7 @@ const mergeExports = (obj, exports) => { }); } else { throw new Error( - 'Exposed values must be either a getter or an nested object' + "Exposed values must be either a getter or an nested object" ); } } @@ -1391,10 +1391,10 @@ module.exports = mergeExports(Server, { // TODO compatibility with webpack v4, remove it after drop cli: { get getArguments() { - return () => require('../bin/cli-flags'); + return () => require("../bin/cli-flags"); }, get processArguments() { - return require('../bin/process-arguments'); + return require("../bin/process-arguments"); }, }, }); diff --git a/lib/servers/BaseServer.js b/lib/servers/BaseServer.js index 43a115c779..d4812954bb 100644 --- a/lib/servers/BaseServer.js +++ b/lib/servers/BaseServer.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; // base class that users should extend if they are making their own // server implementation diff --git a/lib/servers/SockJSServer.js b/lib/servers/SockJSServer.js index 457fbecd42..18a2f2df51 100644 --- a/lib/servers/SockJSServer.js +++ b/lib/servers/SockJSServer.js @@ -1,16 +1,16 @@ -'use strict'; +"use strict"; /* eslint-disable class-methods-use-this */ -const sockjs = require('sockjs'); -const BaseServer = require('./BaseServer'); +const sockjs = require("sockjs"); +const BaseServer = require("./BaseServer"); // Workaround for sockjs@~0.3.19 // sockjs will remove Origin header, however Origin header is required for checking host. // See https://github.com/webpack/webpack-dev-server/issues/1604 for more information { - const SockjsSession = require('sockjs/lib/transport').Session; + const SockjsSession = require("sockjs/lib/transport").Session; const decorateConnection = SockjsSession.prototype.decorateConnection; // eslint-disable-next-line func-names @@ -21,8 +21,8 @@ const BaseServer = require('./BaseServer'); if ( connection.headers && - !('origin' in connection.headers) && - 'origin' in req.headers + !("origin" in connection.headers) && + "origin" in req.headers ) { connection.headers.origin = req.headers.origin; } @@ -36,12 +36,12 @@ module.exports = class SockJSServer extends BaseServer { this.implementation = sockjs.createServer({ // Use provided up-to-date sockjs-client - sockjs_url: '/__webpack_dev_server__/sockjs.bundle.js', + sockjs_url: "/__webpack_dev_server__/sockjs.bundle.js", // Default logger is very annoy. Limit useless logs. log: (severity, line) => { - if (severity === 'error') { + if (severity === "error") { this.server.logger.error(line); - } else if (severity === 'info') { + } else if (severity === "info") { this.server.logger.log(line); } else { this.server.logger.debug(line); @@ -50,7 +50,7 @@ module.exports = class SockJSServer extends BaseServer { }); const getPrefix = (options) => { - if (typeof options.prefix !== 'undefined') { + if (typeof options.prefix !== "undefined") { return options.prefix; } @@ -62,13 +62,13 @@ module.exports = class SockJSServer extends BaseServer { prefix: getPrefix(this.server.options.webSocketServer.options), }); - this.implementation.on('connection', (client) => { + this.implementation.on("connection", (client) => { // Implement the the same API as for `ws` client.send = client.write; this.clients.add(client); - client.on('close', () => { + client.on("close", () => { this.clients.delete(client); }); }); diff --git a/lib/servers/WebsocketServer.js b/lib/servers/WebsocketServer.js index 3e24a43b34..078238c931 100644 --- a/lib/servers/WebsocketServer.js +++ b/lib/servers/WebsocketServer.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; /* eslint-disable class-methods-use-this */ -const WebSocket = require('ws'); -const BaseServer = require('./BaseServer'); +const WebSocket = require("ws"); +const BaseServer = require("./BaseServer"); module.exports = class WebsocketServer extends BaseServer { static heartbeatInterval = 1000; @@ -17,8 +17,8 @@ module.exports = class WebsocketServer extends BaseServer { clientTracking: false, }; const isNoServerMode = - typeof options.port === 'undefined' && - typeof options.server === 'undefined'; + typeof options.port === "undefined" && + typeof options.server === "undefined"; if (isNoServerMode) { options.noServer = true; @@ -26,17 +26,17 @@ module.exports = class WebsocketServer extends BaseServer { this.implementation = new WebSocket.Server(options); - this.server.server.on('upgrade', (req, sock, head) => { + this.server.server.on("upgrade", (req, sock, head) => { if (!this.implementation.shouldHandle(req)) { return; } this.implementation.handleUpgrade(req, sock, head, (connection) => { - this.implementation.emit('connection', connection, req); + this.implementation.emit("connection", connection, req); }); }); - this.implementation.on('error', (err) => { + this.implementation.on("error", (err) => { this.server.logger.error(err.message); }); @@ -53,21 +53,21 @@ module.exports = class WebsocketServer extends BaseServer { }); }, WebsocketServer.heartbeatInterval); - this.implementation.on('connection', (client) => { + this.implementation.on("connection", (client) => { this.clients.add(client); client.isAlive = true; - client.on('pong', () => { + client.on("pong", () => { client.isAlive = true; }); - client.on('close', () => { + client.on("close", () => { this.clients.delete(client); }); }); - this.implementation.on('close', () => { + this.implementation.on("close", () => { clearInterval(interval); this.clients.clear(); diff --git a/lib/utils/DevServerPlugin.js b/lib/utils/DevServerPlugin.js index 35ffdfe96c..146dcb98fd 100644 --- a/lib/utils/DevServerPlugin.js +++ b/lib/utils/DevServerPlugin.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; /** * An Entry, it can be of type string or string[] or Object @@ -19,34 +19,34 @@ class DevServerPlugin { const isKnownWebSocketServerImplementation = this.options.webSocketServer && - typeof this.options.webSocketServer.type === 'string' && - (this.options.webSocketServer.type === 'ws' || - this.options.webSocketServer.type === 'sockjs'); + typeof this.options.webSocketServer.type === "string" && + (this.options.webSocketServer.type === "ws" || + this.options.webSocketServer.type === "sockjs"); let clientTransport; if (this.options.client) { - if (typeof this.options.client.webSocketTransport !== 'undefined') { + if (typeof this.options.client.webSocketTransport !== "undefined") { clientTransport = this.options.client.webSocketTransport; } else if (isKnownWebSocketServerImplementation) { clientTransport = this.options.webSocketServer.type; } else { - clientTransport = 'ws'; + clientTransport = "ws"; } } else { - clientTransport = 'ws'; + clientTransport = "ws"; } switch (typeof clientTransport) { - case 'string': + case "string": // could be 'sockjs', 'ws', or a path that should be required - if (clientTransport === 'sockjs') { + if (clientTransport === "sockjs") { ClientImplementation = require.resolve( - '../../client/clients/SockJSClient' + "../../client/clients/SockJSClient" ); - } else if (clientTransport === 'ws') { + } else if (clientTransport === "ws") { ClientImplementation = require.resolve( - '../../client/clients/WebsocketClient' + "../../client/clients/WebsocketClient" ); } else { try { @@ -65,8 +65,8 @@ class DevServerPlugin { throw new Error( `${ !isKnownWebSocketServerImplementation - ? 'When you use custom web socket implementation you must explicitly specify client.webSocketTransport. ' - : '' + ? "When you use custom web socket implementation you must explicitly specify client.webSocketTransport. " + : "" }client.webSocketTransport must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to a JS file via require.resolve(...) which exports a class ` ); } @@ -85,20 +85,20 @@ class DevServerPlugin { let protocol; // We are proxying dev server and need to specify custom `hostname` - if (typeof options.client.webSocketURL.protocol !== 'undefined') { + if (typeof options.client.webSocketURL.protocol !== "undefined") { protocol = options.client.webSocketURL.protocol; } else { - protocol = options.https ? 'wss:' : 'ws:'; + protocol = options.https ? "wss:" : "ws:"; } - searchParams.set('protocol', protocol); + searchParams.set("protocol", protocol); - if (typeof options.client.webSocketURL.username !== 'undefined') { - searchParams.set('username', options.client.webSocketURL.username); + if (typeof options.client.webSocketURL.username !== "undefined") { + searchParams.set("username", options.client.webSocketURL.username); } - if (typeof options.client.webSocketURL.password !== 'undefined') { - searchParams.set('password', options.client.webSocketURL.password); + if (typeof options.client.webSocketURL.password !== "undefined") { + searchParams.set("password", options.client.webSocketURL.password); } /** @type {string} */ @@ -106,80 +106,80 @@ class DevServerPlugin { // SockJS is not supported server mode, so `hostname` and `port` can't specified, let's ignore them // TODO show warning about this - const isSockJSType = options.webSocketServer.type === 'sockjs'; + const isSockJSType = options.webSocketServer.type === "sockjs"; // We are proxying dev server and need to specify custom `hostname` - if (typeof options.client.webSocketURL.hostname !== 'undefined') { + if (typeof options.client.webSocketURL.hostname !== "undefined") { hostname = options.client.webSocketURL.hostname; } // Web socket server works on custom `hostname`, only for `ws` because `sock-js` is not support custom `hostname` else if ( - typeof options.webSocketServer.options.host !== 'undefined' && + typeof options.webSocketServer.options.host !== "undefined" && !isSockJSType ) { hostname = options.webSocketServer.options.host; } // The `host` option is specified - else if (typeof this.options.host !== 'undefined') { + else if (typeof this.options.host !== "undefined") { hostname = this.options.host; } // The `port` option is not specified else { - hostname = '0.0.0.0'; + hostname = "0.0.0.0"; } - searchParams.set('hostname', hostname); + searchParams.set("hostname", hostname); /** @type {number | string} */ let port; // We are proxying dev server and need to specify custom `port` - if (typeof options.client.webSocketURL.port !== 'undefined') { + if (typeof options.client.webSocketURL.port !== "undefined") { port = options.client.webSocketURL.port; } // Web socket server works on custom `port`, only for `ws` because `sock-js` is not support custom `port` else if ( - typeof options.webSocketServer.options.port !== 'undefined' && + typeof options.webSocketServer.options.port !== "undefined" && !isSockJSType ) { port = options.webSocketServer.options.port; } // The `port` option is specified - else if (typeof options.port === 'number') { + else if (typeof options.port === "number") { port = options.port; } // The `port` option is specified using `string` - else if (typeof options.port === 'string' && options.port !== 'auto') { + else if (typeof options.port === "string" && options.port !== "auto") { port = Number(options.port); } // The `port` option is not specified or set to `auto` else { - port = '0'; + port = "0"; } - searchParams.set('port', String(port)); + searchParams.set("port", String(port)); /** @type {string} */ - let pathname = ''; + let pathname = ""; // We are proxying dev server and need to specify custom `pathname` - if (typeof options.client.webSocketURL.pathname !== 'undefined') { + if (typeof options.client.webSocketURL.pathname !== "undefined") { pathname = options.client.webSocketURL.pathname; } // Web socket server works on custom `path` else if ( - typeof options.webSocketServer.options.prefix !== 'undefined' || - typeof options.webSocketServer.options.path !== 'undefined' + typeof options.webSocketServer.options.prefix !== "undefined" || + typeof options.webSocketServer.options.path !== "undefined" ) { pathname = options.webSocketServer.options.prefix || options.webSocketServer.options.path; } - searchParams.set('pathname', pathname); + searchParams.set("pathname", pathname); - if (typeof options.client.logging !== 'undefined') { - searchParams.set('logging', options.client.logging); + if (typeof options.client.logging !== "undefined") { + searchParams.set("logging", options.client.logging); } return searchParams.toString(); @@ -192,9 +192,9 @@ class DevServerPlugin { /** @type {string} */ const webSocketURL = this.options.webSocketServer ? this.getWebSocketURL() - : ''; + : ""; - return `${require.resolve('../../client/index.js')}?${webSocketURL}`; + return `${require.resolve("../../client/index.js")}?${webSocketURL}`; } getHotEntry() { @@ -203,10 +203,10 @@ class DevServerPlugin { /** @type {(string[] | string)} */ let hotEntry; - if (options.hot === 'only') { - hotEntry = require.resolve('webpack/hot/only-dev-server'); + if (options.hot === "only") { + hotEntry = require.resolve("webpack/hot/only-dev-server"); } else if (options.hot) { - hotEntry = require.resolve('webpack/hot/dev-server'); + hotEntry = require.resolve("webpack/hot/dev-server"); } return hotEntry; @@ -221,11 +221,11 @@ class DevServerPlugin { return compilerOptions.externalsPresets ? compilerOptions.externalsPresets.web : [ - 'web', - 'webworker', - 'electron-preload', - 'electron-renderer', - 'node-webkit', + "web", + "webworker", + "electron-preload", + "electron-renderer", + "node-webkit", // eslint-disable-next-line no-undefined undefined, null, @@ -261,10 +261,10 @@ class DevServerPlugin { additionalEntries.push(hotEntry); } - const webpack = compiler.webpack || require('webpack'); + const webpack = compiler.webpack || require("webpack"); // use a hook to add entries if available - if (typeof webpack.EntryPlugin !== 'undefined') { + if (typeof webpack.EntryPlugin !== "undefined") { for (const additionalEntry of additionalEntries) { new webpack.EntryPlugin(compiler.context, additionalEntry, { // eslint-disable-next-line no-undefined @@ -279,7 +279,7 @@ class DevServerPlugin { * @returns {Entry} */ const prependEntry = (originalEntry, newAdditionalEntries) => { - if (typeof originalEntry === 'function') { + if (typeof originalEntry === "function") { return () => Promise.resolve(originalEntry()).then((entry) => prependEntry(entry, newAdditionalEntries) @@ -287,7 +287,7 @@ class DevServerPlugin { } if ( - typeof originalEntry === 'object' && + typeof originalEntry === "object" && !Array.isArray(originalEntry) ) { /** @type {Object} */ @@ -318,7 +318,7 @@ class DevServerPlugin { }; compiler.options.entry = prependEntry( - compiler.options.entry || './src', + compiler.options.entry || "./src", additionalEntries ); compiler.hooks.entryOption.call( diff --git a/lib/utils/getCompilerConfigArray.js b/lib/utils/getCompilerConfigArray.js index 4cd48fdd50..93d7612eb6 100644 --- a/lib/utils/getCompilerConfigArray.js +++ b/lib/utils/getCompilerConfigArray.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; function getCompilerConfigArray(compiler) { const compilers = compiler.compilers ? compiler.compilers : [compiler]; diff --git a/lib/utils/normalizeOptions.js b/lib/utils/normalizeOptions.js index 1861e50a23..f8e125a236 100644 --- a/lib/utils/normalizeOptions.js +++ b/lib/utils/normalizeOptions.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; -const os = require('os'); -const path = require('path'); -const del = require('del'); -const fs = require('graceful-fs'); -const getCompilerConfigArray = require('./getCompilerConfigArray'); +const os = require("os"); +const path = require("path"); +const del = require("del"); +const fs = require("graceful-fs"); +const getCompilerConfigArray = require("./getCompilerConfigArray"); function normalizeOptions(compiler, options, logger, cacheDir) { // TODO: improve this to not use .find for compiler watchOptions @@ -17,59 +17,59 @@ function normalizeOptions(compiler, options, logger, cacheDir) { : {}; const defaultOptionsForStatic = { - directory: path.join(process.cwd(), 'public'), + directory: path.join(process.cwd(), "public"), staticOptions: {}, - publicPath: ['/'], + publicPath: ["/"], serveIndex: { icons: true }, // Respect options from compiler watchOptions watch: watchOptions, }; - if (typeof options.allowedHosts === 'undefined') { + if (typeof options.allowedHosts === "undefined") { // allowedHosts allows some default hosts picked from // `options.host` or `webSocketURL.hostname` and `localhost` - options.allowedHosts = 'auto'; + options.allowedHosts = "auto"; } if ( - typeof options.allowedHosts === 'string' && - options.allowedHosts !== 'auto' && - options.allowedHosts !== 'all' + typeof options.allowedHosts === "string" && + options.allowedHosts !== "auto" && + options.allowedHosts !== "all" ) { // we store allowedHosts as array when supplied as string options.allowedHosts = [options.allowedHosts]; } if ( - typeof options.client === 'undefined' || - (typeof options.client === 'object' && options.client !== null) + typeof options.client === "undefined" || + (typeof options.client === "object" && options.client !== null) ) { if (!options.client) { options.client = {}; } - if (typeof options.client.webSocketURL === 'undefined') { + if (typeof options.client.webSocketURL === "undefined") { options.client.webSocketURL = {}; - } else if (typeof options.client.webSocketURL === 'string') { + } else if (typeof options.client.webSocketURL === "string") { const parsedURL = new URL(options.client.webSocketURL); options.client.webSocketURL = { protocol: parsedURL.protocol, hostname: parsedURL.hostname, - port: parsedURL.port.length > 0 ? Number(parsedURL.port) : '', + port: parsedURL.port.length > 0 ? Number(parsedURL.port) : "", pathname: parsedURL.pathname, username: parsedURL.username, password: parsedURL.password, }; - } else if (typeof options.client.webSocketURL.port === 'string') { + } else if (typeof options.client.webSocketURL.port === "string") { options.client.webSocketURL.port = Number( options.client.webSocketURL.port ); } // Enable client overlay by default - if (typeof options.client.overlay === 'undefined') { + if (typeof options.client.overlay === "undefined") { options.client.overlay = true; - } else if (typeof options.client.overlay !== 'boolean') { + } else if (typeof options.client.overlay !== "boolean") { options.client.overlay = { errors: true, warnings: true, @@ -78,14 +78,14 @@ function normalizeOptions(compiler, options, logger, cacheDir) { } } - if (typeof options.compress === 'undefined') { + if (typeof options.compress === "undefined") { options.compress = true; } options.devMiddleware = options.devMiddleware || {}; options.hot = - typeof options.hot === 'boolean' || options.hot === 'only' + typeof options.hot === "boolean" || options.hot === "only" ? options.hot : true; @@ -98,7 +98,7 @@ function normalizeOptions(compiler, options, logger, cacheDir) { // https option if (options.https) { - for (const property of ['cacert', 'pfx', 'key', 'cert']) { + for (const property of ["cacert", "pfx", "key", "cert"]) { const value = options.https[property]; const isBuffer = value instanceof Buffer; @@ -122,7 +122,7 @@ function normalizeOptions(compiler, options, logger, cacheDir) { if (!options.https.key || !options.https.cert) { const certificateDir = cacheDir || os.tmpdir(); - const certificatePath = path.join(certificateDir, 'server.pem'); + const certificatePath = path.join(certificateDir, "server.pem"); let certificateExists = fs.existsSync(certificatePath); if (certificateExists) { @@ -133,7 +133,7 @@ function normalizeOptions(compiler, options, logger, cacheDir) { // cert is more than 30 days old, kill it with fire if ((now - certificateStat.ctime) / certificateTtl > 30) { - logger.info('SSL Certificate is more than 30 days old. Removing.'); + logger.info("SSL Certificate is more than 30 days old. Removing."); del.sync([certificatePath], { force: true }); @@ -142,12 +142,12 @@ function normalizeOptions(compiler, options, logger, cacheDir) { } if (!certificateExists) { - logger.info('Generating SSL Certificate'); + logger.info("Generating SSL Certificate"); - const selfsigned = require('selfsigned'); - const attributes = [{ name: 'commonName', value: 'localhost' }]; + const selfsigned = require("selfsigned"); + const attributes = [{ name: "commonName", value: "localhost" }]; const pems = selfsigned.generate(attributes, { - algorithm: 'sha256', + algorithm: "sha256", days: 30, keySize: 2048, extensions: [ @@ -156,7 +156,7 @@ function normalizeOptions(compiler, options, logger, cacheDir) { // cA: true, // }, { - name: 'keyUsage', + name: "keyUsage", keyCertSign: true, digitalSignature: true, nonRepudiation: true, @@ -164,44 +164,44 @@ function normalizeOptions(compiler, options, logger, cacheDir) { dataEncipherment: true, }, { - name: 'extKeyUsage', + name: "extKeyUsage", serverAuth: true, clientAuth: true, codeSigning: true, timeStamping: true, }, { - name: 'subjectAltName', + name: "subjectAltName", altNames: [ { // type 2 is DNS type: 2, - value: 'localhost', + value: "localhost", }, { type: 2, - value: 'localhost.localdomain', + value: "localhost.localdomain", }, { type: 2, - value: 'lvh.me', + value: "lvh.me", }, { type: 2, - value: '*.lvh.me', + value: "*.lvh.me", }, { type: 2, - value: '[::1]', + value: "[::1]", }, { // type 7 is IP type: 7, - ip: '127.0.0.1', + ip: "127.0.0.1", }, { type: 7, - ip: 'fe80::1', + ip: "fe80::1", }, ], }, @@ -210,7 +210,7 @@ function normalizeOptions(compiler, options, logger, cacheDir) { fs.mkdirSync(certificateDir, { recursive: true }); fs.writeFileSync(certificatePath, pems.private + pems.cert, { - encoding: 'utf8', + encoding: "utf8", }); } @@ -221,29 +221,29 @@ function normalizeOptions(compiler, options, logger, cacheDir) { options.https.cert = options.https.cert || fakeCert; } - if (typeof options.ipc === 'boolean') { - const isWindows = process.platform === 'win32'; - const pipePrefix = isWindows ? '\\\\.\\pipe\\' : os.tmpdir(); - const pipeName = 'webpack-dev-server.sock'; + if (typeof options.ipc === "boolean") { + const isWindows = process.platform === "win32"; + const pipePrefix = isWindows ? "\\\\.\\pipe\\" : os.tmpdir(); + const pipeName = "webpack-dev-server.sock"; options.ipc = path.join(pipePrefix, pipeName); } options.liveReload = - typeof options.liveReload !== 'undefined' ? options.liveReload : true; + typeof options.liveReload !== "undefined" ? options.liveReload : true; // https://github.com/webpack/webpack-dev-server/issues/1990 const defaultOpenOptions = { wait: false }; const getOpenItemsFromObject = ({ target, ...rest }) => { const normalizedOptions = { ...defaultOpenOptions, ...rest }; - if (typeof normalizedOptions.app === 'string') { + if (typeof normalizedOptions.app === "string") { normalizedOptions.app = { name: normalizedOptions.app, }; } - const normalizedTarget = typeof target === 'undefined' ? '' : target; + const normalizedTarget = typeof target === "undefined" ? "" : target; if (Array.isArray(normalizedTarget)) { return normalizedTarget.map((singleTarget) => { @@ -254,19 +254,19 @@ function normalizeOptions(compiler, options, logger, cacheDir) { return [{ target: normalizedTarget, options: normalizedOptions }]; }; - if (typeof options.open === 'undefined') { + if (typeof options.open === "undefined") { options.open = []; - } else if (typeof options.open === 'boolean') { + } else if (typeof options.open === "boolean") { options.open = options.open - ? [{ target: '', options: defaultOpenOptions }] + ? [{ target: "", options: defaultOpenOptions }] : []; - } else if (typeof options.open === 'string') { + } else if (typeof options.open === "string") { options.open = [{ target: options.open, options: defaultOpenOptions }]; } else if (Array.isArray(options.open)) { const result = []; options.open.forEach((item) => { - if (typeof item === 'string') { + if (typeof item === "string") { result.push({ target: item, options: defaultOpenOptions }); return; @@ -280,7 +280,7 @@ function normalizeOptions(compiler, options, logger, cacheDir) { options.open = [...getOpenItemsFromObject(options.open)]; } - if (typeof options.port === 'string' && options.port !== 'auto') { + if (typeof options.port === "string" && options.port !== "auto") { options.port = Number(options.port); } @@ -294,19 +294,19 @@ function normalizeOptions(compiler, options, logger, cacheDir) { * 'context': 'target' * } */ - if (typeof options.proxy !== 'undefined') { + if (typeof options.proxy !== "undefined") { if (!Array.isArray(options.proxy)) { - if (Object.prototype.hasOwnProperty.call(options.proxy, 'target')) { + if (Object.prototype.hasOwnProperty.call(options.proxy, "target")) { options.proxy = [options.proxy]; } else { options.proxy = Object.keys(options.proxy).map((context) => { let proxyOptions; // For backwards compatibility reasons. const correctedContext = context - .replace(/^\*$/, '**') - .replace(/\/\*$/, ''); + .replace(/^\*$/, "**") + .replace(/\/\*$/, ""); - if (typeof options.proxy[context] === 'string') { + if (typeof options.proxy[context] === "string") { proxyOptions = { context: correctedContext, target: options.proxy[context], @@ -317,16 +317,16 @@ function normalizeOptions(compiler, options, logger, cacheDir) { } const getLogLevelForProxy = (level) => { - if (level === 'none') { - return 'silent'; + if (level === "none") { + return "silent"; } - if (level === 'log') { - return 'info'; + if (level === "log") { + return "info"; } - if (level === 'verbose') { - return 'debug'; + if (level === "verbose") { + return "debug"; } return level; @@ -336,13 +336,13 @@ function normalizeOptions(compiler, options, logger, cacheDir) { const configWithDevServer = configs.find((config) => config.devServer) || configs[0]; - if (typeof proxyOptions.logLevel === 'undefined') { + if (typeof proxyOptions.logLevel === "undefined") { proxyOptions.logLevel = getLogLevelForProxy( configWithDevServer.infrastructureLogging.level ); } - if (typeof proxyOptions.logProvider === 'undefined') { + if (typeof proxyOptions.logProvider === "undefined") { proxyOptions.logProvider = () => logger; } @@ -352,21 +352,21 @@ function normalizeOptions(compiler, options, logger, cacheDir) { } } - if (typeof options.setupExitSignals === 'undefined') { + if (typeof options.setupExitSignals === "undefined") { options.setupExitSignals = true; } - if (typeof options.static === 'undefined') { + if (typeof options.static === "undefined") { options.static = [defaultOptionsForStatic]; - } else if (typeof options.static === 'boolean') { + } else if (typeof options.static === "boolean") { options.static = options.static ? [defaultOptionsForStatic] : false; - } else if (typeof options.static === 'string') { + } else if (typeof options.static === "string") { options.static = [ { ...defaultOptionsForStatic, directory: options.static }, ]; } else if (Array.isArray(options.static)) { options.static = options.static.map((item) => { - if (typeof item === 'string') { + if (typeof item === "string") { return { ...defaultOptionsForStatic, directory: item }; } @@ -377,15 +377,15 @@ function normalizeOptions(compiler, options, logger, cacheDir) { } if (options.static) { - const isAbsoluteUrl = require('is-absolute-url'); + const isAbsoluteUrl = require("is-absolute-url"); options.static.forEach((staticOption) => { if (isAbsoluteUrl(staticOption.directory)) { - throw new Error('Using a URL as static.directory is not supported'); + throw new Error("Using a URL as static.directory is not supported"); } // ensure that publicPath is an array - if (typeof staticOption.publicPath === 'string') { + if (typeof staticOption.publicPath === "string") { staticOption.publicPath = [staticOption.publicPath]; } @@ -401,22 +401,22 @@ function normalizeOptions(compiler, options, logger, cacheDir) { }); } - const defaultWebSocketServerType = 'ws'; - const defaultWebSocketServerOptions = { path: '/ws' }; + const defaultWebSocketServerType = "ws"; + const defaultWebSocketServerOptions = { path: "/ws" }; - if (typeof options.webSocketServer === 'undefined') { + if (typeof options.webSocketServer === "undefined") { options.webSocketServer = { type: defaultWebSocketServerType, options: defaultWebSocketServerOptions, }; } else if ( - typeof options.webSocketServer === 'boolean' && + typeof options.webSocketServer === "boolean" && !options.webSocketServer ) { options.webSocketServer = false; } else if ( - typeof options.webSocketServer === 'string' || - typeof options.webSocketServer === 'function' + typeof options.webSocketServer === "string" || + typeof options.webSocketServer === "function" ) { options.webSocketServer = { type: options.webSocketServer, @@ -431,7 +431,7 @@ function normalizeOptions(compiler, options, logger, cacheDir) { }, }; - if (typeof options.webSocketServer.options.port === 'string') { + if (typeof options.webSocketServer.options.port === "string") { options.webSocketServer.options.port = Number( options.webSocketServer.options.port ); diff --git a/lint-staged.config.js b/lint-staged.config.js index 4000eeb1d0..ec5222129a 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; module.exports = { - '*.js': ['prettier --write', 'eslint --fix'], - '*.{json,md,yml,css}': ['prettier --write'], + "*.js": ["eslint --fix", "prettier --write"], + "*.{json,md,yml,css}": ["prettier --write"], }; diff --git a/migration-v4.md b/migration-v4.md index e362d5c685..82247d04fc 100644 --- a/migration-v4.md +++ b/migration-v4.md @@ -22,7 +22,7 @@ v4: ```js module.exports = { devServer: { - hot: 'only', + hot: "only", }, }; ``` @@ -37,8 +37,8 @@ v3: module.exports = { devServer: { before: function (app, server, compiler) { - app.get('/some/path', function (req, res) { - res.json({ custom: 'response' }); + app.get("/some/path", function (req, res) { + res.json({ custom: "response" }); }); }, }, @@ -51,8 +51,8 @@ v4: module.exports = { devServer: { onBeforeSetupMiddleware: function (devServer) { - devServer.app.get('/some/path', function (req, res) { - res.json({ custom: 'response' }); + devServer.app.get("/some/path", function (req, res) { + res.json({ custom: "response" }); }); }, }, @@ -67,8 +67,8 @@ v3: module.exports = { devServer: { after: function (app, server, compiler) { - app.get('/some/path', function (req, res) { - res.json({ custom: 'response' }); + app.get("/some/path", function (req, res) { + res.json({ custom: "response" }); }); }, }, @@ -81,8 +81,8 @@ v4: module.exports = { devServer: { onAfterSetupMiddleware: function (devServer) { - devServer.app.get('/some/path', function (req, res) { - res.json({ custom: 'response' }); + devServer.app.get("/some/path", function (req, res) { + res.json({ custom: "response" }); }); }, }, @@ -97,11 +97,11 @@ v3: ```js module.exports = { devServer: { - ca: './server.pem', - pfx: './server.pfx', - key: './server.key', - cert: './server.crt', - pfxPassphrase: 'webpack-dev-server', + ca: "./server.pem", + pfx: "./server.pfx", + key: "./server.key", + cert: "./server.crt", + pfxPassphrase: "webpack-dev-server", requestCert: true, }, }; @@ -113,11 +113,11 @@ v4: module.exports = { devServer: { https: { - cacert: './server.pem', - pfx: './server.pfx', - key: './server.key', - cert: './server.crt', - passphrase: 'webpack-dev-server', + cacert: "./server.pem", + pfx: "./server.pfx", + key: "./server.key", + cert: "./server.crt", + passphrase: "webpack-dev-server", requestCert: true, }, }, @@ -145,7 +145,7 @@ v4: ```js module.exports = { devServer: { - host: 'local-ip', + host: "local-ip", }, }; ``` @@ -160,8 +160,8 @@ v3: module.exports = { devServer: { index: true, - mimeTypes: { 'text/html': ['phtml'] }, - publicPath: '/publicPathForDevServe', + mimeTypes: { "text/html": ["phtml"] }, + publicPath: "/publicPathForDevServe", serverSideRender: true, writeToDisk: true, }, @@ -175,8 +175,8 @@ module.exports = { devServer: { devMiddleware: { index: true, - mimeTypes: { 'text/html': ['phtml'] }, - publicPath: '/publicPathForDevServe', + mimeTypes: { "text/html": ["phtml"] }, + publicPath: "/publicPathForDevServe", serverSideRender: true, writeToDisk: true, }, @@ -191,7 +191,7 @@ v3: ```js module.exports = { devServer: { - clientLogLevel: 'info', + clientLogLevel: "info", overlay: true, progress: true, }, @@ -204,7 +204,7 @@ v4: module.exports = { devServer: { client: { - logging: 'info', + logging: "info", // Can be used only for `errors`/`warnings` // // overlay: { @@ -225,7 +225,7 @@ v3: ```js module.exports = { devServer: { - public: 'ws://localhost:8080', + public: "ws://localhost:8080", }, }; ``` @@ -233,8 +233,8 @@ module.exports = { ```js module.exports = { devServer: { - sockHost: '0.0.0.0', - sockPath: '/ws', + sockHost: "0.0.0.0", + sockPath: "/ws", sockPort: 8080, }, }; @@ -250,8 +250,8 @@ module.exports = { // // webSocketURL: 'ws://0.0.0.0/ws' webSocketURL: { - hostname: '0.0.0.0', - pathname: '/ws', + hostname: "0.0.0.0", + pathname: "/ws", port: 8080, }, }, @@ -265,7 +265,7 @@ If you need to set custom `path` to dev server web socket server, please use: module.exports = { devServer: { webSocketServer: { - path: '/my/custom/path/to/web/socket/server', + path: "/my/custom/path/to/web/socket/server", }, }, }; @@ -279,8 +279,8 @@ v3: ```js module.exports = { devServer: { - contentBase: path.join(__dirname, 'public'), - contentBasePublicPath: '/serve-content-base-at-this-url', + contentBase: path.join(__dirname, "public"), + contentBasePublicPath: "/serve-content-base-at-this-url", serveIndex: true, watchContentBase: true, watchOptions: { @@ -296,12 +296,12 @@ v4: module.exports = { devServer: { static: { - directory: path.resolve(__dirname, 'static'), + directory: path.resolve(__dirname, "static"), staticOptions: {}, // Don't be confused with `devMiddleware.publicPath`, it is `publicPath` for static directory // Can be: // publicPath: ['/static-public-path-one/', '/static-public-path-two/'], - publicPath: '/static-public-path/', + publicPath: "/static-public-path/", // Can be: // serveIndex: {} (options for the `serveIndex` option you can find https://github.com/expressjs/serve-index) serveIndex: true, @@ -353,7 +353,7 @@ v4: ```js module.exports = { devServer: { - allowedHosts: 'all', + allowedHosts: "all", }, }; ``` @@ -386,10 +386,10 @@ module.exports = { module.exports = { devServer: { open: { - target: ['first.html', `http://localhost:8080/second.html`], + target: ["first.html", `http://localhost:8080/second.html`], app: { - name: 'google-chrome', - arguments: ['--incognito', '--new-window'], + name: "google-chrome", + arguments: ["--incognito", "--new-window"], }, }, }, @@ -402,15 +402,15 @@ v3: ```js module.exports = { - transportMode: 'ws', + transportMode: "ws", }; ``` ```js module.exports = { transportMode: { - client: require.resolve('./CustomClient'), - server: require.resolve('./CustomServer'), + client: require.resolve("./CustomClient"), + server: require.resolve("./CustomServer"), }, }; ``` @@ -421,7 +421,7 @@ v4: module.exports = { devServer: { // webSocketServer: 'sockjs', - webSocketServer: 'ws', + webSocketServer: "ws", }, }; ``` @@ -430,9 +430,9 @@ module.exports = { module.exports = { devServer: { client: { - webSocketTransport: require.resolve('./CustomClient'), + webSocketTransport: require.resolve("./CustomClient"), }, - webSocketServer: require.resolve('./CustomServer'), + webSocketServer: require.resolve("./CustomServer"), }, }; ``` @@ -480,7 +480,7 @@ There are a lot of other bug fixes. ```js module.exports = { entry: { - entry: ['whatwg-fetch', 'core-js/features/promise', './entry.js'], + entry: ["whatwg-fetch", "core-js/features/promise", "./entry.js"], }, }; ``` @@ -490,10 +490,10 @@ There are a lot of other bug fixes. ```js module.exports = { entry: { - entry: ['whatwg-fetch', 'core-js/features/promise', './entry.js'], + entry: ["whatwg-fetch", "core-js/features/promise", "./entry.js"], }, devServer: { - webSocketServer: 'sockjs', + webSocketServer: "sockjs", }, }; ``` diff --git a/setupTest.js b/setupTest.js index bb885657ac..0c7c3a98e2 100644 --- a/setupTest.js +++ b/setupTest.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; process.env.CHOKIDAR_USEPOLLING = true; diff --git a/test/cli/allowedHosts-option.test.js b/test/cli/allowedHosts-option.test.js index b7222235c4..47a4005d9a 100644 --- a/test/cli/allowedHosts-option.test.js +++ b/test/cli/allowedHosts-option.test.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; -const { testBin } = require('../helpers/test-bin'); -const port = require('../ports-map')['cli-allowed-hosts']; +const { testBin } = require("../helpers/test-bin"); +const port = require("../ports-map")["cli-allowed-hosts"]; describe('"allowedHosts" CLI option', () => { it('should work using "--allowed-hosts auto"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--allowed-hosts', - 'auto', + "--allowed-hosts", + "auto", ]); expect(exitCode).toEqual(0); @@ -17,10 +17,10 @@ describe('"allowedHosts" CLI option', () => { it('should work using "--allowed-hosts all"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--allowed-hosts', - 'all', + "--allowed-hosts", + "all", ]); expect(exitCode).toEqual(0); @@ -28,10 +28,10 @@ describe('"allowedHosts" CLI option', () => { it('should work using "--allowed-hosts testhouse.com"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--allowed-hosts', - 'testhouse.com', + "--allowed-hosts", + "testhouse.com", ]); expect(exitCode).toEqual(0); @@ -39,12 +39,12 @@ describe('"allowedHosts" CLI option', () => { it('should work using "--allowed-hosts testhost.com --allowed-hosts testhost1.com"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--allowed-hosts', - 'testhost.com', - '--allowed-hosts', - 'testhost1.com', + "--allowed-hosts", + "testhost.com", + "--allowed-hosts", + "testhost1.com", ]); expect(exitCode).toEqual(0); diff --git a/test/cli/basic.test.js b/test/cli/basic.test.js index fe4e554b24..aa20ee90cb 100644 --- a/test/cli/basic.test.js +++ b/test/cli/basic.test.js @@ -1,21 +1,21 @@ -'use strict'; - -const path = require('path'); -const webpack = require('webpack'); -const execa = require('execa'); -const stripAnsi = require('strip-ansi-v6'); -const schema = require('../../lib/options.json'); -const cliOptions = require('../../bin/cli-flags'); -const { testBin, normalizeStderr } = require('../helpers/test-bin'); -const isWebpack5 = require('../helpers/isWebpack5'); -const port = require('../ports-map')['cli-basic']; - -const isMacOS = process.platform === 'darwin'; +"use strict"; + +const path = require("path"); +const webpack = require("webpack"); +const execa = require("execa"); +const stripAnsi = require("strip-ansi-v6"); +const schema = require("../../lib/options.json"); +const cliOptions = require("../../bin/cli-flags"); +const { testBin, normalizeStderr } = require("../helpers/test-bin"); +const isWebpack5 = require("../helpers/isWebpack5"); +const port = require("../ports-map")["cli-basic"]; + +const isMacOS = process.platform === "darwin"; const webpack5Test = isWebpack5 ? it : it.skip; -describe('basic', () => { - describe('should validate CLI options', () => { - webpack5Test('should be same as in schema', () => { +describe("basic", () => { + describe("should validate CLI options", () => { + webpack5Test("should be same as in schema", () => { const cliOptionsFromWebpack = webpack.cli.getArguments(schema); const normalizedCliOptions = {}; @@ -32,293 +32,293 @@ describe('basic', () => { }); }); - describe('should output help', () => { - (isMacOS ? it.skip : it)('should generate correct cli flags', async () => { - const { exitCode, stdout } = await testBin(['--help']); + describe("should output help", () => { + (isMacOS ? it.skip : it)("should generate correct cli flags", async () => { + const { exitCode, stdout } = await testBin(["--help"]); expect(exitCode).toBe(0); expect(stripAnsi(stdout)).toMatchSnapshot(); }); }); - describe('basic', () => { - it('should work', async () => { + describe("basic", () => { + it("should work", async () => { const { exitCode, stderr } = await testBin([ // Ideally it should be empty to test without arguments, unfortunately it takes 8080 port and other test can failed - '--port', + "--port", port, ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it('should work using "--host localhost --port "', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--host', - 'localhost', + "--host", + "localhost", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); }); - it('should accept the promise function of webpack.config.js', async () => { + it("should accept the promise function of webpack.config.js", async () => { try { const { exitCode } = await testBin([ - '--config', + "--config", path.resolve( __dirname, - '../fixtures/promise-config/webpack.config.js' + "../fixtures/promise-config/webpack.config.js" ), - '--port', + "--port", port, ]); expect(exitCode).toEqual(0); } catch (err) { // for windows - expect(err.stdout).toContain('main.js'); + expect(err.stdout).toContain("main.js"); } }); - it('should exit the process when SIGINT is detected', (done) => { + it("should exit the process when SIGINT is detected", (done) => { const cliPath = path.resolve( __dirname, - '../../bin/webpack-dev-server.js' + "../../bin/webpack-dev-server.js" ); const examplePath = path.resolve( __dirname, - '../../examples/cli/web-socket-url' + "../../examples/cli/web-socket-url" ); - const cp = execa('node', ['--port', port, cliPath], { cwd: examplePath }); + const cp = execa("node", ["--port", port, cliPath], { cwd: examplePath }); - cp.stdout.on('data', (data) => { + cp.stdout.on("data", (data) => { const bits = data.toString(); if (/main.js/.test(bits)) { expect(cp.pid !== 0).toBe(true); - cp.kill('SIGINT'); + cp.kill("SIGINT"); } }); - cp.on('exit', () => { + cp.on("exit", () => { done(); }); }); - it('should exit the process when SIGINT is detected, even before the compilation is done', (done) => { + it("should exit the process when SIGINT is detected, even before the compilation is done", (done) => { const cliPath = path.resolve( __dirname, - '../../bin/webpack-dev-server.js' + "../../bin/webpack-dev-server.js" ); - const cwd = path.resolve(__dirname, '../fixtures/cli'); - const cp = execa('node', ['--port', port, cliPath], { cwd }); + const cwd = path.resolve(__dirname, "../fixtures/cli"); + const cp = execa("node", ["--port", port, cliPath], { cwd }); let killed = false; - cp.stdout.on('data', () => { + cp.stdout.on("data", () => { if (!killed) { expect(cp.pid !== 0).toBe(true); - cp.kill('SIGINT'); + cp.kill("SIGINT"); } killed = true; }); - cp.on('exit', () => { + cp.on("exit", () => { done(); }); }); - it('should exit the process when stdin ends if --watch-options-stdin', (done) => { + it("should exit the process when stdin ends if --watch-options-stdin", (done) => { const cliPath = path.resolve( __dirname, - '../../bin/webpack-dev-server.js' + "../../bin/webpack-dev-server.js" ); const examplePath = path.resolve( __dirname, - '../../examples/cli/web-socket-url' + "../../examples/cli/web-socket-url" ); const cp = execa( - 'node', - [cliPath, '--port', port, '--watch-options-stdin'], + "node", + [cliPath, "--port", port, "--watch-options-stdin"], { cwd: examplePath, } ); - cp.stdout.on('data', (data) => { + cp.stdout.on("data", (data) => { const bits = data.toString(); if (/main.js/.test(bits)) { expect(cp.pid !== 0).toBe(true); - cp.stdin.write('hello'); - cp.stdin.end('world'); + cp.stdin.write("hello"); + cp.stdin.end("world"); } }); - cp.on('exit', () => { + cp.on("exit", () => { done(); }); }); - it('should exit the process when stdin ends if --watch-options-stdin, even before the compilation is done', (done) => { + it("should exit the process when stdin ends if --watch-options-stdin, even before the compilation is done", (done) => { const cliPath = path.resolve( __dirname, - '../../bin/webpack-dev-server.js' + "../../bin/webpack-dev-server.js" ); - const cwd = path.resolve(__dirname, '../fixtures/cli'); + const cwd = path.resolve(__dirname, "../fixtures/cli"); const cp = execa( - 'node', - [cliPath, '--port', port, '--watch-options-stdin'], + "node", + [cliPath, "--port", port, "--watch-options-stdin"], { cwd } ); let killed = false; - cp.stdout.on('data', () => { + cp.stdout.on("data", () => { if (!killed) { expect(cp.pid !== 0).toBe(true); - cp.stdin.write('hello'); - cp.stdin.end('world'); + cp.stdin.write("hello"); + cp.stdin.end("world"); } killed = true; }); - cp.on('exit', () => { + cp.on("exit", () => { done(); }); }); - it('should add dev server entry points to a single entry point', async () => { + it("should add dev server entry points to a single entry point", async () => { const { exitCode, stdout } = await testBin([ - '--port', + "--port", port, - '--config', - './test/fixtures/dev-server/default-config.js', + "--config", + "./test/fixtures/dev-server/default-config.js", ]); expect(exitCode).toEqual(0); - expect(stdout).toContain('client/index.js?'); + expect(stdout).toContain("client/index.js?"); }); webpack5Test( - 'should add dev server entry points to a multi entry point object', + "should add dev server entry points to a multi entry point object", async () => { const { exitCode, stdout } = await testBin([ - '--port', + "--port", port, - '--config', - './test/fixtures/dev-server/multi-entry.js', - '--stats', - 'verbose', + "--config", + "./test/fixtures/dev-server/multi-entry.js", + "--stats", + "verbose", ]); expect(exitCode).toEqual(0); - expect(stdout).toContain('client/index.js?'); - expect(stdout).toContain('foo.js'); + expect(stdout).toContain("client/index.js?"); + expect(stdout).toContain("foo.js"); } ); webpack5Test( - 'should add dev server entry points to an empty entry object', + "should add dev server entry points to an empty entry object", async () => { const { exitCode, stdout } = await testBin([ - '--port', + "--port", port, - '--config', - './test/fixtures/dev-server/empty-entry.js', + "--config", + "./test/fixtures/dev-server/empty-entry.js", ]); expect(exitCode).toEqual(0); - expect(stdout).toContain('client/index.js?'); + expect(stdout).toContain("client/index.js?"); } ); - webpack5Test('should supports entry as descriptor', async () => { + webpack5Test("should supports entry as descriptor", async () => { const { exitCode, stdout } = await testBin([ - '--port', + "--port", port, - '--config', - './test/fixtures/entry-as-descriptor/webpack.config', - '--stats', - 'detailed', + "--config", + "./test/fixtures/entry-as-descriptor/webpack.config", + "--stats", + "detailed", ]); expect(exitCode).toEqual(0); - expect(stdout).toContain('foo.js'); + expect(stdout).toContain("foo.js"); }); it('should only prepends dev server entry points to "web" target', async () => { const { exitCode, stdout } = await testBin([ - '--port', + "--port", port, - '--target', - 'web', + "--target", + "web", ]); expect(exitCode).toEqual(0); - expect(stdout).toContain('client/index.js?'); - expect(stdout).toContain('foo.js'); + expect(stdout).toContain("client/index.js?"); + expect(stdout).toContain("foo.js"); }); it('should not prepend dev server entry points to "node" target', async () => { const { exitCode, stdout } = await testBin([ - '--port', + "--port", port, - '--target', - 'node', + "--target", + "node", ]); expect(exitCode).toEqual(0); - expect(stdout).not.toContain('client/index.js?'); - expect(stdout).toContain('foo.js'); + expect(stdout).not.toContain("client/index.js?"); + expect(stdout).toContain("foo.js"); }); it('should prepends the hot runtime to "node" target as well', async () => { const { exitCode, stdout } = await testBin([ - '--port', + "--port", port, - '--target', - 'node', - '--hot', + "--target", + "node", + "--hot", ]); expect(exitCode).toEqual(0); - expect(stdout).toContain('webpack/hot/dev-server'); + expect(stdout).toContain("webpack/hot/dev-server"); }); webpack5Test( - 'should prepend dev server entry points depending on targetProperties', + "should prepend dev server entry points depending on targetProperties", async () => { const { exitCode, stdout } = await testBin([ - '--port', + "--port", port, - '--config', - './test/fixtures/dev-server/target-config.js', + "--config", + "./test/fixtures/dev-server/target-config.js", ]); expect(exitCode).toEqual(0); - expect(stdout).toContain('client/index.js'); + expect(stdout).toContain("client/index.js"); } ); - it.skip('should use different random port when multiple instances are started on different processes', async () => { + it.skip("should use different random port when multiple instances are started on different processes", async () => { const cliPath = path.resolve( __dirname, - '../../bin/webpack-dev-server.js' + "../../bin/webpack-dev-server.js" ); - const cwd = path.resolve(__dirname, '../fixtures/cli'); + const cwd = path.resolve(__dirname, "../fixtures/cli"); - const cp = execa('node', [cliPath, '--colors=false'], { cwd }); - const cp2 = execa('node', [cliPath, '--colors=false'], { cwd }); + const cp = execa("node", [cliPath, "--colors=false"], { cwd }); + const cp2 = execa("node", [cliPath, "--colors=false"], { cwd }); const runtime = { cp: { @@ -331,7 +331,7 @@ describe('basic', () => { }, }; - cp.stderr.on('data', (data) => { + cp.stderr.on("data", (data) => { const bits = data.toString(); const portMatch = /Project is running at http:\/\/localhost:(\d*)\//.exec(bits); @@ -342,11 +342,11 @@ describe('basic', () => { if (/Compiled successfully/.test(bits)) { expect(cp.pid !== 0).toBe(true); - cp.kill('SIGINT'); + cp.kill("SIGINT"); } }); - cp2.stderr.on('data', (data) => { + cp2.stderr.on("data", (data) => { const bits = data.toString(); const portMatch = /Project is running at http:\/\/localhost:(\d*)\//.exec(bits); @@ -357,18 +357,18 @@ describe('basic', () => { if (/Compiled successfully/.test(bits)) { expect(cp.pid !== 0).toBe(true); - cp2.kill('SIGINT'); + cp2.kill("SIGINT"); } }); - cp.on('exit', () => { + cp.on("exit", () => { runtime.cp.done = true; if (runtime.cp2.done) { expect(runtime.cp.port !== runtime.cp2.port).toBe(true); } }); - cp2.on('exit', () => { + cp2.on("exit", () => { runtime.cp2.done = true; if (runtime.cp.done) { diff --git a/test/cli/bonjour-option.test.js b/test/cli/bonjour-option.test.js index 7cc424c6b8..9e123320fa 100644 --- a/test/cli/bonjour-option.test.js +++ b/test/cli/bonjour-option.test.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; -const { testBin, normalizeStderr } = require('../helpers/test-bin'); -const port = require('../ports-map')['cli-bonjour']; +const { testBin, normalizeStderr } = require("../helpers/test-bin"); +const port = require("../ports-map")["cli-bonjour"]; describe('"bonjour" CLI option', () => { it('should work using "--bonjour"', async () => { - const { exitCode, stderr } = await testBin(['--port', port, '--bonjour']); + const { exitCode, stderr } = await testBin(["--port", port, "--bonjour"]); expect(exitCode).toEqual(0); expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot(); @@ -13,10 +13,10 @@ describe('"bonjour" CLI option', () => { it('should work using "--bonjour and --https"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--bonjour', - '--https', + "--bonjour", + "--https", ]); expect(exitCode).toEqual(0); @@ -27,9 +27,9 @@ describe('"bonjour" CLI option', () => { it('should work using "--no-bonjour"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--no-bonjour', + "--no-bonjour", ]); expect(exitCode).toEqual(0); diff --git a/test/cli/client-option.test.js b/test/cli/client-option.test.js index 11ab2fbb1f..f1592d297f 100644 --- a/test/cli/client-option.test.js +++ b/test/cli/client-option.test.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; -const { testBin } = require('../helpers/test-bin'); -const port = require('../ports-map')['cli-client']; +const { testBin } = require("../helpers/test-bin"); +const port = require("../ports-map")["cli-client"]; describe('"client" CLI option', () => { it('should work using "--client-web-socket-transport sockjs"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--client-web-socket-transport', - 'sockjs', + "--client-web-socket-transport", + "sockjs", ]); expect(exitCode).toEqual(0); @@ -17,32 +17,32 @@ describe('"client" CLI option', () => { it('should work using "--client-web-socket-transport ws"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--client-web-socket-transport', - 'ws', + "--client-web-socket-transport", + "ws", ]); expect(exitCode).toEqual(0); }); it('should work using "--client-overlay"', async () => { - const { exitCode } = await testBin(['--port', port, '--client-overlay']); + const { exitCode } = await testBin(["--port", port, "--client-overlay"]); expect(exitCode).toEqual(0); }); it('should work using "--no-client-overlay"', async () => { - const { exitCode } = await testBin(['--port', port, '--no-client-overlay']); + const { exitCode } = await testBin(["--port", port, "--no-client-overlay"]); expect(exitCode).toEqual(0); }); it('should work using "--client-overlay-errors"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--client-overlay-errors', + "--client-overlay-errors", ]); expect(exitCode).toEqual(0); @@ -50,9 +50,9 @@ describe('"client" CLI option', () => { it('should work using "--no-client-overlay-errors"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--no-client-overlay-errors', + "--no-client-overlay-errors", ]); expect(exitCode).toEqual(0); @@ -60,9 +60,9 @@ describe('"client" CLI option', () => { it('should work using "--client-overlay-warnings"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--client-overlay-warnings', + "--client-overlay-warnings", ]); expect(exitCode).toEqual(0); @@ -70,9 +70,9 @@ describe('"client" CLI option', () => { it('should work using "--no-client-overlay-warnings"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--no-client-overlay-warnings', + "--no-client-overlay-warnings", ]); expect(exitCode).toEqual(0); @@ -80,26 +80,26 @@ describe('"client" CLI option', () => { it('should work using "--client-logging"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--client-logging', - 'verbose', + "--client-logging", + "verbose", ]); expect(exitCode).toEqual(0); }); it('should work using "--client-progress"', async () => { - const { exitCode } = await testBin(['--port', port, '--client-progress']); + const { exitCode } = await testBin(["--port", port, "--client-progress"]); expect(exitCode).toEqual(0); }); it('should work using "--no-client-progress"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--no-client-progress', + "--no-client-progress", ]); expect(exitCode).toEqual(0); @@ -107,10 +107,10 @@ describe('"client" CLI option', () => { it('should work using "--client-web-socket-url"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--client-web-socket-url', - 'ws://myhost.com:8080/foo/test', + "--client-web-socket-url", + "ws://myhost.com:8080/foo/test", ]); expect(exitCode).toEqual(0); @@ -118,10 +118,10 @@ describe('"client" CLI option', () => { it('should work using "--client-web-socket-url-protocol"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--client-web-socket-url-protocol', - 'ws:', + "--client-web-socket-url-protocol", + "ws:", ]); expect(exitCode).toEqual(0); @@ -129,10 +129,10 @@ describe('"client" CLI option', () => { it('should work using "--client-web-socket-url-hostname"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--client-web-socket-url-hostname', - '0.0.0.0', + "--client-web-socket-url-hostname", + "0.0.0.0", ]); expect(exitCode).toEqual(0); @@ -140,10 +140,10 @@ describe('"client" CLI option', () => { it('should work using "--client-web-socket-url-pathname"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--client-web-socket-url-pathname', - '/ws', + "--client-web-socket-url-pathname", + "/ws", ]); expect(exitCode).toEqual(0); @@ -151,9 +151,9 @@ describe('"client" CLI option', () => { it('should work using "--client-web-socket-url-port"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--client-web-socket-url-port', + "--client-web-socket-url-port", 8080, ]); diff --git a/test/cli/colors.test.js b/test/cli/colors.test.js index c4f308b67d..81a43d17b1 100644 --- a/test/cli/colors.test.js +++ b/test/cli/colors.test.js @@ -1,79 +1,79 @@ -'use strict'; +"use strict"; -const { testBin, normalizeStderr } = require('../helpers/test-bin'); -const port = require('../ports-map')['cli-colors']; +const { testBin, normalizeStderr } = require("../helpers/test-bin"); +const port = require("../ports-map")["cli-colors"]; const colorsDefaultStats = require.resolve( - '../fixtures/cli-colors-default-stats/webpack.config' + "../fixtures/cli-colors-default-stats/webpack.config" ); const colorsDisabled = require.resolve( - '../fixtures/cli-colors-disabled/webpack.config' + "../fixtures/cli-colors-disabled/webpack.config" ); const colorsEnabled = require.resolve( - '../fixtures/cli-colors-enabled/webpack.config' + "../fixtures/cli-colors-enabled/webpack.config" ); -describe('colors', () => { - it('should work use colors by default', async () => { +describe("colors", () => { + it("should work use colors by default", async () => { const { exitCode, stderr, stdout } = await testBin([ - '--port', + "--port", port, - '--color', + "--color", colorsDefaultStats, ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); - expect(stdout).toContain('\x1b[1m'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); + expect(stdout).toContain("\x1b[1m"); }); it('should work use colors using "--color"', async () => { const { exitCode, stderr, stdout } = await testBin([ - '--port', + "--port", port, - '--color', + "--color", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); - expect(stdout).toContain('\x1b[1m'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); + expect(stdout).toContain("\x1b[1m"); }); it('should work do not use colors using "--no-color"', async () => { const { exitCode, stderr, stdout } = await testBin([ - '--port', + "--port", port, - '--no-color', + "--no-color", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); - expect(stdout).not.toContain('\x1b[1m'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); + expect(stdout).not.toContain("\x1b[1m"); }); - it('should work use colors using configuration with enabled colors', async () => { + it("should work use colors using configuration with enabled colors", async () => { const { exitCode, stderr, stdout } = await testBin([ - '--port', + "--port", port, - '--config', + "--config", colorsEnabled, ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); - expect(stdout).toContain('\x1b[1m'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); + expect(stdout).toContain("\x1b[1m"); }); - it('should work and do not use colors using configuration with disabled colors', async () => { + it("should work and do not use colors using configuration with disabled colors", async () => { const { exitCode, stderr, stdout } = await testBin([ - '--port', + "--port", port, - '--config', + "--config", colorsDisabled, ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); - expect(stdout).not.toContain('\x1b[1m'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); + expect(stdout).not.toContain("\x1b[1m"); }); }); diff --git a/test/cli/compress-option.test.js b/test/cli/compress-option.test.js index 70042dad3f..7f87d05772 100644 --- a/test/cli/compress-option.test.js +++ b/test/cli/compress-option.test.js @@ -1,17 +1,17 @@ -'use strict'; +"use strict"; -const { testBin } = require('../helpers/test-bin'); -const port = require('../ports-map')['cli-compress']; +const { testBin } = require("../helpers/test-bin"); +const port = require("../ports-map")["cli-compress"]; describe('"compress" CLI option', () => { it('should work using "--compress"', async () => { - const { exitCode } = await testBin(['--port', port, '--compress']); + const { exitCode } = await testBin(["--port", port, "--compress"]); expect(exitCode).toEqual(0); }); it('should work using "--no-compress"', async () => { - const { exitCode } = await testBin(['--port', port, '--no-compress']); + const { exitCode } = await testBin(["--port", port, "--no-compress"]); expect(exitCode).toEqual(0); }); diff --git a/test/cli/historyApiFallback-option.test.js b/test/cli/historyApiFallback-option.test.js index afd857fee1..e8cbf13a85 100644 --- a/test/cli/historyApiFallback-option.test.js +++ b/test/cli/historyApiFallback-option.test.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict"; -const { testBin, normalizeStderr } = require('../helpers/test-bin'); -const port = require('../ports-map')['cli-history-api-fallback']; +const { testBin, normalizeStderr } = require("../helpers/test-bin"); +const port = require("../ports-map")["cli-history-api-fallback"]; describe('"historyApiFallback" CLI option', () => { it('should work using "--history-api-fallback"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--history-api-fallback', + "--history-api-fallback", ]); expect(exitCode).toEqual(0); @@ -17,9 +17,9 @@ describe('"historyApiFallback" CLI option', () => { it('should work using "--no-history-api-fallback"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--no-history-api-fallback', + "--no-history-api-fallback", ]); expect(exitCode).toEqual(0); diff --git a/test/cli/host-option.test.js b/test/cli/host-option.test.js index 5ea2f75fd8..aa05980dbd 100644 --- a/test/cli/host-option.test.js +++ b/test/cli/host-option.test.js @@ -1,8 +1,8 @@ -'use strict'; +"use strict"; -const internalIp = require('internal-ip'); -const { testBin, normalizeStderr } = require('../helpers/test-bin'); -const port = require('../ports-map')['cli-host']; +const internalIp = require("internal-ip"); +const { testBin, normalizeStderr } = require("../helpers/test-bin"); +const port = require("../ports-map")["cli-host"]; const localIPv4 = internalIp.v4.sync(); const localIPv6 = internalIp.v6.sync(); @@ -10,121 +10,121 @@ const localIPv6 = internalIp.v6.sync(); describe('"host" CLI option', () => { it('should work using "--host 0.0.0.0" (IPv4)', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--host', - '0.0.0.0', + "--host", + "0.0.0.0", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it('should work using "--host ::" (IPv6)', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--host', - '::', + "--host", + "::", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it('should work using "--host ::1" (IPv6)', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--host', - '::1', + "--host", + "::1", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); }); it('should work using "--host localhost"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--host', - 'localhost', + "--host", + "localhost", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); }); it('should work using "--host 127.0.0.1" (IPv4)', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--host', - '127.0.0.1', + "--host", + "127.0.0.1", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); }); it('should work using "--host ::1" (IPv6)', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--host', - '::1', + "--host", + "::1", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); }); it(`should work using "--host "`, async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--host', + "--host", localIPv4, ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); }); it.skip(`should work using "--host "`, async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--host', + "--host", localIPv6, ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); }); it('should work using "--host local-ip"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--host', - 'local-ip', + "--host", + "local-ip", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); }); it('should work using "--host local-ipv4"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--host', - 'local-ipv4', + "--host", + "local-ipv4", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); }); }); diff --git a/test/cli/hot-option.test.js b/test/cli/hot-option.test.js index 70ad756426..7a31f1de61 100644 --- a/test/cli/hot-option.test.js +++ b/test/cli/hot-option.test.js @@ -1,42 +1,42 @@ -'use strict'; +"use strict"; -const { testBin } = require('../helpers/test-bin'); -const port = require('../ports-map')['cli-hot']; +const { testBin } = require("../helpers/test-bin"); +const port = require("../ports-map")["cli-hot"]; describe('"hot" CLI option', () => { it('should work using "--hot"', async () => { const { exitCode, stdout } = await testBin([ - '--port', + "--port", port, - '--hot', - '--stats=detailed', + "--hot", + "--stats=detailed", ]); expect(exitCode).toEqual(0); - expect(stdout).toContain('webpack/hot/dev-server.js'); + expect(stdout).toContain("webpack/hot/dev-server.js"); }); it('should work using "--no-hot"', async () => { const { exitCode, stdout } = await testBin([ - '--port', + "--port", port, - '--no-hot', - '--stats=detailed', + "--no-hot", + "--stats=detailed", ]); expect(exitCode).toEqual(0); - expect(stdout).not.toContain('webpack/hot/dev-server.js'); + expect(stdout).not.toContain("webpack/hot/dev-server.js"); }); it('should work using "--hot only"', async () => { const { exitCode, stdout } = await testBin([ - '--port', + "--port", port, - '--hot', - 'only', + "--hot", + "only", ]); expect(exitCode).toEqual(0); - expect(stdout).toContain('/hot/only-dev-server.js'); + expect(stdout).toContain("/hot/only-dev-server.js"); }); }); diff --git a/test/cli/http2-option.test.js b/test/cli/http2-option.test.js index 9a12d70fbb..3f7f354d9b 100644 --- a/test/cli/http2-option.test.js +++ b/test/cli/http2-option.test.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; -const { testBin, normalizeStderr } = require('../helpers/test-bin'); -const port = require('../ports-map')['cli-http2']; +const { testBin, normalizeStderr } = require("../helpers/test-bin"); +const port = require("../ports-map")["cli-http2"]; describe('"http2" CLI option', () => { it('should work using "--http2"', async () => { - const { exitCode, stderr } = await testBin(['--port', port, '--http2']); + const { exitCode, stderr } = await testBin(["--port", port, "--http2"]); expect(exitCode).toEqual(0); expect( @@ -14,7 +14,7 @@ describe('"http2" CLI option', () => { }); it('should work using "--no-http2"', async () => { - const { exitCode, stderr } = await testBin(['--port', port, '--no-http2']); + const { exitCode, stderr } = await testBin(["--port", port, "--no-http2"]); expect(exitCode).toEqual(0); expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot(); diff --git a/test/cli/https-option.test.js b/test/cli/https-option.test.js index 4b2b8c8d4d..06870f0b84 100644 --- a/test/cli/https-option.test.js +++ b/test/cli/https-option.test.js @@ -1,17 +1,17 @@ -'use strict'; +"use strict"; -const path = require('path'); -const { testBin, normalizeStderr } = require('../helpers/test-bin'); -const port = require('../ports-map')['cli-https']; +const path = require("path"); +const { testBin, normalizeStderr } = require("../helpers/test-bin"); +const port = require("../ports-map")["cli-https"]; const httpsCertificateDirectory = path.resolve( __dirname, - '../fixtures/https-certificate' + "../fixtures/https-certificate" ); describe('"https" CLI option', () => { it('should work using "--https"', async () => { - const { exitCode, stderr } = await testBin(['--port', port, '--https']); + const { exitCode, stderr } = await testBin(["--port", port, "--https"]); expect(exitCode).toEqual(0); expect( @@ -20,24 +20,24 @@ describe('"https" CLI option', () => { }); it('should work using "--https-key --https-pfx --https-passphrase webpack-dev-server --https-cert --https-cacert "', async () => { - const pfxFile = path.join(httpsCertificateDirectory, 'server.pfx'); - const key = path.join(httpsCertificateDirectory, 'server.key'); - const cert = path.join(httpsCertificateDirectory, 'server.crt'); - const cacert = path.join(httpsCertificateDirectory, 'ca.pem'); - const passphrase = 'webpack-dev-server'; + const pfxFile = path.join(httpsCertificateDirectory, "server.pfx"); + const key = path.join(httpsCertificateDirectory, "server.key"); + const cert = path.join(httpsCertificateDirectory, "server.crt"); + const cacert = path.join(httpsCertificateDirectory, "ca.pem"); + const passphrase = "webpack-dev-server"; const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--https-key', + "--https-key", key, - '--https-pfx', + "--https-pfx", pfxFile, - '--https-passphrase', + "--https-passphrase", passphrase, - '--https-cert', + "--https-cert", cert, - '--https-cacert', + "--https-cacert", cacert, ]); @@ -49,21 +49,21 @@ describe('"https" CLI option', () => { // For https://github.com/webpack/webpack-dev-server/issues/3306 it('should work using "--https-key --https-pfx --https-passphrase webpack-dev-server --https-cert "', async () => { - const pfxFile = path.join(httpsCertificateDirectory, 'server.pfx'); - const key = path.join(httpsCertificateDirectory, 'server.key'); - const cert = path.join(httpsCertificateDirectory, 'server.crt'); - const passphrase = 'webpack-dev-server'; + const pfxFile = path.join(httpsCertificateDirectory, "server.pfx"); + const key = path.join(httpsCertificateDirectory, "server.key"); + const cert = path.join(httpsCertificateDirectory, "server.crt"); + const passphrase = "webpack-dev-server"; const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--https-key', + "--https-key", key, - '--https-pfx', + "--https-pfx", pfxFile, - '--https-passphrase', + "--https-passphrase", passphrase, - '--https-cert', + "--https-cert", cert, ]); @@ -75,9 +75,9 @@ describe('"https" CLI option', () => { it('should work using "--https-request-cert"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--https-request-cert', + "--https-request-cert", ]); expect(exitCode).toEqual(0); @@ -88,9 +88,9 @@ describe('"https" CLI option', () => { it('should work using "--no-https-request-cert"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--no-https-request-cert', + "--no-https-request-cert", ]); expect(exitCode).toEqual(0); @@ -100,7 +100,7 @@ describe('"https" CLI option', () => { }); it('should work using "--no-https"', async () => { - const { exitCode, stderr } = await testBin(['--port', port, '--no-https']); + const { exitCode, stderr } = await testBin(["--port", port, "--no-https"]); expect(exitCode).toEqual(0); expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot(); diff --git a/test/cli/ipc-option.test.js b/test/cli/ipc-option.test.js index fdb5cd14cb..35701f1356 100644 --- a/test/cli/ipc-option.test.js +++ b/test/cli/ipc-option.test.js @@ -1,26 +1,26 @@ -'use strict'; +"use strict"; -const path = require('path'); -const os = require('os'); -const { testBin, normalizeStderr } = require('../helpers/test-bin'); +const path = require("path"); +const os = require("os"); +const { testBin, normalizeStderr } = require("../helpers/test-bin"); describe('"ipc" CLI option', () => { it('should work using "--ipc"', async () => { - const { exitCode, stderr } = await testBin(['--ipc']); + const { exitCode, stderr } = await testBin(["--ipc"]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); }); it('should work using "--ipc="', async () => { - const isWindows = process.platform === 'win32'; - const pipePrefix = isWindows ? '\\\\.\\pipe\\' : os.tmpdir(); + const isWindows = process.platform === "win32"; + const pipePrefix = isWindows ? "\\\\.\\pipe\\" : os.tmpdir(); const pipeName = `webpack-dev-server.cli.sock`; const ipc = path.join(pipePrefix, pipeName); - const { exitCode, stderr } = await testBin(['--ipc', ipc]); + const { exitCode, stderr } = await testBin(["--ipc", ipc]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr)).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); }); }); diff --git a/test/cli/liveReload-option.test.js b/test/cli/liveReload-option.test.js index 5177540200..716e1bd3a7 100644 --- a/test/cli/liveReload-option.test.js +++ b/test/cli/liveReload-option.test.js @@ -1,17 +1,17 @@ -'use strict'; +"use strict"; -const { testBin } = require('../helpers/test-bin'); -const port = require('../ports-map')['cli-live-reload']; +const { testBin } = require("../helpers/test-bin"); +const port = require("../ports-map")["cli-live-reload"]; describe('"liveReload" CLI option', () => { it('should work using "--live-reload"', async () => { - const { exitCode } = await testBin(['--port', port, '--live-reload']); + const { exitCode } = await testBin(["--port", port, "--live-reload"]); expect(exitCode).toEqual(0); }); it('should work using "--no-live-reload"', async () => { - const { exitCode } = await testBin(['--port', port, '--no-live-reload']); + const { exitCode } = await testBin(["--port", port, "--no-live-reload"]); expect(exitCode).toEqual(0); }); diff --git a/test/cli/open-option.test.js b/test/cli/open-option.test.js index 552e82e68c..b673d4774f 100644 --- a/test/cli/open-option.test.js +++ b/test/cli/open-option.test.js @@ -1,21 +1,21 @@ -'use strict'; +"use strict"; -const { testBin } = require('../helpers/test-bin'); -const port = require('../ports-map')['cli-open']; +const { testBin } = require("../helpers/test-bin"); +const port = require("../ports-map")["cli-open"]; describe('"open" CLI option', () => { it('should work using "--open"', async () => { - const { exitCode } = await testBin(['--port', port, '--open']); + const { exitCode } = await testBin(["--port", port, "--open"]); expect(exitCode).toEqual(0); }); it('should work using "--open /index.html"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--open', - '/index.html', + "--open", + "/index.html", ]); expect(exitCode).toEqual(0); @@ -23,29 +23,29 @@ describe('"open" CLI option', () => { it('should work using "--open /first.html second.html"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--open', - '/first.html', - 'second.html', + "--open", + "/first.html", + "second.html", ]); expect(exitCode).toEqual(0); }); it('should work using "--no-open"', async () => { - const { exitCode } = await testBin(['--no-open', '--port', port]); + const { exitCode } = await testBin(["--no-open", "--port", port]); expect(exitCode).toEqual(0); }); it('should work using "--open-reset --open /third.html"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--open-reset', - '--open', - '/third.html', + "--open-reset", + "--open", + "/third.html", ]); expect(exitCode).toEqual(0); @@ -53,11 +53,11 @@ describe('"open" CLI option', () => { it('should work using "--open-reset --open-target "', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--open-reset', - '--open-target', - '', + "--open-reset", + "--open-target", + "", ]); expect(exitCode).toEqual(0); @@ -65,11 +65,11 @@ describe('"open" CLI option', () => { it('should work using "--open-reset --open-target /third.html"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--open-reset', - '--open-target', - '/third.html', + "--open-reset", + "--open-target", + "/third.html", ]); expect(exitCode).toEqual(0); @@ -77,10 +77,10 @@ describe('"open" CLI option', () => { it('should work using "--open-app google-chrome"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--open-app', - 'google-chrome', + "--open-app", + "google-chrome", ]); expect(exitCode).toEqual(0); @@ -88,10 +88,10 @@ describe('"open" CLI option', () => { it('should work using "--open-app-name google-chrome"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--open-app-name', - 'google-chrome', + "--open-app-name", + "google-chrome", ]); expect(exitCode).toEqual(0); @@ -99,11 +99,11 @@ describe('"open" CLI option', () => { it('should work using "--open-app-name-reset --open-app-name firefox"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--open-app-name-reset', - '--open-app-name', - 'firefox', + "--open-app-name-reset", + "--open-app-name", + "firefox", ]); expect(exitCode).toEqual(0); @@ -111,10 +111,10 @@ describe('"open" CLI option', () => { it('should work using "--open-target index.html"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--open-target', - 'index.html', + "--open-target", + "index.html", ]); expect(exitCode).toEqual(0); @@ -122,11 +122,11 @@ describe('"open" CLI option', () => { it('should work using "--open-target-reset --open-target first.html"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--open-target-reset', - '--open-target', - 'first.html', + "--open-target-reset", + "--open-target", + "first.html", ]); expect(exitCode).toEqual(0); @@ -134,11 +134,11 @@ describe('"open" CLI option', () => { it('should work using "--open-target /first.html second.html"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--open-target', - '/first.html', - 'second.html', + "--open-target", + "/first.html", + "second.html", ]); expect(exitCode).toEqual(0); @@ -146,12 +146,12 @@ describe('"open" CLI option', () => { it('should work using "--open-target /index.html --open-app google-chrome"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--open-target', - '/index.html', - '--open-app', - 'google-chrome', + "--open-target", + "/index.html", + "--open-app", + "google-chrome", ]); expect(exitCode).toEqual(0); @@ -159,12 +159,12 @@ describe('"open" CLI option', () => { it('should work using "--open-target /index.html --open-app-name google-chrome"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--open-target', - '/index.html', - '--open-app-name', - 'google-chrome', + "--open-target", + "/index.html", + "--open-app-name", + "google-chrome", ]); expect(exitCode).toEqual(0); @@ -172,14 +172,14 @@ describe('"open" CLI option', () => { it('should work using "--open-target /index.html --open-app google-chrome --open-app-name google-chrome"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--open-target', - '/index.html', - '--open-app', - 'google-chrome', - '--open-app-name', - 'google-chrome', + "--open-target", + "/index.html", + "--open-app", + "google-chrome", + "--open-app-name", + "google-chrome", ]); expect(exitCode).toEqual(0); diff --git a/test/cli/port-option.test.js b/test/cli/port-option.test.js index f2eb4136af..3d85f35ff8 100644 --- a/test/cli/port-option.test.js +++ b/test/cli/port-option.test.js @@ -1,20 +1,20 @@ -'use strict'; +"use strict"; -const { testBin, normalizeStderr } = require('../helpers/test-bin'); -const port = require('../ports-map')['cli-port-option']; +const { testBin, normalizeStderr } = require("../helpers/test-bin"); +const port = require("../ports-map")["cli-port-option"]; describe('"port" CLI option', () => { it('should work using "--port "', async () => { - const { exitCode, stderr } = await testBin(['--port', port]); + const { exitCode, stderr } = await testBin(["--port", port]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it(`should work using "--port auto"`, async () => { - const { exitCode, stderr } = await testBin(['--port', 'auto']); + const { exitCode, stderr } = await testBin(["--port", "auto"]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); }); diff --git a/test/cli/static-option.test.js b/test/cli/static-option.test.js index d350df9214..5a923ae94b 100644 --- a/test/cli/static-option.test.js +++ b/test/cli/static-option.test.js @@ -1,146 +1,146 @@ -'use strict'; +"use strict"; -const { testBin, normalizeStderr } = require('../helpers/test-bin'); -const port = require('../ports-map')['cli-static']; +const { testBin, normalizeStderr } = require("../helpers/test-bin"); +const port = require("../ports-map")["cli-static"]; describe('"static" CLI option', () => { it('should work using "--static"', async () => { - const { exitCode, stderr } = await testBin(['--port', port, '--static']); + const { exitCode, stderr } = await testBin(["--port", port, "--static"]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it('should work using "--static new-static"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--static', - 'new-static', + "--static", + "new-static", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it('should work using "--static new-static --static other-static"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--static', - 'new-static', - '--static', - 'other-static', + "--static", + "new-static", + "--static", + "other-static", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it('should work using "--static-reset"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--static-reset', - '--static', - 'new-static-after-reset', + "--static-reset", + "--static", + "new-static-after-reset", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it('should work using "--static-reset --static-directory new-static-directory"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--static-reset', - '--static-directory', - 'new-static-directory', + "--static-reset", + "--static-directory", + "new-static-directory", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it('should work using "--static-directory static-dir"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--static-directory', - 'static-dir', + "--static-directory", + "static-dir", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it('should work using "--static-public-path /public"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--static-public-path', - '/public', + "--static-public-path", + "/public", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it('should work using "--static-public-path-reset"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--static-public-path-reset', - '--static-public-path', - '/new-public', + "--static-public-path-reset", + "--static-public-path", + "/new-public", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it('should work using "--static-serve-index"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--static-serve-index', + "--static-serve-index", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it('should work using "--no-static-serve-index"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--no-static-serve-index', + "--no-static-serve-index", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it('should work using "--static-watch"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--static-watch', + "--static-watch", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it('should work using "--no-static-watch"', async () => { const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--no-static-watch', + "--no-static-watch", ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); }); diff --git a/test/cli/watchFiles-option.test.js b/test/cli/watchFiles-option.test.js index 444f62c60e..d601481c10 100644 --- a/test/cli/watchFiles-option.test.js +++ b/test/cli/watchFiles-option.test.js @@ -1,56 +1,56 @@ -'use strict'; +"use strict"; -const path = require('path'); -const { testBin, normalizeStderr } = require('../helpers/test-bin'); -const port = require('../ports-map')['cli-watch-files']; +const path = require("path"); +const { testBin, normalizeStderr } = require("../helpers/test-bin"); +const port = require("../ports-map")["cli-watch-files"]; describe('"watchFiles" CLI option', () => { it('should work using "--watch-files "', async () => { - const watchDirectory = path.resolve(__dirname, '../fixtures/static/static'); + const watchDirectory = path.resolve(__dirname, "../fixtures/static/static"); const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--watch-files', + "--watch-files", watchDirectory, ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it('should work using "--watch-files --watch-files "', async () => { - const watchDirectory = path.resolve(__dirname, '../fixtures/static/static'); + const watchDirectory = path.resolve(__dirname, "../fixtures/static/static"); const watchOtherDirectory = path.resolve( __dirname, - '../fixtures/static/simple-config' + "../fixtures/static/simple-config" ); const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--watch-files', + "--watch-files", watchDirectory, - '--watch-files', + "--watch-files", watchOtherDirectory, ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); it('should work using "--watch-files-reset --watch-files "', async () => { - const watchDirectory = path.resolve(__dirname, '../fixtures/static/static'); + const watchDirectory = path.resolve(__dirname, "../fixtures/static/static"); const { exitCode, stderr } = await testBin([ - '--port', + "--port", port, - '--watch-files-reset', - '--watch-files', + "--watch-files-reset", + "--watch-files", watchDirectory, ]); expect(exitCode).toEqual(0); - expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot('stderr'); + expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr"); }); }); diff --git a/test/cli/webSocketServer-option.test.js b/test/cli/webSocketServer-option.test.js index 0240e5d9c6..51f0f14826 100644 --- a/test/cli/webSocketServer-option.test.js +++ b/test/cli/webSocketServer-option.test.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; -const { testBin } = require('../helpers/test-bin'); -const port = require('../ports-map')['cli-web-socket-server']; +const { testBin } = require("../helpers/test-bin"); +const port = require("../ports-map")["cli-web-socket-server"]; describe('"webSocketServer" CLI option', () => { it('should work using "--web-socket-server sockjs"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--web-socket-server', - 'sockjs', + "--web-socket-server", + "sockjs", ]); expect(exitCode).toEqual(0); @@ -17,10 +17,10 @@ describe('"webSocketServer" CLI option', () => { it('should work using "--web-socket-server ws"', async () => { const { exitCode } = await testBin([ - '--port', + "--port", port, - '--web-socket-server', - 'ws', + "--web-socket-server", + "ws", ]); expect(exitCode).toEqual(0); diff --git a/test/client/bundle.test.js b/test/client/bundle.test.js index 928a5502a5..7db01f1a03 100644 --- a/test/client/bundle.test.js +++ b/test/client/bundle.test.js @@ -1,28 +1,28 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const acorn = require('acorn'); -const request = require('supertest'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/simple-config/webpack.config'); -const port = require('../ports-map').bundle; -const isWebpack5 = require('../helpers/isWebpack5'); +const webpack = require("webpack"); +const acorn = require("acorn"); +const request = require("supertest"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/simple-config/webpack.config"); +const port = require("../ports-map").bundle; +const isWebpack5 = require("../helpers/isWebpack5"); -describe('bundle', () => { - describe('main.js bundled output', () => { +describe("bundle", () => { + describe("main.js bundled output", () => { let server; let req; beforeAll(async () => { const compiler = webpack({ ...config, - target: isWebpack5 ? ['es5', 'web'] : 'web', + target: isWebpack5 ? ["es5", "web"] : "web", }); server = new Server({ port }, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -44,10 +44,10 @@ describe('bundle', () => { }); }); - it('should get full user bundle and parse with ES5', async () => { + it("should get full user bundle and parse with ES5", async () => { const { text } = await req - .get('/main.js') - .expect('Content-Type', 'application/javascript; charset=utf-8') + .get("/main.js") + .expect("Content-Type", "application/javascript; charset=utf-8") .expect(200); expect(() => { @@ -64,11 +64,11 @@ describe('bundle', () => { // this can be done by waiting for tokens during the main parse // then when we hit a string in an 'eval' function we also try // to parse that string with ES5 - if (token.type.label === 'name' && token.value === 'eval') { + if (token.type.label === "name" && token.value === "eval") { evalStep += 1; - } else if (token.type.label === '(' && evalStep === 1) { + } else if (token.type.label === "(" && evalStep === 1) { evalStep += 1; - } else if (token.type.label === 'string' && evalStep === 2) { + } else if (token.type.label === "string" && evalStep === 2) { const program = token.value; acorn.parse(program, { ecmaVersion: 5, diff --git a/test/client/clients/SockJSClient.test.js b/test/client/clients/SockJSClient.test.js index 5bd2988011..1b767b7749 100644 --- a/test/client/clients/SockJSClient.test.js +++ b/test/client/clients/SockJSClient.test.js @@ -2,37 +2,37 @@ * @jest-environment jsdom */ -'use strict'; +"use strict"; -const http = require('http'); -const express = require('express'); -const sockjs = require('sockjs'); -const port = require('../../ports-map')['sockjs-client']; +const http = require("http"); +const express = require("express"); +const sockjs = require("sockjs"); +const port = require("../../ports-map")["sockjs-client"]; -jest.setMock('../../../client-src/utils/log', { +jest.setMock("../../../client-src/utils/log", { log: { error: jest.fn(), }, }); -describe('SockJSClient', () => { - const SockJSClient = require('../../../client-src/clients/SockJSClient'); - const { log } = require('../../../client-src/utils/log'); +describe("SockJSClient", () => { + const SockJSClient = require("../../../client-src/clients/SockJSClient"); + const { log } = require("../../../client-src/utils/log"); let consoleMock; let socketServer; let server; beforeAll((done) => { - consoleMock = jest.spyOn(console, 'log').mockImplementation(); + consoleMock = jest.spyOn(console, "log").mockImplementation(); // eslint-disable-next-line new-cap const app = new express(); server = http.createServer(app); - server.listen(port, 'localhost', () => { + server.listen(port, "localhost", () => { socketServer = sockjs.createServer(); socketServer.installHandlers(server, { - prefix: '/ws', + prefix: "/ws", }); done(); }); @@ -42,10 +42,10 @@ describe('SockJSClient', () => { consoleMock.mockRestore(); }); - describe('client', () => { - it('should open, receive message, and close', (done) => { - socketServer.on('connection', (connection) => { - connection.write('hello world'); + describe("client", () => { + it("should open, receive message, and close", (done) => { + socketServer.on("connection", (connection) => { + connection.write("hello world"); setTimeout(() => { connection.close(); @@ -56,16 +56,16 @@ describe('SockJSClient', () => { const data = []; client.onOpen(() => { - data.push('open'); + data.push("open"); }); client.onClose(() => { - data.push('close'); + data.push("close"); }); client.onMessage((msg) => { data.push(msg); }); - const testError = new Error('test'); + const testError = new Error("test"); client.sock.onerror(testError); diff --git a/test/client/clients/WebsocketClient.test.js b/test/client/clients/WebsocketClient.test.js index 17f377afe7..f9cb5d5988 100644 --- a/test/client/clients/WebsocketClient.test.js +++ b/test/client/clients/WebsocketClient.test.js @@ -2,22 +2,22 @@ * @jest-environment jsdom */ -'use strict'; +"use strict"; -const http = require('http'); -const express = require('express'); -const ws = require('ws'); -const port = require('../../ports-map')['web-socket-client']; +const http = require("http"); +const express = require("express"); +const ws = require("ws"); +const port = require("../../ports-map")["web-socket-client"]; -jest.setMock('../../../client-src/utils/log', { +jest.setMock("../../../client-src/utils/log", { log: { error: jest.fn(), }, }); -describe('WebsocketClient', () => { - const WebsocketClient = require('../../../client-src/clients/WebsocketClient'); - const { log } = require('../../../client-src/utils/log'); +describe("WebsocketClient", () => { + const WebsocketClient = require("../../../client-src/clients/WebsocketClient"); + const { log } = require("../../../client-src/utils/log"); let socketServer; let server; @@ -27,19 +27,19 @@ describe('WebsocketClient', () => { const app = new express(); server = http.createServer(app); - server.listen(port, 'localhost', () => { + server.listen(port, "localhost", () => { socketServer = new ws.Server({ server, - path: '/ws-server', + path: "/ws-server", }); done(); }); }); - describe('client', () => { - it('should open, receive message, and close', (done) => { - socketServer.on('connection', (connection) => { - connection.send('hello world'); + describe("client", () => { + it("should open, receive message, and close", (done) => { + socketServer.on("connection", (connection) => { + connection.send("hello world"); setTimeout(() => { connection.close(); @@ -50,16 +50,16 @@ describe('WebsocketClient', () => { const data = []; client.onOpen(() => { - data.push('open'); + data.push("open"); }); client.onClose(() => { - data.push('close'); + data.push("close"); }); client.onMessage((msg) => { data.push(msg); }); - const testError = new Error('test'); + const testError = new Error("test"); client.client.onerror(testError); diff --git a/test/client/index.test.js b/test/client/index.test.js index 0bc0a5494c..f8837b1edd 100644 --- a/test/client/index.test.js +++ b/test/client/index.test.js @@ -2,9 +2,9 @@ * @jest-environment jsdom */ -'use strict'; +"use strict"; -describe('index', () => { +describe("index", () => { let log; let socket; let overlay; @@ -15,10 +15,10 @@ describe('index', () => { const resourceQueryValue = global.__resourceQuery; beforeEach(() => { - global.__resourceQuery = 'foo'; + global.__resourceQuery = "foo"; // log - jest.setMock('../../client-src/utils/log.js', { + jest.setMock("../../client-src/utils/log.js", { log: { info: jest.fn(), warn: jest.fn(), @@ -26,40 +26,40 @@ describe('index', () => { }, setLogLevel: jest.fn(), }); - jest.setMock('strip-ansi', { - default: require('strip-ansi-v6'), + jest.setMock("strip-ansi", { + default: require("strip-ansi-v6"), }); - log = require('../../client-src/utils/log'); + log = require("../../client-src/utils/log"); // socket - jest.setMock('../../client-src/socket.js', jest.fn()); - socket = require('../../client-src/socket'); + jest.setMock("../../client-src/socket.js", jest.fn()); + socket = require("../../client-src/socket"); // overlay - jest.setMock('../../client-src/overlay.js', { + jest.setMock("../../client-src/overlay.js", { hide: jest.fn(), show: jest.fn(), }); - overlay = require('../../client-src/overlay'); + overlay = require("../../client-src/overlay"); // reloadApp - jest.setMock('../../client-src/utils/reloadApp.js', jest.fn()); - reloadApp = require('../../client-src/utils/reloadApp'); + jest.setMock("../../client-src/utils/reloadApp.js", jest.fn()); + reloadApp = require("../../client-src/utils/reloadApp"); // sendMessage - jest.setMock('../../client-src/utils/sendMessage.js', jest.fn()); - sendMessage = require('../../client-src/utils/sendMessage'); + jest.setMock("../../client-src/utils/sendMessage.js", jest.fn()); + sendMessage = require("../../client-src/utils/sendMessage"); // getUrlOptions - jest.setMock('../../client-src/utils/parseURL.js', () => { + jest.setMock("../../client-src/utils/parseURL.js", () => { return { - logging: 'info', + logging: "info", }; }); // createSocketUrl - jest.setMock('../../client-src/utils/createSocketURL.js', () => 'mock-url'); + jest.setMock("../../client-src/utils/createSocketURL.js", () => "mock-url"); // issue: https://github.com/jsdom/jsdom/issues/2112 delete window.location; @@ -68,7 +68,7 @@ describe('index', () => { reload: jest.fn(), }; - require('../../client-src'); + require("../../client-src"); onSocketMessage = socket.mock.calls[0][1]; }); @@ -79,69 +79,69 @@ describe('index', () => { jest.resetModules(); }); - test('should set arguments into socket function', () => { + test("should set arguments into socket function", () => { expect(socket.mock.calls[0]).toMatchSnapshot(); }); - test('should run onSocketMessage.hot', () => { + test("should run onSocketMessage.hot", () => { onSocketMessage.hot(); expect(log.log.info.mock.calls[0][0]).toMatchSnapshot(); }); - test('should run onSocketMessage.liveReload', () => { + test("should run onSocketMessage.liveReload", () => { onSocketMessage.liveReload(); expect(log.log.info.mock.calls[0][0]).toMatchSnapshot(); }); test("should run onSocketMessage['still-ok']", () => { - onSocketMessage['still-ok'](); + onSocketMessage["still-ok"](); expect(log.log.info.mock.calls[0][0]).toMatchSnapshot(); expect(sendMessage.mock.calls[0][0]).toMatchSnapshot(); expect(overlay.hide).not.toBeCalled(); // change flags onSocketMessage.overlay(true); - onSocketMessage['still-ok'](); + onSocketMessage["still-ok"](); expect(overlay.hide).toBeCalled(); }); test("should run onSocketMessage.progress and onSocketMessage['progress-update']", () => { onSocketMessage.progress(false); - onSocketMessage['progress-update']({ - msg: 'mock-msg', - percent: '12', + onSocketMessage["progress-update"]({ + msg: "mock-msg", + percent: "12", }); expect(log.log.info).not.toBeCalled(); expect(sendMessage.mock.calls[0][0]).toMatchSnapshot(); onSocketMessage.progress(true); - onSocketMessage['progress-update']({ - msg: 'mock-msg', - percent: '12', + onSocketMessage["progress-update"]({ + msg: "mock-msg", + percent: "12", }); expect(log.log.info.mock.calls[0][0]).toMatchSnapshot(); }); test("should run onSocketMessage.progress and onSocketMessage['progress-update'] and log plugin name", () => { onSocketMessage.progress(false); - onSocketMessage['progress-update']({ - msg: 'mock-msg', - percent: '12', - pluginName: 'mock-plugin', + onSocketMessage["progress-update"]({ + msg: "mock-msg", + percent: "12", + pluginName: "mock-plugin", }); expect(log.log.info).not.toBeCalled(); expect(sendMessage.mock.calls[0][0]).toMatchSnapshot(); onSocketMessage.progress(true); - onSocketMessage['progress-update']({ - msg: 'mock-msg', - percent: '12', - pluginName: 'mock-plugin', + onSocketMessage["progress-update"]({ + msg: "mock-msg", + percent: "12", + pluginName: "mock-plugin", }); expect(log.log.info.mock.calls[0][0]).toMatchSnapshot(); }); - test('should run onSocketMessage.ok', () => { + test("should run onSocketMessage.ok", () => { { const res = onSocketMessage.ok(); expect(sendMessage.mock.calls[0][0]).toMatchSnapshot(); @@ -151,7 +151,7 @@ describe('index', () => { // change flags { onSocketMessage.errors([]); - onSocketMessage.hash('mock-hash'); + onSocketMessage.hash("mock-hash"); const res = onSocketMessage.ok(); expect(reloadApp).toBeCalled(); @@ -162,39 +162,39 @@ describe('index', () => { }); test("should run onSocketMessage['content-changed']", () => { - onSocketMessage['content-changed'](); + onSocketMessage["content-changed"](); expect(log.log.info.mock.calls[0][0]).toMatchSnapshot(); expect(self.location.reload).toBeCalled(); }); test("should run onSocketMessage['content-changed'](file)", () => { - onSocketMessage['content-changed']('/public/assets/index.html'); + onSocketMessage["content-changed"]("/public/assets/index.html"); expect(log.log.info.mock.calls[0][0]).toMatchSnapshot(); expect(self.location.reload).toBeCalled(); }); test("should run onSocketMessage['static-changed']", () => { - onSocketMessage['static-changed'](); + onSocketMessage["static-changed"](); expect(log.log.info.mock.calls[0][0]).toMatchSnapshot(); expect(self.location.reload).toBeCalled(); }); test("should run onSocketMessage['static-changed'](file)", () => { - onSocketMessage['static-changed']('/static/assets/index.html'); + onSocketMessage["static-changed"]("/static/assets/index.html"); expect(log.log.info.mock.calls[0][0]).toMatchSnapshot(); expect(self.location.reload).toBeCalled(); }); - test('should run onSocketMessage.warnings', () => { + test("should run onSocketMessage.warnings", () => { { const res = onSocketMessage.warnings([ - 'warn1', - '\u001B[4mwarn2\u001B[0m', - 'warn3', + "warn1", + "\u001B[4mwarn2\u001B[0m", + "warn3", ]); expect(res).toEqual(false); @@ -217,18 +217,18 @@ describe('index', () => { } }); - test('should run onSocketMessage.error', () => { - onSocketMessage.error('error!!'); + test("should run onSocketMessage.error", () => { + onSocketMessage.error("error!!"); expect(log.log.error.mock.calls[0][0]).toMatchSnapshot(); }); - test('should run onSocketMessage.close', () => { + test("should run onSocketMessage.close", () => { onSocketMessage.close(); expect(log.log.error.mock.calls[0][0]).toMatchSnapshot(); expect(sendMessage.mock.calls[0][0]).toMatchSnapshot(); }); - test('should run onSocketMessage.close (hot enabled)', () => { + test("should run onSocketMessage.close (hot enabled)", () => { // enabling hot onSocketMessage.hot(); onSocketMessage.close(); @@ -236,7 +236,7 @@ describe('index', () => { expect(sendMessage.mock.calls[0][0]).toMatchSnapshot(); }); - test('should run onSocketMessage.close (liveReload enabled)', () => { + test("should run onSocketMessage.close (liveReload enabled)", () => { // enabling liveReload onSocketMessage.liveReload(); onSocketMessage.close(); @@ -244,7 +244,7 @@ describe('index', () => { expect(sendMessage.mock.calls[0][0]).toMatchSnapshot(); }); - test('should update log level if options is passed', () => { + test("should update log level if options is passed", () => { expect(log.setLogLevel.mock.calls[0][0]).toMatchSnapshot(); }); }); diff --git a/test/client/socket-helper.test.js b/test/client/socket-helper.test.js index 41e0084a4d..66a4c9d9f7 100644 --- a/test/client/socket-helper.test.js +++ b/test/client/socket-helper.test.js @@ -2,22 +2,22 @@ * @jest-environment jsdom */ -'use strict'; +"use strict"; -describe('socket', () => { +describe("socket", () => { afterEach(() => { jest.resetAllMocks(); jest.resetModules(); }); - it('should default to WebsocketClient when no __webpack_dev_server_client__ set', () => { - jest.mock('../../client/clients/WebsocketClient'); - const socket = require('../../client/socket'); - const WebsocketClient = require('../../client/clients/WebsocketClient'); + it("should default to WebsocketClient when no __webpack_dev_server_client__ set", () => { + jest.mock("../../client/clients/WebsocketClient"); + const socket = require("../../client/socket"); + const WebsocketClient = require("../../client/clients/WebsocketClient"); const mockHandler = jest.fn(); - socket('my.url', { + socket("my.url", { example: mockHandler, }); @@ -27,8 +27,8 @@ describe('socket', () => { // along to the callback of onMessage mockClientInstance.onMessage.mock.calls[0][0]( JSON.stringify({ - type: 'example', - data: 'hello world', + type: "example", + data: "hello world", }) ); @@ -39,13 +39,13 @@ describe('socket', () => { expect(mockHandler.mock.calls).toMatchSnapshot(); }); - it('should use __webpack_dev_server_client__ when set', () => { - jest.mock('../../client/clients/WebsocketClient'); - const socket = require('../../client/socket'); - global.__webpack_dev_server_client__ = require('../../client/clients/WebsocketClient'); + it("should use __webpack_dev_server_client__ when set", () => { + jest.mock("../../client/clients/WebsocketClient"); + const socket = require("../../client/socket"); + global.__webpack_dev_server_client__ = require("../../client/clients/WebsocketClient"); const mockHandler = jest.fn(); - socket('my.url', { + socket("my.url", { example: mockHandler, }); @@ -56,8 +56,8 @@ describe('socket', () => { // along to the callback of onMessage mockClientInstance.onMessage.mock.calls[0][0]( JSON.stringify({ - type: 'example', - data: 'hello world', + type: "example", + data: "hello world", }) ); diff --git a/test/client/utils/createSocketURL.test.js b/test/client/utils/createSocketURL.test.js index 035f43e155..33bd7b2d5b 100644 --- a/test/client/utils/createSocketURL.test.js +++ b/test/client/utils/createSocketURL.test.js @@ -2,114 +2,114 @@ * @jest-environment jsdom */ -'use strict'; +"use strict"; describe("'createSocketURL' function ", () => { const samples = [ // __resourceQuery, location and socket URL [ - '?hostname=example.com&pathname=/ws', - 'http://example.com', - 'ws://example.com/ws', + "?hostname=example.com&pathname=/ws", + "http://example.com", + "ws://example.com/ws", ], - ['?protocol=auto:', 'http://example.com', 'ws://example.com/ws'], - ['?protocol=auto:', 'https://example.com', 'wss://example.com/ws'], - ['?protocol=wss:', 'http://example.com', 'wss://example.com/ws'], - ['?protocol=https:', 'https://example.com', 'wss://example.com/ws'], - ['?protocol=http:', 'https://example.com', 'ws://example.com/ws'], - ['?hostname=example.com', 'http://example.com', 'ws://example.com/ws'], + ["?protocol=auto:", "http://example.com", "ws://example.com/ws"], + ["?protocol=auto:", "https://example.com", "wss://example.com/ws"], + ["?protocol=wss:", "http://example.com", "wss://example.com/ws"], + ["?protocol=https:", "https://example.com", "wss://example.com/ws"], + ["?protocol=http:", "https://example.com", "ws://example.com/ws"], + ["?hostname=example.com", "http://example.com", "ws://example.com/ws"], [ - '?username=username&password=password', - 'http://example.com', - 'ws://username:password@example.com/ws', + "?username=username&password=password", + "http://example.com", + "ws://username:password@example.com/ws", ], [ - '?hostname=example.com&port=80', - 'http://example.com', - 'ws://example.com:80/ws', + "?hostname=example.com&port=80", + "http://example.com", + "ws://example.com:80/ws", ], - ['?port=0', 'http://example.com:8080', 'ws://example.com:8080/ws'], - ['?port=80', 'http://example.com:8080', 'ws://example.com:80/ws'], - ['?hostname=0.0.0.0', 'http://127.0.0.1', 'ws://127.0.0.1/ws'], - ['?hostname=0.0.0.0', 'http://192.168.0.1', 'ws://192.168.0.1/ws'], - ['?hostname=0.0.0.0', 'https://192.168.0.1', 'wss://192.168.0.1/ws'], - ['?hostname=0.0.0.0', 'https://example.com', 'wss://example.com/ws'], + ["?port=0", "http://example.com:8080", "ws://example.com:8080/ws"], + ["?port=80", "http://example.com:8080", "ws://example.com:80/ws"], + ["?hostname=0.0.0.0", "http://127.0.0.1", "ws://127.0.0.1/ws"], + ["?hostname=0.0.0.0", "http://192.168.0.1", "ws://192.168.0.1/ws"], + ["?hostname=0.0.0.0", "https://192.168.0.1", "wss://192.168.0.1/ws"], + ["?hostname=0.0.0.0", "https://example.com", "wss://example.com/ws"], [ - '?hostname=0.0.0.0', - 'http://example.com:8080', - 'ws://example.com:8080/ws', + "?hostname=0.0.0.0", + "http://example.com:8080", + "ws://example.com:8080/ws", ], [ - '?hostname=0.0.0.0', - 'http://example.com:8080', - 'ws://example.com:8080/ws', + "?hostname=0.0.0.0", + "http://example.com:8080", + "ws://example.com:8080/ws", ], [ - '?hostname=0.0.0.0', - 'https://example.com:8080', - 'wss://example.com:8080/ws', + "?hostname=0.0.0.0", + "https://example.com:8080", + "wss://example.com:8080/ws", ], - ['?hostname=::', 'http://example.com:8080', 'ws://example.com:8080/ws'], - ['?hostname=[::]', 'http://example.com:8080', 'ws://example.com:8080/ws'], - ['?hostname=[::]', 'http://example.com:8080', 'ws://example.com:8080/ws'], + ["?hostname=::", "http://example.com:8080", "ws://example.com:8080/ws"], + ["?hostname=[::]", "http://example.com:8080", "ws://example.com:8080/ws"], + ["?hostname=[::]", "http://example.com:8080", "ws://example.com:8080/ws"], - ['?hostname=%3A%3A', 'http://example.com:8080', 'ws://example.com:8080/ws'], - ['?hostname=%3A%3A1', 'http://example.com:8080', 'ws://[::1]:8080/ws'], - ['?hostname=%3A%3A1', 'https://example.com:8080', 'ws://[::1]:8080/ws'], + ["?hostname=%3A%3A", "http://example.com:8080", "ws://example.com:8080/ws"], + ["?hostname=%3A%3A1", "http://example.com:8080", "ws://[::1]:8080/ws"], + ["?hostname=%3A%3A1", "https://example.com:8080", "ws://[::1]:8080/ws"], [ - '?hostname=%3A%3A', - 'https://example.com:8080', - 'wss://example.com:8080/ws', + "?hostname=%3A%3A", + "https://example.com:8080", + "wss://example.com:8080/ws", ], [ - '?hostname=%3A%3A', - 'https://example.com:8080', - 'wss://example.com:8080/ws', + "?hostname=%3A%3A", + "https://example.com:8080", + "wss://example.com:8080/ws", ], [ - '?pathname=/custom-ws', - 'http://example.com', - 'ws://example.com/custom-ws', + "?pathname=/custom-ws", + "http://example.com", + "ws://example.com/custom-ws", ], [ - '?protocol=wss:&username=user&password=password&hostname=localhost&port=8080&pathname=/ws', - 'http://user:password@localhost/', - 'wss://user:password@localhost:8080/ws', + "?protocol=wss:&username=user&password=password&hostname=localhost&port=8080&pathname=/ws", + "http://user:password@localhost/", + "wss://user:password@localhost:8080/ws", ], - [null, 'http://example.com', 'ws://example.com/ws'], - [null, 'https://example.com', 'wss://example.com/ws'], - [null, 'http://example.com:8080', 'ws://example.com:8080/ws'], - [null, 'http://example.com/foo/bar', 'ws://example.com/ws'], + [null, "http://example.com", "ws://example.com/ws"], + [null, "https://example.com", "wss://example.com/ws"], + [null, "http://example.com:8080", "ws://example.com:8080/ws"], + [null, "http://example.com/foo/bar", "ws://example.com/ws"], [ null, - 'http://user:password@localhost/', - 'ws://user:password@localhost/ws', + "http://user:password@localhost/", + "ws://user:password@localhost/ws", ], - [null, 'http://user@localhost:8080/', 'ws://user@localhost:8080/ws'], + [null, "http://user@localhost:8080/", "ws://user@localhost:8080/ws"], [ null, - 'http://user:password@localhost:8080/', - 'ws://user:password@localhost:8080/ws', + "http://user:password@localhost:8080/", + "ws://user:password@localhost:8080/ws", ], - [null, 'https://localhost:8080', 'wss://localhost:8080/ws'], - [null, 'http://127.0.0.1', 'ws://127.0.0.1/ws'], - [null, 'http://127.0.0.1:8080', 'ws://127.0.0.1:8080/ws'], - [null, 'https://127.0.0.1', 'wss://127.0.0.1/ws'], - [null, 'http://[::1]:8080/ws', 'ws://[::1]:8080/ws'], - [null, 'https://[::1]:8080/ws', 'wss://[::1]:8080/ws'], - [null, 'file:///home/user/project/index.html', 'ws://localhost/ws'], - [null, 'chrome-extension://localhost/', 'ws://localhost/ws'], - [null, 'file://localhost/', 'ws://localhost/ws'], + [null, "https://localhost:8080", "wss://localhost:8080/ws"], + [null, "http://127.0.0.1", "ws://127.0.0.1/ws"], + [null, "http://127.0.0.1:8080", "ws://127.0.0.1:8080/ws"], + [null, "https://127.0.0.1", "wss://127.0.0.1/ws"], + [null, "http://[::1]:8080/ws", "ws://[::1]:8080/ws"], + [null, "https://[::1]:8080/ws", "wss://[::1]:8080/ws"], + [null, "file:///home/user/project/index.html", "ws://localhost/ws"], + [null, "chrome-extension://localhost/", "ws://localhost/ws"], + [null, "file://localhost/", "ws://localhost/ws"], ]; samples.forEach(([__resourceQuery, location, expected]) => { jest.doMock( - '../../../client-src/utils/getCurrentScriptSource', - () => () => new URL('./entry.js', location).toString() + "../../../client-src/utils/getCurrentScriptSource", + () => () => new URL("./entry.js", location).toString() ); - const createSocketURL = require('../../../client-src/utils/createSocketURL'); - const parseURL = require('../../../client-src/utils/parseURL'); + const createSocketURL = require("../../../client-src/utils/createSocketURL"); + const parseURL = require("../../../client-src/utils/parseURL"); test(`should return '${expected}' socket URL when '__resourceQuery' is '${__resourceQuery}' and 'self.location' is '${location}'`, () => { const selfLocation = new URL(location); diff --git a/test/client/utils/getCurrentScriptSource.test.js b/test/client/utils/getCurrentScriptSource.test.js index 8a1016f65a..a341d1b566 100644 --- a/test/client/utils/getCurrentScriptSource.test.js +++ b/test/client/utils/getCurrentScriptSource.test.js @@ -2,18 +2,18 @@ * @jest-environment jsdom */ -'use strict'; +"use strict"; -const getCurrentScriptSource = require('../../../client-src/utils/getCurrentScriptSource'); +const getCurrentScriptSource = require("../../../client-src/utils/getCurrentScriptSource"); describe("'getCurrentScriptSource' function", () => { afterEach(() => { - Object.defineProperty(document, 'currentScript', { + Object.defineProperty(document, "currentScript", { // eslint-disable-next-line no-undefined value: undefined, writable: true, }); - Object.defineProperty(document, 'scripts', { + Object.defineProperty(document, "scripts", { value: [], writable: true, }); @@ -28,19 +28,19 @@ describe("'getCurrentScriptSource' function", () => { }); test("should return src when 'document.currentScript' exists", () => { - const elm = document.createElement('script'); + const elm = document.createElement("script"); - elm.setAttribute('src', 'foo'); + elm.setAttribute("src", "foo"); - Object.defineProperty(document, 'currentScript', { + Object.defineProperty(document, "currentScript", { value: elm, }); - expect(getCurrentScriptSource()).toEqual('foo'); + expect(getCurrentScriptSource()).toEqual("foo"); }); test("should fail when 'document.scripts' doesn't exist and no scripts", () => { - Object.defineProperty(document, 'scripts', { + Object.defineProperty(document, "scripts", { // eslint-disable-next-line no-undefined value: undefined, writable: true, @@ -54,25 +54,25 @@ describe("'getCurrentScriptSource' function", () => { }); test("should return the 'src' attribute of the last 'script' tag", () => { - const elements = ['foo', 'bar'].map((src) => { - const element = document.createElement('script'); + const elements = ["foo", "bar"].map((src) => { + const element = document.createElement("script"); - element.setAttribute('src', src); + element.setAttribute("src", src); return element; }); - Object.defineProperty(document, 'scripts', { + Object.defineProperty(document, "scripts", { value: elements, }); - expect(getCurrentScriptSource()).toEqual('bar'); + expect(getCurrentScriptSource()).toEqual("bar"); }); test("should fail when no scripts with the 'scr' attribute", () => { - const elements = ['foo', 'bar'].map(() => document.createElement('script')); + const elements = ["foo", "bar"].map(() => document.createElement("script")); - Object.defineProperty(document, 'scripts', { + Object.defineProperty(document, "scripts", { value: elements, }); diff --git a/test/client/utils/log.test.js b/test/client/utils/log.test.js index eda1c471f0..8ca0ff433c 100644 --- a/test/client/utils/log.test.js +++ b/test/client/utils/log.test.js @@ -2,20 +2,20 @@ * @jest-environment jsdom */ -'use strict'; +"use strict"; describe("'log' function", () => { let logMock; let setLogLevel; beforeEach(() => { - jest.setMock('webpack/lib/logging/runtime', { + jest.setMock("webpack/lib/logging/runtime", { getLogger: jest.fn(), configureDefaultLogger: jest.fn(), }); - logMock = require('webpack/lib/logging/runtime'); + logMock = require("webpack/lib/logging/runtime"); - setLogLevel = require('../../../client-src/utils/log').setLogLevel; + setLogLevel = require("../../../client-src/utils/log").setLogLevel; }); afterEach(() => { @@ -23,21 +23,21 @@ describe("'log' function", () => { logMock.configureDefaultLogger.mockClear(); }); - test('should set info as the default level and create logger', () => { + test("should set info as the default level and create logger", () => { const getLogger = logMock.getLogger; const configureDefaultLogger = logMock.configureDefaultLogger; expect(configureDefaultLogger).toBeCalled(); expect(configureDefaultLogger.mock.calls[0][0]).toEqual({ - level: 'info', + level: "info", }); expect(getLogger).toBeCalled(); - expect(getLogger.mock.calls[0][0]).toEqual('webpack-dev-server'); + expect(getLogger.mock.calls[0][0]).toEqual("webpack-dev-server"); }); - test('should set log level via setLogLevel', () => { - ['none', 'error', 'warn', 'info', 'log', 'verbose'].forEach((level) => { + test("should set log level via setLogLevel", () => { + ["none", "error", "warn", "info", "log", "verbose"].forEach((level) => { setLogLevel(level); }); diff --git a/test/client/utils/reloadApp.test.js b/test/client/utils/reloadApp.test.js index 9dd5344ee0..dc1e433d44 100644 --- a/test/client/utils/reloadApp.test.js +++ b/test/client/utils/reloadApp.test.js @@ -2,7 +2,7 @@ * @jest-environment jsdom */ -'use strict'; +"use strict"; describe("'reloadApp' function", () => { let reloadApp; @@ -14,20 +14,20 @@ describe("'reloadApp' function", () => { self.postMessage = jest.fn(); - Object.defineProperty(window, 'location', { - value: { reload: jest.fn(), search: '' }, + Object.defineProperty(window, "location", { + value: { reload: jest.fn(), search: "" }, }); - jest.mock('webpack/lib/logging/runtime'); + jest.mock("webpack/lib/logging/runtime"); - log = require('webpack/lib/logging/runtime'); + log = require("webpack/lib/logging/runtime"); log.getLogger.mockImplementation(() => { return { info: jest.fn(), }; }); - reloadApp = require('../../../client-src/utils/reloadApp'); + reloadApp = require("../../../client-src/utils/reloadApp"); }); afterEach(() => { @@ -36,7 +36,7 @@ describe("'reloadApp' function", () => { jest.resetModules(); }); - test('should do nothing when isUnloading is true or hotReload is false', () => { + test("should do nothing when isUnloading is true or hotReload is false", () => { // eslint-disable-next-line no-undefined expect(reloadApp({}, { isUnloading: false })).toEqual(undefined); expect(log.getLogger.mock.results[0].value.info).not.toBeCalled(); @@ -47,14 +47,14 @@ describe("'reloadApp' function", () => { expect(log.getLogger.mock.results[0].value.info).not.toBeCalled(); }); - test('should run hot', () => { - jest.mock('webpack/hot/emitter'); - const emitter = require('webpack/hot/emitter'); + test("should run hot", () => { + jest.mock("webpack/hot/emitter"); + const emitter = require("webpack/hot/emitter"); emitter.emit = jest.fn(); reloadApp( { hot: true, hotReload: true }, - { isUnloading: false, currentHash: 'hash' } + { isUnloading: false, currentHash: "hash" } ); expect( @@ -64,11 +64,11 @@ describe("'reloadApp' function", () => { expect(self.postMessage.mock.calls[0]).toMatchSnapshot(); }); - test('should run liveReload when protocol is about:', (done) => { - Object.defineProperty(self, 'location', { + test("should run liveReload when protocol is about:", (done) => { + Object.defineProperty(self, "location", { value: { ...self.location, - protocol: 'about:', + protocol: "about:", }, }); @@ -86,7 +86,7 @@ describe("'reloadApp' function", () => { }); }); - test('should run liveReload when protocol is http:', (done) => { + test("should run liveReload when protocol is http:", (done) => { reloadApp( { hot: false, hotReload: true, liveReload: true }, { isUnloading: false } diff --git a/test/client/utils/sendMessage.test.js b/test/client/utils/sendMessage.test.js index 9dee503cc9..e4aec761ed 100644 --- a/test/client/utils/sendMessage.test.js +++ b/test/client/utils/sendMessage.test.js @@ -2,19 +2,19 @@ * @jest-environment jsdom */ -'use strict'; +"use strict"; -const sendMessage = require('../../../client-src/utils/sendMessage'); +const sendMessage = require("../../../client-src/utils/sendMessage"); describe("'sendMessage' function", () => { afterEach(() => { jest.resetAllMocks(); }); - test('should run self.postMessage', () => { + test("should run self.postMessage", () => { self.postMessage = jest.fn(); - sendMessage('foo', 'bar'); + sendMessage("foo", "bar"); expect(self.postMessage).toBeCalled(); expect(self.postMessage.mock.calls[0]).toMatchSnapshot(); diff --git a/test/e2e/entry.test.js b/test/e2e/entry.test.js index 79244e90d3..bf925363de 100644 --- a/test/e2e/entry.test.js +++ b/test/e2e/entry.test.js @@ -1,17 +1,17 @@ -'use strict'; +"use strict"; -const path = require('path'); -const webpack = require('webpack'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/client-config/webpack.config'); -const runBrowser = require('../helpers/run-browser'); -const port = require('../ports-map').entry; -const isWebpack5 = require('../helpers/isWebpack5'); +const path = require("path"); +const webpack = require("webpack"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/client-config/webpack.config"); +const runBrowser = require("../helpers/run-browser"); +const port = require("../ports-map").entry; +const isWebpack5 = require("../helpers/isWebpack5"); const HOT_ENABLED_MESSAGE = - '[webpack-dev-server] Hot Module Replacement enabled.'; + "[webpack-dev-server] Hot Module Replacement enabled."; const LIVE_RELOAD_ENABLED_MESSAGE = - '[webpack-dev-server] Hot Module Replacement enabled.'; + "[webpack-dev-server] Hot Module Replacement enabled."; const waitForConsoleLogFinished = async (consoleLogs) => { await new Promise((resolve) => { @@ -28,28 +28,28 @@ const waitForConsoleLogFinished = async (consoleLogs) => { }); }; -describe('entry', () => { +describe("entry", () => { const entryFirst = path.resolve( __dirname, - '../fixtures/client-config/foo.js' + "../fixtures/client-config/foo.js" ); const entrySecond = path.resolve( __dirname, - '../fixtures/client-config/bar.js' + "../fixtures/client-config/bar.js" ); const itOnlyWebpack5 = isWebpack5 ? it : it.skip; - it('should work with single entry', async () => { + it("should work with single entry", async () => { const compiler = webpack({ ...config, entry: entryFirst }); const devServerOptions = { - host: '127.0.0.1', + host: "127.0.0.1", port, }; const server = new Server(devServerOptions, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -66,21 +66,21 @@ describe('entry', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); await page.goto(`http://127.0.0.1:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -96,16 +96,16 @@ describe('entry', () => { }); }); - it('should work with single array entry', async () => { + it("should work with single array entry", async () => { const compiler = webpack({ ...config, entry: [entryFirst, entrySecond] }); const devServerOptions = { - host: '127.0.0.1', + host: "127.0.0.1", port, }; const server = new Server(devServerOptions, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -122,21 +122,21 @@ describe('entry', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); await page.goto(`http://127.0.0.1:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -152,7 +152,7 @@ describe('entry', () => { }); }); - itOnlyWebpack5('should work with object entry', async () => { + itOnlyWebpack5("should work with object entry", async () => { const compiler = webpack({ ...config, entry: { @@ -160,13 +160,13 @@ describe('entry', () => { }, }); const devServerOptions = { - host: '127.0.0.1', + host: "127.0.0.1", port, }; const server = new Server(devServerOptions, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -183,21 +183,21 @@ describe('entry', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); await page.goto(`http://127.0.0.1:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -213,16 +213,16 @@ describe('entry', () => { }); }); - it('should work with dynamic entry', async () => { + it("should work with dynamic entry", async () => { const compiler = webpack({ ...config, entry: () => entryFirst }); const devServerOptions = { - host: '127.0.0.1', + host: "127.0.0.1", port, }; const server = new Server(devServerOptions, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -239,21 +239,21 @@ describe('entry', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); await page.goto(`http://127.0.0.1:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -269,19 +269,19 @@ describe('entry', () => { }); }); - it('should work with dynamic async entry', async () => { + it("should work with dynamic async entry", async () => { const compiler = webpack({ ...config, entry: () => new Promise((resolve) => resolve([entryFirst])), }); const devServerOptions = { - host: '127.0.0.1', + host: "127.0.0.1", port, }; const server = new Server(devServerOptions, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -298,21 +298,21 @@ describe('entry', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); await page.goto(`http://127.0.0.1:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -328,7 +328,7 @@ describe('entry', () => { }); }); - it('should work with multiple entries', async () => { + it("should work with multiple entries", async () => { const compiler = webpack({ ...config, entry: { @@ -337,18 +337,18 @@ describe('entry', () => { }, optimization: { runtimeChunk: { - name: 'runtime', + name: "runtime", }, }, }); const devServerOptions = { - host: '127.0.0.1', + host: "127.0.0.1", port, }; const server = new Server(devServerOptions, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -365,22 +365,22 @@ describe('entry', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message.text()); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); await page.goto(`http://127.0.0.1:${port}/test.html`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); await page.addScriptTag({ url: `http://127.0.0.1:${port}/runtime.js` }); await page.addScriptTag({ url: `http://127.0.0.1:${port}/foo.js` }); await waitForConsoleLogFinished(consoleMessages); - expect(consoleMessages).toMatchSnapshot('console messages'); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(consoleMessages).toMatchSnapshot("console messages"); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -396,7 +396,7 @@ describe('entry', () => { }); }); - it('should work with multiple entries #2', async () => { + it("should work with multiple entries #2", async () => { const compiler = webpack({ ...config, entry: { @@ -405,18 +405,18 @@ describe('entry', () => { }, optimization: { runtimeChunk: { - name: 'runtime', + name: "runtime", }, }, }); const devServerOptions = { - host: '127.0.0.1', + host: "127.0.0.1", port, }; const server = new Server(devServerOptions, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -432,22 +432,22 @@ describe('entry', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message.text()); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); await page.goto(`http://127.0.0.1:${port}/test.html`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); await page.addScriptTag({ url: `http://127.0.0.1:${port}/runtime.js` }); await page.addScriptTag({ url: `http://127.0.0.1:${port}/bar.js` }); await waitForConsoleLogFinished(consoleMessages); - expect(consoleMessages).toMatchSnapshot('console messages'); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(consoleMessages).toMatchSnapshot("console messages"); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -471,19 +471,19 @@ describe('entry', () => { entry: { foo: { import: entryFirst, - dependOn: 'bar', + dependOn: "bar", }, bar: entrySecond, }, }); const devServerOptions = { - host: '127.0.0.1', + host: "127.0.0.1", port, }; const server = new Server(devServerOptions, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -500,22 +500,22 @@ describe('entry', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message.text()); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); await page.goto(`http://127.0.0.1:${port}/test.html`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); await page.addScriptTag({ url: `http://127.0.0.1:${port}/bar.js` }); await page.addScriptTag({ url: `http://127.0.0.1:${port}/foo.js` }); await waitForConsoleLogFinished(consoleMessages); - expect(consoleMessages).toMatchSnapshot('console messages'); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(consoleMessages).toMatchSnapshot("console messages"); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -532,7 +532,7 @@ describe('entry', () => { } ); - itOnlyWebpack5('should work with empty', async () => { + itOnlyWebpack5("should work with empty", async () => { const compiler = webpack({ ...config, entry: {}, @@ -540,17 +540,17 @@ describe('entry', () => { new webpack.EntryPlugin(compiler.context, entryFirst, { // eslint-disable-next-line no-undefined - name: 'main', + name: "main", }).apply(compiler); const devServerOptions = { - host: '127.0.0.1', + host: "127.0.0.1", port, }; const server = new Server(devServerOptions, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -567,21 +567,21 @@ describe('entry', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); await page.goto(`http://127.0.0.1:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { diff --git a/test/e2e/hot-and-live-reload.test.js b/test/e2e/hot-and-live-reload.test.js index 1d3a6681f6..51b23f3928 100644 --- a/test/e2e/hot-and-live-reload.test.js +++ b/test/e2e/hot-and-live-reload.test.js @@ -2,34 +2,34 @@ * @jest-environment node */ -'use strict'; - -const path = require('path'); -const WebSocket = require('ws'); -const SockJS = require('sockjs-client'); -const webpack = require('webpack'); -const request = require('supertest'); -const fs = require('graceful-fs'); -const Server = require('../../lib/Server'); -const reloadConfig = require('../fixtures/reload-config/webpack.config'); -const runBrowser = require('../helpers/run-browser'); -const port = require('../ports-map')['hot-and-live-reload']; +"use strict"; + +const path = require("path"); +const WebSocket = require("ws"); +const SockJS = require("sockjs-client"); +const webpack = require("webpack"); +const request = require("supertest"); +const fs = require("graceful-fs"); +const Server = require("../../lib/Server"); +const reloadConfig = require("../fixtures/reload-config/webpack.config"); +const runBrowser = require("../helpers/run-browser"); +const port = require("../ports-map")["hot-and-live-reload"]; const cssFilePath = path.resolve( __dirname, - '../fixtures/reload-config/main.css' + "../fixtures/reload-config/main.css" ); -const INVALID_MESSAGE = '[webpack-dev-server] App updated. Recompiling...'; +const INVALID_MESSAGE = "[webpack-dev-server] App updated. Recompiling..."; -describe('hot and live reload', () => { +describe("hot and live reload", () => { // "sockjs" client cannot add additional headers const modes = [ { - title: 'should work and refresh content using hot module replacement', + title: "should work and refresh content using hot module replacement", }, { - title: 'should work and do nothing when web socket server disabled', + title: "should work and do nothing when web socket server disabled", options: { webSocketServer: false, }, @@ -37,20 +37,20 @@ describe('hot and live reload', () => { // Default web socket serve ("ws") { title: - 'should work and refresh content using hot module replacement when hot enabled', + "should work and refresh content using hot module replacement when hot enabled", options: { hot: true, }, }, { title: - 'should work and refresh content using hot module replacement when live reload enabled', + "should work and refresh content using hot module replacement when live reload enabled", options: { liveReload: true, }, }, { - title: 'should not refresh content when hot and no live reload disabled', + title: "should not refresh content when hot and no live reload disabled", options: { hot: false, liveReload: false, @@ -58,14 +58,14 @@ describe('hot and live reload', () => { }, { title: - 'should work and refresh content using hot module replacement when live reload disabled and hot enabled', + "should work and refresh content using hot module replacement when live reload disabled and hot enabled", options: { liveReload: false, hot: true, }, }, { - title: 'should work and refresh content using live reload', + title: "should work and refresh content using live reload", options: { liveReload: true, hot: false, @@ -73,7 +73,7 @@ describe('hot and live reload', () => { }, { title: - 'should work and refresh content using hot module replacement when live reload enabled and hot disabled', + "should work and refresh content using hot module replacement when live reload enabled and hot disabled", options: { liveReload: true, hot: true, @@ -82,51 +82,51 @@ describe('hot and live reload', () => { // "ws" web socket serve { title: - 'should work and refresh content using hot module replacement when hot enabled', + "should work and refresh content using hot module replacement when hot enabled", options: { - webSocketServer: 'ws', + webSocketServer: "ws", hot: true, }, }, { title: - 'should work and refresh content using hot module replacement when live reload enabled', + "should work and refresh content using hot module replacement when live reload enabled", options: { - webSocketServer: 'ws', + webSocketServer: "ws", liveReload: true, }, }, { - title: 'should not refresh content when hot and no live reload disabled', + title: "should not refresh content when hot and no live reload disabled", options: { - webSocketServer: 'ws', + webSocketServer: "ws", hot: false, liveReload: false, }, }, { title: - 'should work and refresh content using hot module replacement when live reload disabled and hot enabled', + "should work and refresh content using hot module replacement when live reload disabled and hot enabled", options: { - webSocketServer: 'ws', + webSocketServer: "ws", liveReload: false, hot: true, }, }, { title: - 'should work and refresh content using live reload when live reload enabled and hot disabled', + "should work and refresh content using live reload when live reload enabled and hot disabled", options: { - webSocketServer: 'ws', + webSocketServer: "ws", liveReload: true, hot: false, }, }, { title: - 'should work and refresh content using hot module replacement when live reload and hot enabled', + "should work and refresh content using hot module replacement when live reload and hot enabled", options: { - webSocketServer: 'ws', + webSocketServer: "ws", liveReload: true, hot: true, }, @@ -134,63 +134,63 @@ describe('hot and live reload', () => { // "sockjs" web socket serve { title: - 'should work and refresh content using hot module replacement when hot enabled', + "should work and refresh content using hot module replacement when hot enabled", options: { - allowedHosts: 'all', + allowedHosts: "all", - webSocketServer: 'sockjs', + webSocketServer: "sockjs", hot: true, }, }, { title: - 'should work and refresh content using hot module replacement when live reload enabled', + "should work and refresh content using hot module replacement when live reload enabled", options: { - allowedHosts: 'all', + allowedHosts: "all", - webSocketServer: 'sockjs', + webSocketServer: "sockjs", liveReload: true, }, }, { - title: 'should not refresh content when hot and no live reload disabled', + title: "should not refresh content when hot and no live reload disabled", options: { - allowedHosts: 'all', + allowedHosts: "all", - webSocketServer: 'sockjs', + webSocketServer: "sockjs", hot: false, liveReload: false, }, }, { title: - 'should work and refresh content using hot module replacement when live reload disabled and hot enabled', + "should work and refresh content using hot module replacement when live reload disabled and hot enabled", options: { - allowedHosts: 'all', + allowedHosts: "all", - webSocketServer: 'sockjs', + webSocketServer: "sockjs", liveReload: false, hot: true, }, }, { title: - 'should work and refresh content using live reload when live reload disabled and hot enabled', + "should work and refresh content using live reload when live reload disabled and hot enabled", options: { - allowedHosts: 'all', + allowedHosts: "all", - webSocketServer: 'sockjs', + webSocketServer: "sockjs", liveReload: true, hot: false, }, }, { title: - 'should work and refresh content using hot module replacement when live reload and hot enabled', + "should work and refresh content using hot module replacement when live reload and hot enabled", options: { - allowedHosts: 'all', + allowedHosts: "all", - webSocketServer: 'sockjs', + webSocketServer: "sockjs", liveReload: true, hot: true, }, @@ -198,7 +198,7 @@ describe('hot and live reload', () => { { title: 'should work and allow to disable hot module replacement using the "webpack-dev-server-hot=false"', - query: '?webpack-dev-server-hot=false', + query: "?webpack-dev-server-hot=false", options: { liveReload: true, hot: true, @@ -207,7 +207,7 @@ describe('hot and live reload', () => { { title: 'should work and allow to disable live reload using the "webpack-dev-server-live-reload=false"', - query: '?webpack-dev-server-live-reload=false', + query: "?webpack-dev-server-live-reload=false", options: { liveReload: true, hot: false, @@ -217,18 +217,18 @@ describe('hot and live reload', () => { title: 'should work and allow to disable hot module replacement and live reload using the "webpack-dev-server-hot=false&webpack-dev-server-live-reload=false"', query: - '?webpack-dev-server-hot=false&webpack-dev-server-live-reload=false', + "?webpack-dev-server-hot=false&webpack-dev-server-live-reload=false", options: { liveReload: true, hot: true, }, }, { - title: 'should work with manual client setup', + title: "should work with manual client setup", webpackOptions: { entry: [ - require.resolve('../../client-src/index.js'), - require.resolve('../fixtures/reload-config/foo.js'), + require.resolve("../../client-src/index.js"), + require.resolve("../fixtures/reload-config/foo.js"), ], }, options: { @@ -240,11 +240,11 @@ describe('hot and live reload', () => { // TODO we still output logs from webpack, need to improve this { title: - 'should work with manual client setup and allow to disable hot module replacement', + "should work with manual client setup and allow to disable hot module replacement", webpackOptions: { entry: [ - `${require.resolve('../../client-src/index.js')}?hot=false`, - require.resolve('../fixtures/reload-config/foo.js'), + `${require.resolve("../../client-src/index.js")}?hot=false`, + require.resolve("../fixtures/reload-config/foo.js"), ], }, options: { @@ -255,11 +255,11 @@ describe('hot and live reload', () => { }, { title: - 'should work with manual client setup and allow to disable live reload', + "should work with manual client setup and allow to disable live reload", webpackOptions: { entry: [ - `${require.resolve('../../client-src/index.js')}?live-reload=false`, - require.resolve('../fixtures/reload-config/foo.js'), + `${require.resolve("../../client-src/index.js")}?live-reload=false`, + require.resolve("../fixtures/reload-config/foo.js"), ], }, options: { @@ -274,19 +274,19 @@ describe('hot and live reload', () => { const webSocketServerTitle = mode.options && mode.options.webSocketServer ? mode.options.webSocketServer - : 'default'; + : "default"; it(`${mode.title} (${webSocketServerTitle})`, async () => { fs.writeFileSync( cssFilePath, - 'body { background-color: rgb(0, 0, 255); }' + "body { background-color: rgb(0, 0, 255); }" ); const webpackOptions = { ...reloadConfig, ...mode.webpackOptions }; const compiler = webpack(webpackOptions); const testDevServerOptions = mode.options || {}; const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, ...testDevServerOptions, }; @@ -306,7 +306,7 @@ describe('hot and live reload', () => { await new Promise((resolve, reject) => { request(`http://127.0.0.1:${devServerOptions.port}`) - .get('/main') + .get("/main") .expect(200, (error) => { if (error) { reject(error); @@ -319,11 +319,11 @@ describe('hot and live reload', () => { }); const hot = - typeof testDevServerOptions.hot !== 'undefined' + typeof testDevServerOptions.hot !== "undefined" ? testDevServerOptions.hot : true; const liveReload = - typeof testDevServerOptions.liveReload !== 'undefined' + typeof testDevServerOptions.liveReload !== "undefined" ? testDevServerOptions.liveReload : true; const webSocketServerLaunched = @@ -331,12 +331,12 @@ describe('hot and live reload', () => { await new Promise((resolve) => { const webSocketTransport = - typeof testDevServerOptions.webSocketServer !== 'undefined' && + typeof testDevServerOptions.webSocketServer !== "undefined" && testDevServerOptions.webSocketServer !== false ? testDevServerOptions.webSocketServer - : 'ws'; + : "ws"; - if (webSocketTransport === 'ws') { + if (webSocketTransport === "ws") { const ws = new WebSocket( `ws://127.0.0.1:${devServerOptions.port}/ws`, { @@ -351,7 +351,7 @@ describe('hot and live reload', () => { let received = false; let errored = false; - ws.on('error', (error) => { + ws.on("error", (error) => { if (!webSocketServerLaunched && /404/.test(error)) { errored = true; } else { @@ -361,21 +361,21 @@ describe('hot and live reload', () => { ws.close(); }); - ws.on('open', () => { + ws.on("open", () => { opened = true; }); - ws.on('message', (data) => { + ws.on("message", (data) => { const message = JSON.parse(data); - if (message.type === 'ok') { + if (message.type === "ok") { received = true; ws.close(); } }); - ws.on('close', () => { + ws.on("close", () => { if (opened && received && !errored) { resolve(); } else if (!webSocketServerLaunched && errored) { @@ -402,7 +402,7 @@ describe('hot and live reload', () => { sockjs.onmessage = ({ data }) => { const message = JSON.parse(data); - if (message.type === 'ok') { + if (message.type === "ok") { received = true; sockjs.close(); @@ -412,7 +412,7 @@ describe('hot and live reload', () => { sockjs.onclose = (event) => { if (opened && received && !errored) { resolve(); - } else if (event && event.reason === 'Cannot connect to server') { + } else if (event && event.reason === "Cannot connect to server") { resolve(); } }; @@ -427,60 +427,60 @@ describe('hot and live reload', () => { let doneHotUpdate = false; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message.text()); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }) - .on('request', (requestObj) => { + .on("request", (requestObj) => { if (/\.hot-update\.json$/.test(requestObj.url())) { doneHotUpdate = true; } }); - await page.goto(`http://localhost:${port}/main${mode.query || ''}`, { - waitUntil: 'networkidle0', + await page.goto(`http://localhost:${port}/main${mode.query || ""}`, { + waitUntil: "networkidle0", }); const backgroundColorBefore = await page.evaluate(() => { const body = document.body; - return getComputedStyle(body)['background-color']; + return getComputedStyle(body)["background-color"]; }); - expect(backgroundColorBefore).toEqual('rgb(0, 0, 255)'); + expect(backgroundColorBefore).toEqual("rgb(0, 0, 255)"); fs.writeFileSync( cssFilePath, - 'body { background-color: rgb(255, 0, 0); }' + "body { background-color: rgb(255, 0, 0); }" ); let doNothing = false; - const query = mode.query || ''; + const query = mode.query || ""; let allowToHotModuleReplacement = true; - if (query.indexOf('webpack-dev-server-hot=false') !== -1) { + if (query.indexOf("webpack-dev-server-hot=false") !== -1) { allowToHotModuleReplacement = false; } if ( Array.isArray(webpackOptions.entry) && - webpackOptions.entry.map((item) => item.includes('hot=false')) + webpackOptions.entry.map((item) => item.includes("hot=false")) ) { allowToHotModuleReplacement = false; } let allowToLiveReload = true; - if (query.indexOf('webpack-dev-server-live-reload=false') !== -1) { + if (query.indexOf("webpack-dev-server-live-reload=false") !== -1) { allowToLiveReload = false; } if ( Array.isArray(webpackOptions.entry) && - webpackOptions.entry.map((item) => item.includes('live-reload=false')) + webpackOptions.entry.map((item) => item.includes("live-reload=false")) ) { allowToLiveReload = false; } @@ -492,14 +492,14 @@ describe('hot and live reload', () => { ) { await page.waitForFunction( () => - getComputedStyle(document.body)['background-color'] === - 'rgb(255, 0, 0)' + getComputedStyle(document.body)["background-color"] === + "rgb(255, 0, 0)" ); expect(doneHotUpdate).toBe(true); } else if (webSocketServerLaunched && liveReload && allowToLiveReload) { await page.waitForNavigation({ - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); } else { if (webSocketServerLaunched) { @@ -520,17 +520,17 @@ describe('hot and live reload', () => { const backgroundColorAfter = await page.evaluate(() => { const body = document.body; - return getComputedStyle(body)['background-color']; + return getComputedStyle(body)["background-color"]; }); if (doNothing) { - expect(backgroundColorAfter).toEqual('rgb(0, 0, 255)'); + expect(backgroundColorAfter).toEqual("rgb(0, 0, 255)"); } else { - expect(backgroundColorAfter).toEqual('rgb(255, 0, 0)'); + expect(backgroundColorAfter).toEqual("rgb(255, 0, 0)"); } - expect(consoleMessages).toMatchSnapshot('console messages'); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(consoleMessages).toMatchSnapshot("console messages"); + expect(pageErrors).toMatchSnapshot("page errors"); fs.unlinkSync(cssFilePath); diff --git a/test/e2e/ipc.test.js b/test/e2e/ipc.test.js index d0f48c69d7..d2363d10a9 100644 --- a/test/e2e/ipc.test.js +++ b/test/e2e/ipc.test.js @@ -1,24 +1,24 @@ -'use strict'; - -const os = require('os'); -const net = require('net'); -const path = require('path'); -const http = require('http'); -const webpack = require('webpack'); -const httpProxy = require('http-proxy'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/client-config/webpack.config'); -const runBrowser = require('../helpers/run-browser'); -const port1 = require('../ports-map').ipc; - -const webSocketServers = ['ws', 'sockjs']; - -describe('web socket server URL', () => { +"use strict"; + +const os = require("os"); +const net = require("net"); +const path = require("path"); +const http = require("http"); +const webpack = require("webpack"); +const httpProxy = require("http-proxy"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/client-config/webpack.config"); +const runBrowser = require("../helpers/run-browser"); +const port1 = require("../ports-map").ipc; + +const webSocketServers = ["ws", "sockjs"]; + +describe("web socket server URL", () => { for (const webSocketServer of webSocketServers) { - const websocketURLProtocol = webSocketServer === 'ws' ? 'ws' : 'http'; + const websocketURLProtocol = webSocketServer === "ws" ? "ws" : "http"; it(`should work with the "ipc" option using "true" value ("${webSocketServer}")`, async () => { - const devServerHost = '127.0.0.1'; + const devServerHost = "127.0.0.1"; const proxyHost = devServerHost; const proxyPort = port1; @@ -59,7 +59,7 @@ describe('web socket server URL', () => { proxy.web(request, response); }); - proxyServer.on('upgrade', (request, socket, head) => { + proxyServer.on("upgrade", (request, socket, head) => { proxy.ws(request, socket, head); }); @@ -78,23 +78,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -102,7 +102,7 @@ describe('web socket server URL', () => { } await page.goto(`http://${proxyHost}:${proxyPort}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -111,9 +111,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://${devServerHost}:${proxyPort}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); proxy.close(); @@ -132,12 +132,12 @@ describe('web socket server URL', () => { }); it(`should work with the "ipc" option using "string" value ("${webSocketServer}")`, async () => { - const isWindows = process.platform === 'win32'; - const pipePrefix = isWindows ? '\\\\.\\pipe\\' : os.tmpdir(); + const isWindows = process.platform === "win32"; + const pipePrefix = isWindows ? "\\\\.\\pipe\\" : os.tmpdir(); const pipeName = `webpack-dev-server.${process.pid}-1.sock`; const ipc = path.join(pipePrefix, pipeName); - const devServerHost = '127.0.0.1'; + const devServerHost = "127.0.0.1"; const proxyHost = devServerHost; const proxyPort = port1; @@ -172,7 +172,7 @@ describe('web socket server URL', () => { proxy.web(request, response); }); - proxyServer.on('upgrade', (request, socket, head) => { + proxyServer.on("upgrade", (request, socket, head) => { proxy.ws(request, socket, head); }); @@ -191,23 +191,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -215,7 +215,7 @@ describe('web socket server URL', () => { } await page.goto(`http://${proxyHost}:${proxyPort}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -224,9 +224,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://${devServerHost}:${proxyPort}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); proxy.close(); @@ -246,16 +246,16 @@ describe('web socket server URL', () => { // TODO un skip after implement new API it.skip(`should work with the "ipc" option using "string" value and remove old ("${webSocketServer}")`, async () => { - const isWindows = process.platform === 'win32'; + const isWindows = process.platform === "win32"; const localRelative = path.relative(process.cwd(), `${os.tmpdir()}/`); - const pipePrefix = isWindows ? '\\\\.\\pipe\\' : localRelative; + const pipePrefix = isWindows ? "\\\\.\\pipe\\" : localRelative; const pipeName = `webpack-dev-server.${process.pid}-2.sock`; const ipc = path.join(pipePrefix, pipeName); const ipcServer = await new Promise((resolve, reject) => { const server = net.Server(); - server.on('error', (error) => { + server.on("error", (error) => { reject(error); }); @@ -264,7 +264,7 @@ describe('web socket server URL', () => { }); }); - const devServerHost = '127.0.0.1'; + const devServerHost = "127.0.0.1"; const proxyHost = devServerHost; const proxyPort = port1; @@ -299,14 +299,14 @@ describe('web socket server URL', () => { proxy.web(request, response); }); - proxyServer.on('upgrade', (request, socket, head) => { + proxyServer.on("upgrade", (request, socket, head) => { proxy.ws(request, socket, head); }); return proxyServer.listen(proxyPort, proxyHost, callback); } - console.log('HERE'); + console.log("HERE"); const proxy = await new Promise((resolve) => { const proxyCreated = startProxy(() => { resolve(proxyCreated); @@ -319,23 +319,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -344,7 +344,7 @@ describe('web socket server URL', () => { console.log(`http://${proxyHost}:${proxyPort}/main`); await page.goto(`http://${proxyHost}:${proxyPort}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -353,9 +353,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://${devServerHost}:${proxyPort}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); proxy.close(); diff --git a/test/e2e/logging.test.js b/test/e2e/logging.test.js index 6466de4f29..1bdeeb7c9e 100644 --- a/test/e2e/logging.test.js +++ b/test/e2e/logging.test.js @@ -1,49 +1,49 @@ -'use strict'; +"use strict"; -const fs = require('fs'); -const path = require('path'); -const webpack = require('webpack'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/client-config/webpack.config'); -const runBrowser = require('../helpers/run-browser'); -const port = require('../ports-map').logging; +const fs = require("fs"); +const path = require("path"); +const webpack = require("webpack"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/client-config/webpack.config"); +const runBrowser = require("../helpers/run-browser"); +const port = require("../ports-map").logging; -describe('logging', () => { +describe("logging", () => { const webSocketServers = [ - { webSocketServer: 'ws' }, - { webSocketServer: 'sockjs' }, + { webSocketServer: "ws" }, + { webSocketServer: "sockjs" }, ]; const cases = [ { - title: 'should work and log message about live reloading is enabled', + title: "should work and log message about live reloading is enabled", devServerOptions: { hot: false, }, }, { title: - 'should work and log messages about hot and live reloading is enabled', + "should work and log messages about hot and live reloading is enabled", devServerOptions: { hot: true, }, }, { - title: 'should work and log messages about hot is enabled', + title: "should work and log messages about hot is enabled", devServerOptions: { liveReload: false, }, }, { title: - 'should work and log messages about hot and live reloading is enabled', + "should work and log messages about hot and live reloading is enabled", devServerOptions: { liveReload: true, }, }, { title: - 'should work and do not log messages about hot and live reloading is enabled', + "should work and do not log messages about hot and live reloading is enabled", devServerOptions: { liveReload: false, hot: false, @@ -51,23 +51,23 @@ describe('logging', () => { }, { title: - 'should work and log messages about hot and live reloading is enabled', + "should work and log messages about hot and live reloading is enabled", devServerOptions: { liveReload: true, hot: true, }, }, { - title: 'should work and log warnings by default', + title: "should work and log warnings by default", webpackOptions: { plugins: [ { apply(compiler) { compiler.hooks.thisCompilation.tap( - 'warnings-webpack-plugin', + "warnings-webpack-plugin", (compilation) => { compilation.warnings.push( - new Error('Warning from compilation') + new Error("Warning from compilation") ); } ); @@ -77,15 +77,15 @@ describe('logging', () => { }, }, { - title: 'should work and log errors by default', + title: "should work and log errors by default", webpackOptions: { plugins: [ { apply(compiler) { compiler.hooks.thisCompilation.tap( - 'warnings-webpack-plugin', + "warnings-webpack-plugin", (compilation) => { - compilation.errors.push(new Error('Error from compilation')); + compilation.errors.push(new Error("Error from compilation")); } ); }, @@ -97,7 +97,7 @@ describe('logging', () => { title: 'should work when the "client.logging" is "info"', devServerOptions: { client: { - logging: 'info', + logging: "info", }, }, }, @@ -105,7 +105,7 @@ describe('logging', () => { title: 'should work when the "client.logging" is "log"', devServerOptions: { client: { - logging: 'log', + logging: "log", }, }, }, @@ -113,7 +113,7 @@ describe('logging', () => { title: 'should work when the "client.logging" is "verbose"', devServerOptions: { client: { - logging: 'verbose', + logging: "verbose", }, }, }, @@ -121,23 +121,23 @@ describe('logging', () => { title: 'should work when the "client.logging" is "none"', devServerOptions: { client: { - logging: 'none', + logging: "none", }, }, }, { - title: 'should work and log only error', + title: "should work and log only error", webpackOptions: { plugins: [ { apply(compiler) { compiler.hooks.thisCompilation.tap( - 'warnings-webpack-plugin', + "warnings-webpack-plugin", (compilation) => { compilation.warnings.push( - new Error('Warning from compilation') + new Error("Warning from compilation") ); - compilation.errors.push(new Error('Error from compilation')); + compilation.errors.push(new Error("Error from compilation")); } ); }, @@ -146,23 +146,23 @@ describe('logging', () => { }, devServerOptions: { client: { - logging: 'error', + logging: "error", }, }, }, { - title: 'should work and log warning and errors', + title: "should work and log warning and errors", webpackOptions: { plugins: [ { apply(compiler) { compiler.hooks.thisCompilation.tap( - 'warnings-webpack-plugin', + "warnings-webpack-plugin", (compilation) => { compilation.warnings.push( - new Error('Warning from compilation') + new Error("Warning from compilation") ); - compilation.errors.push(new Error('Error from compilation')); + compilation.errors.push(new Error("Error from compilation")); } ); }, @@ -171,14 +171,14 @@ describe('logging', () => { }, devServerOptions: { client: { - logging: 'warn', + logging: "warn", }, }, }, { - title: 'should work and log static changes', + title: "should work and log static changes", devServerOptions: { - static: path.resolve(__dirname, '../fixtures/client-config/static'), + static: path.resolve(__dirname, "../fixtures/client-config/static"), }, }, ]; @@ -186,11 +186,11 @@ describe('logging', () => { webSocketServers.forEach((webSocketServer) => { cases.forEach((testCase) => { it(`${testCase.title} (${ - webSocketServer.webSocketServer || 'default' + webSocketServer.webSocketServer || "default" })`, async () => { const compiler = webpack({ ...config, ...testCase.webpackOptions }); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, ...testCase.devServerOptions, }; @@ -216,22 +216,22 @@ describe('logging', () => { const consoleMessages = []; - page.on('console', (message) => { + page.on("console", (message) => { consoleMessages.push(message); }); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); if (testCase.devServerOptions && testCase.devServerOptions.static) { fs.writeFileSync( - path.join(testCase.devServerOptions.static, './foo.txt'), - 'Text' + path.join(testCase.devServerOptions.static, "./foo.txt"), + "Text" ); await page.waitForNavigation({ - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); } @@ -239,10 +239,10 @@ describe('logging', () => { consoleMessages.map((message) => message .text() - .replace(/\\/g, '/') + .replace(/\\/g, "/") .replace( - new RegExp(process.cwd().replace(/\\/g, '/'), 'g'), - '' + new RegExp(process.cwd().replace(/\\/g, "/"), "g"), + "" ) ) ).toMatchSnapshot(); diff --git a/test/e2e/overlay.test.js b/test/e2e/overlay.test.js index a177178616..f85a493d59 100644 --- a/test/e2e/overlay.test.js +++ b/test/e2e/overlay.test.js @@ -1,21 +1,21 @@ -'use strict'; +"use strict"; -const fs = require('fs'); -const path = require('path'); -const prettier = require('prettier'); -const webpack = require('webpack'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/overlay-config/webpack.config'); -const runBrowser = require('../helpers/run-browser'); -const port = require('../ports-map').overlay; +const fs = require("fs"); +const path = require("path"); +const prettier = require("prettier"); +const webpack = require("webpack"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/overlay-config/webpack.config"); +const runBrowser = require("../helpers/run-browser"); +const port = require("../ports-map").overlay; class ErrorPlugin { // eslint-disable-next-line class-methods-use-this apply(compiler) { compiler.hooks.thisCompilation.tap( - 'warnings-webpack-plugin', + "warnings-webpack-plugin", (compilation) => { - compilation.errors.push(new Error('Error from compilation')); + compilation.errors.push(new Error("Error from compilation")); } ); } @@ -25,22 +25,22 @@ class WarningPlugin { // eslint-disable-next-line class-methods-use-this apply(compiler) { compiler.hooks.thisCompilation.tap( - 'warnings-webpack-plugin', + "warnings-webpack-plugin", (compilation) => { - compilation.warnings.push(new Error('Warning from compilation')); + compilation.warnings.push(new Error("Warning from compilation")); } ); } } -describe('overlay', () => { - it('should show on a warning for initial compilation', async () => { +describe("overlay", () => { + it("should show on a warning for initial compilation", async () => { const compiler = webpack(config); new WarningPlugin().apply(compiler); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, }; const server = new Server(devServerOptions, compiler); @@ -60,21 +60,21 @@ describe('overlay', () => { const { page, browser } = await runBrowser(); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const pageHtml = await page.evaluate(() => document.body.outerHTML); - const overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + const overlayHandle = await page.$("#webpack-dev-server-client-overlay"); const overlayFrame = await overlayHandle.contentFrame(); const overlayHtml = await overlayFrame.evaluate( () => document.body.outerHTML ); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html" ); - expect(prettier.format(overlayHtml, { parser: 'html' })).toMatchSnapshot( - 'overlay html' + expect(prettier.format(overlayHtml, { parser: "html" })).toMatchSnapshot( + "overlay html" ); await browser.close(); @@ -85,13 +85,13 @@ describe('overlay', () => { }); }); - it('should show on an error for initial compilation', async () => { + it("should show on an error for initial compilation", async () => { const compiler = webpack(config); new ErrorPlugin().apply(compiler); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, }; const server = new Server(devServerOptions, compiler); @@ -111,21 +111,21 @@ describe('overlay', () => { const { page, browser } = await runBrowser(); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const pageHtml = await page.evaluate(() => document.body.outerHTML); - const overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + const overlayHandle = await page.$("#webpack-dev-server-client-overlay"); const overlayFrame = await overlayHandle.contentFrame(); const overlayHtml = await overlayFrame.evaluate( () => document.body.outerHTML ); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html" ); - expect(prettier.format(overlayHtml, { parser: 'html' })).toMatchSnapshot( - 'overlay html' + expect(prettier.format(overlayHtml, { parser: "html" })).toMatchSnapshot( + "overlay html" ); await browser.close(); @@ -136,7 +136,7 @@ describe('overlay', () => { }); }); - it('should show on a warning and error for initial compilation', async () => { + it("should show on a warning and error for initial compilation", async () => { const compiler = webpack(config); new WarningPlugin().apply(compiler); @@ -146,7 +146,7 @@ describe('overlay', () => { new ErrorPlugin().apply(compiler); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, }; const server = new Server(devServerOptions, compiler); @@ -166,21 +166,21 @@ describe('overlay', () => { const { page, browser } = await runBrowser(); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const pageHtml = await page.evaluate(() => document.body.outerHTML); - const overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + const overlayHandle = await page.$("#webpack-dev-server-client-overlay"); const overlayFrame = await overlayHandle.contentFrame(); const overlayHtml = await overlayFrame.evaluate( () => document.body.outerHTML ); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html" ); - expect(prettier.format(overlayHtml, { parser: 'html' })).toMatchSnapshot( - 'overlay html' + expect(prettier.format(overlayHtml, { parser: "html" })).toMatchSnapshot( + "overlay html" ); await browser.close(); @@ -191,10 +191,10 @@ describe('overlay', () => { }); }); - it('should not show initially, then show on an error, then hide on fix', async () => { + it("should not show initially, then show on an error, then hide on fix", async () => { const compiler = webpack(config); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, }; const server = new Server(devServerOptions, compiler); @@ -214,28 +214,28 @@ describe('overlay', () => { const { page, browser } = await runBrowser(); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); let pageHtml = await page.evaluate(() => document.body.outerHTML); - let overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + let overlayHandle = await page.$("#webpack-dev-server-client-overlay"); expect(overlayHandle).toBe(null); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html initial' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html initial" ); const pathToFile = path.resolve( __dirname, - '../fixtures/overlay-config/foo.js' + "../fixtures/overlay-config/foo.js" ); const originalCode = fs.readFileSync(pathToFile); - fs.writeFileSync(pathToFile, '`;'); + fs.writeFileSync(pathToFile, "`;"); - await page.waitForSelector('#webpack-dev-server-client-overlay'); + await page.waitForSelector("#webpack-dev-server-client-overlay"); - overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + overlayHandle = await page.$("#webpack-dev-server-client-overlay"); pageHtml = await page.evaluate(() => document.body.outerHTML); const overlayFrame = await overlayHandle.contentFrame(); @@ -243,25 +243,25 @@ describe('overlay', () => { () => document.body.outerHTML ); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html with error' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html with error" ); - expect(prettier.format(overlayHtml, { parser: 'html' })).toMatchSnapshot( - 'overlay html' + expect(prettier.format(overlayHtml, { parser: "html" })).toMatchSnapshot( + "overlay html" ); fs.writeFileSync(pathToFile, originalCode); - await page.waitForSelector('#webpack-dev-server-client-overlay', { + await page.waitForSelector("#webpack-dev-server-client-overlay", { hidden: true, }); pageHtml = await page.evaluate(() => document.body.outerHTML); - overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + overlayHandle = await page.$("#webpack-dev-server-client-overlay"); expect(overlayHandle).toBe(null); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html after fix error' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html after fix error" ); await browser.close(); @@ -272,10 +272,10 @@ describe('overlay', () => { }); }); - it('should not show initially, then show on an error, then show other error, then hide on fix', async () => { + it("should not show initially, then show on an error, then show other error, then hide on fix", async () => { const compiler = webpack(config); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, }; const server = new Server(devServerOptions, compiler); @@ -295,28 +295,28 @@ describe('overlay', () => { const { page, browser } = await runBrowser(); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); let pageHtml = await page.evaluate(() => document.body.outerHTML); - let overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + let overlayHandle = await page.$("#webpack-dev-server-client-overlay"); expect(overlayHandle).toBe(null); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html initial' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html initial" ); const pathToFile = path.resolve( __dirname, - '../fixtures/overlay-config/foo.js' + "../fixtures/overlay-config/foo.js" ); const originalCode = fs.readFileSync(pathToFile); - fs.writeFileSync(pathToFile, '`;'); + fs.writeFileSync(pathToFile, "`;"); - await page.waitForSelector('#webpack-dev-server-client-overlay'); + await page.waitForSelector("#webpack-dev-server-client-overlay"); - overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + overlayHandle = await page.$("#webpack-dev-server-client-overlay"); pageHtml = await page.evaluate(() => document.body.outerHTML); let overlayFrame = await overlayHandle.contentFrame(); @@ -324,45 +324,45 @@ describe('overlay', () => { () => document.body.outerHTML ); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html with error' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html with error" ); - expect(prettier.format(overlayHtml, { parser: 'html' })).toMatchSnapshot( - 'overlay html' + expect(prettier.format(overlayHtml, { parser: "html" })).toMatchSnapshot( + "overlay html" ); - fs.writeFileSync(pathToFile, '`;a'); + fs.writeFileSync(pathToFile, "`;a"); - await page.waitForSelector('#webpack-dev-server-client-overlay', { + await page.waitForSelector("#webpack-dev-server-client-overlay", { hidden: true, }); - await page.waitForSelector('#webpack-dev-server-client-overlay'); + await page.waitForSelector("#webpack-dev-server-client-overlay"); - overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + overlayHandle = await page.$("#webpack-dev-server-client-overlay"); pageHtml = await page.evaluate(() => document.body.outerHTML); overlayFrame = await overlayHandle.contentFrame(); overlayHtml = await overlayFrame.evaluate(() => document.body.outerHTML); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html with other error' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html with other error" ); - expect(prettier.format(overlayHtml, { parser: 'html' })).toMatchSnapshot( - 'overlay html' + expect(prettier.format(overlayHtml, { parser: "html" })).toMatchSnapshot( + "overlay html" ); fs.writeFileSync(pathToFile, originalCode); - await page.waitForSelector('#webpack-dev-server-client-overlay', { + await page.waitForSelector("#webpack-dev-server-client-overlay", { hidden: true, }); pageHtml = await page.evaluate(() => document.body.outerHTML); - overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + overlayHandle = await page.$("#webpack-dev-server-client-overlay"); expect(overlayHandle).toBe(null); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html after fix error' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html after fix error" ); await browser.close(); @@ -373,10 +373,10 @@ describe('overlay', () => { }); }); - it('should not show initially, then show on an error and allow to close', async () => { + it("should not show initially, then show on an error and allow to close", async () => { const compiler = webpack(config); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, }; const server = new Server(devServerOptions, compiler); @@ -396,28 +396,28 @@ describe('overlay', () => { const { page, browser } = await runBrowser(); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); let pageHtml = await page.evaluate(() => document.body.outerHTML); - let overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + let overlayHandle = await page.$("#webpack-dev-server-client-overlay"); expect(overlayHandle).toBe(null); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html initial' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html initial" ); const pathToFile = path.resolve( __dirname, - '../fixtures/overlay-config/foo.js' + "../fixtures/overlay-config/foo.js" ); const originalCode = fs.readFileSync(pathToFile); - fs.writeFileSync(pathToFile, '`;'); + fs.writeFileSync(pathToFile, "`;"); - await page.waitForSelector('#webpack-dev-server-client-overlay'); + await page.waitForSelector("#webpack-dev-server-client-overlay"); - overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + overlayHandle = await page.$("#webpack-dev-server-client-overlay"); pageHtml = await page.evaluate(() => document.body.outerHTML); const overlayFrame = await overlayHandle.contentFrame(); @@ -425,31 +425,31 @@ describe('overlay', () => { () => document.body.outerHTML ); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html with error' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html with error" ); - expect(prettier.format(overlayHtml, { parser: 'html' })).toMatchSnapshot( - 'overlay html' + expect(prettier.format(overlayHtml, { parser: "html" })).toMatchSnapshot( + "overlay html" ); const frame = await page .frames() - .find((item) => item.name() === 'webpack-dev-server-client-overlay'); + .find((item) => item.name() === "webpack-dev-server-client-overlay"); - const buttonHandle = await frame.$('button'); + const buttonHandle = await frame.$("button"); await buttonHandle.click(); - await page.waitForSelector('#webpack-dev-server-client-overlay', { + await page.waitForSelector("#webpack-dev-server-client-overlay", { hidden: true, }); pageHtml = await page.evaluate(() => document.body.outerHTML); - overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + overlayHandle = await page.$("#webpack-dev-server-client-overlay"); expect(overlayHandle).toBe(null); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html after close' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html after close" ); fs.writeFileSync(pathToFile, originalCode); @@ -468,7 +468,7 @@ describe('overlay', () => { new WarningPlugin().apply(compiler); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, client: { overlay: false, @@ -491,15 +491,15 @@ describe('overlay', () => { const { page, browser } = await runBrowser(); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const pageHtml = await page.evaluate(() => document.body.outerHTML); - const overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + const overlayHandle = await page.$("#webpack-dev-server-client-overlay"); expect(overlayHandle).toBe(null); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html" ); await browser.close(); @@ -516,7 +516,7 @@ describe('overlay', () => { new WarningPlugin().apply(compiler); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, client: { overlay: { @@ -541,15 +541,15 @@ describe('overlay', () => { const { page, browser } = await runBrowser(); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const pageHtml = await page.evaluate(() => document.body.outerHTML); - const overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + const overlayHandle = await page.$("#webpack-dev-server-client-overlay"); expect(overlayHandle).toBe(null); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html" ); await browser.close(); @@ -566,7 +566,7 @@ describe('overlay', () => { new WarningPlugin().apply(compiler); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, client: { overlay: true, @@ -589,21 +589,21 @@ describe('overlay', () => { const { page, browser } = await runBrowser(); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const pageHtml = await page.evaluate(() => document.body.outerHTML); - const overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + const overlayHandle = await page.$("#webpack-dev-server-client-overlay"); const overlayFrame = await overlayHandle.contentFrame(); const overlayHtml = await overlayFrame.evaluate( () => document.body.outerHTML ); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html" ); - expect(prettier.format(overlayHtml, { parser: 'html' })).toMatchSnapshot( - 'overlay html' + expect(prettier.format(overlayHtml, { parser: "html" })).toMatchSnapshot( + "overlay html" ); await browser.close(); @@ -620,7 +620,7 @@ describe('overlay', () => { new WarningPlugin().apply(compiler); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, client: { overlay: { @@ -645,21 +645,21 @@ describe('overlay', () => { const { page, browser } = await runBrowser(); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const pageHtml = await page.evaluate(() => document.body.outerHTML); - const overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + const overlayHandle = await page.$("#webpack-dev-server-client-overlay"); const overlayFrame = await overlayHandle.contentFrame(); const overlayHtml = await overlayFrame.evaluate( () => document.body.outerHTML ); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html" ); - expect(prettier.format(overlayHtml, { parser: 'html' })).toMatchSnapshot( - 'overlay html' + expect(prettier.format(overlayHtml, { parser: "html" })).toMatchSnapshot( + "overlay html" ); await browser.close(); @@ -676,7 +676,7 @@ describe('overlay', () => { new WarningPlugin().apply(compiler); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, client: { overlay: { @@ -701,21 +701,21 @@ describe('overlay', () => { const { page, browser } = await runBrowser(); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const pageHtml = await page.evaluate(() => document.body.outerHTML); - const overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + const overlayHandle = await page.$("#webpack-dev-server-client-overlay"); const overlayFrame = await overlayHandle.contentFrame(); const overlayHtml = await overlayFrame.evaluate( () => document.body.outerHTML ); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html" ); - expect(prettier.format(overlayHtml, { parser: 'html' })).toMatchSnapshot( - 'overlay html' + expect(prettier.format(overlayHtml, { parser: "html" })).toMatchSnapshot( + "overlay html" ); await browser.close(); @@ -732,7 +732,7 @@ describe('overlay', () => { new ErrorPlugin().apply(compiler); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, client: { overlay: false, @@ -755,15 +755,15 @@ describe('overlay', () => { const { page, browser } = await runBrowser(); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const pageHtml = await page.evaluate(() => document.body.outerHTML); - const overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + const overlayHandle = await page.$("#webpack-dev-server-client-overlay"); expect(overlayHandle).toBe(null); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html" ); await browser.close(); @@ -780,7 +780,7 @@ describe('overlay', () => { new ErrorPlugin().apply(compiler); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, client: { overlay: { @@ -805,15 +805,15 @@ describe('overlay', () => { const { page, browser } = await runBrowser(); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const pageHtml = await page.evaluate(() => document.body.outerHTML); - const overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + const overlayHandle = await page.$("#webpack-dev-server-client-overlay"); expect(overlayHandle).toBe(null); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html" ); await browser.close(); @@ -830,7 +830,7 @@ describe('overlay', () => { new ErrorPlugin().apply(compiler); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, client: { overlay: true, @@ -853,21 +853,21 @@ describe('overlay', () => { const { page, browser } = await runBrowser(); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const pageHtml = await page.evaluate(() => document.body.outerHTML); - const overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + const overlayHandle = await page.$("#webpack-dev-server-client-overlay"); const overlayFrame = await overlayHandle.contentFrame(); const overlayHtml = await overlayFrame.evaluate( () => document.body.outerHTML ); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html" ); - expect(prettier.format(overlayHtml, { parser: 'html' })).toMatchSnapshot( - 'overlay html' + expect(prettier.format(overlayHtml, { parser: "html" })).toMatchSnapshot( + "overlay html" ); await browser.close(); @@ -884,7 +884,7 @@ describe('overlay', () => { new ErrorPlugin().apply(compiler); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, client: { overlay: { @@ -909,21 +909,21 @@ describe('overlay', () => { const { page, browser } = await runBrowser(); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const pageHtml = await page.evaluate(() => document.body.outerHTML); - const overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + const overlayHandle = await page.$("#webpack-dev-server-client-overlay"); const overlayFrame = await overlayHandle.contentFrame(); const overlayHtml = await overlayFrame.evaluate( () => document.body.outerHTML ); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html" ); - expect(prettier.format(overlayHtml, { parser: 'html' })).toMatchSnapshot( - 'overlay html' + expect(prettier.format(overlayHtml, { parser: "html" })).toMatchSnapshot( + "overlay html" ); await browser.close(); @@ -940,7 +940,7 @@ describe('overlay', () => { new WarningPlugin().apply(compiler); const devServerOptions = { - host: '0.0.0.0', + host: "0.0.0.0", port, client: { overlay: { @@ -965,21 +965,21 @@ describe('overlay', () => { const { page, browser } = await runBrowser(); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const pageHtml = await page.evaluate(() => document.body.outerHTML); - const overlayHandle = await page.$('#webpack-dev-server-client-overlay'); + const overlayHandle = await page.$("#webpack-dev-server-client-overlay"); const overlayFrame = await overlayHandle.contentFrame(); const overlayHtml = await overlayFrame.evaluate( () => document.body.outerHTML ); - expect(prettier.format(pageHtml, { parser: 'html' })).toMatchSnapshot( - 'page html' + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html" ); - expect(prettier.format(overlayHtml, { parser: 'html' })).toMatchSnapshot( - 'overlay html' + expect(prettier.format(overlayHtml, { parser: "html" })).toMatchSnapshot( + "overlay html" ); await browser.close(); diff --git a/test/e2e/progress.test.js b/test/e2e/progress.test.js index 9bdc37158f..a3608287c0 100644 --- a/test/e2e/progress.test.js +++ b/test/e2e/progress.test.js @@ -1,26 +1,26 @@ -'use strict'; +"use strict"; -const fs = require('fs'); -const path = require('path'); -const webpack = require('webpack'); -const Server = require('../../lib/Server'); -const reloadConfig = require('../fixtures/reload-config-2/webpack.config'); -const runBrowser = require('../helpers/run-browser'); -const port = require('../ports-map').progress; +const fs = require("fs"); +const path = require("path"); +const webpack = require("webpack"); +const Server = require("../../lib/Server"); +const reloadConfig = require("../fixtures/reload-config-2/webpack.config"); +const runBrowser = require("../helpers/run-browser"); +const port = require("../ports-map").progress; const cssFilePath = path.resolve( __dirname, - '../fixtures/reload-config-2/main.css' + "../fixtures/reload-config-2/main.css" ); -describe('progress', () => { - it('should work and log progress in a browser console', async () => { - fs.writeFileSync(cssFilePath, 'body { background-color: rgb(0, 0, 255); }'); +describe("progress", () => { + it("should work and log progress in a browser console", async () => { + fs.writeFileSync(cssFilePath, "body { background-color: rgb(0, 0, 255); }"); const compiler = webpack(reloadConfig); const devServerOptions = { port, - host: '0.0.0.0', + host: "0.0.0.0", static: false, hot: true, client: { @@ -48,20 +48,20 @@ describe('progress', () => { let doHotUpdate = false; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('request', (requestObj) => { + .on("request", (requestObj) => { if (/\.hot-update\.(json|js)$/.test(requestObj.url())) { doHotUpdate = true; } }); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); - fs.writeFileSync(cssFilePath, 'body { background-color: rgb(255, 0, 0); }'); + fs.writeFileSync(cssFilePath, "body { background-color: rgb(255, 0, 0); }"); await new Promise((resolve) => { const timer = setInterval(() => { diff --git a/test/e2e/stats.test.js b/test/e2e/stats.test.js index 0b780030d7..2584e89c94 100644 --- a/test/e2e/stats.test.js +++ b/test/e2e/stats.test.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/client-config/webpack.config'); -const runBrowser = require('../helpers/run-browser'); -const port = require('../ports-map').stats; +const webpack = require("webpack"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/client-config/webpack.config"); +const runBrowser = require("../helpers/run-browser"); +const port = require("../ports-map").stats; global.console.log = jest.fn(); -describe('stats', () => { +describe("stats", () => { const cases = [ { title: 'should work when "stats" is not specified', @@ -36,7 +36,7 @@ describe('stats', () => { { title: 'should work using "errors-only" value for the "stats" option', webpackOptions: { - stats: 'errors-only', + stats: "errors-only", }, }, { @@ -54,7 +54,7 @@ describe('stats', () => { webpackOptions: { stats: { colors: { - green: '\u001b[32m', + green: "\u001b[32m", }, }, }, @@ -67,10 +67,10 @@ describe('stats', () => { { apply(compiler) { compiler.hooks.thisCompilation.tap( - 'warnings-webpack-plugin', + "warnings-webpack-plugin", (compilation) => { compilation.warnings.push( - new Error('Warning from compilation') + new Error("Warning from compilation") ); } ); @@ -82,7 +82,7 @@ describe('stats', () => { }, ]; - if (webpack.version.startsWith('5')) { + if (webpack.version.startsWith("5")) { cases.push({ title: 'should work and respect the "ignoreWarnings" option', webpackOptions: { @@ -90,10 +90,10 @@ describe('stats', () => { { apply(compiler) { compiler.hooks.thisCompilation.tap( - 'warnings-webpack-plugin', + "warnings-webpack-plugin", (compilation) => { compilation.warnings.push( - new Error('Warning from compilation') + new Error("Warning from compilation") ); } ); @@ -109,7 +109,7 @@ describe('stats', () => { it(testCase.title, async () => { const compiler = webpack({ ...config, ...testCase.webpackOptions }); const devServerOptions = { - host: '127.0.0.1', + host: "127.0.0.1", port, }; const server = new Server(devServerOptions, compiler); @@ -130,12 +130,12 @@ describe('stats', () => { const consoleMessages = []; - page.on('console', (message) => { + page.on("console", (message) => { consoleMessages.push(message); }); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); expect( diff --git a/test/e2e/target.test.js b/test/e2e/target.test.js index 3f5e40f35b..256e0adc53 100644 --- a/test/e2e/target.test.js +++ b/test/e2e/target.test.js @@ -1,38 +1,38 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/client-config/webpack.config'); -const runBrowser = require('../helpers/run-browser'); -const isWebpack5 = require('../helpers/isWebpack5'); -const port = require('../ports-map').target; +const webpack = require("webpack"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/client-config/webpack.config"); +const runBrowser = require("../helpers/run-browser"); +const isWebpack5 = require("../helpers/isWebpack5"); +const port = require("../ports-map").target; -describe('target', () => { +describe("target", () => { const targets = isWebpack5 ? [ false, - 'browserslist:defaults', - 'web', - 'webworker', - 'node', - 'async-node', - 'electron-main', - 'electron-preload', - 'electron-renderer', - 'nwjs', - 'node-webkit', - 'es5', - ['web', 'es5'], + "browserslist:defaults", + "web", + "webworker", + "node", + "async-node", + "electron-main", + "electron-preload", + "electron-renderer", + "nwjs", + "node-webkit", + "es5", + ["web", "es5"], ] : [ - 'web', - 'webworker', - 'node', - 'async-node', - 'electron-main', - 'electron-preload', - 'electron-renderer', - 'node-webkit', + "web", + "webworker", + "node", + "async-node", + "electron-main", + "electron-preload", + "electron-renderer", + "node-webkit", ]; for (const target of targets) { @@ -40,20 +40,20 @@ describe('target', () => { const compiler = webpack({ ...config, target, - ...(target === false || target === 'es5' + ...(target === false || target === "es5" ? { - output: { chunkFormat: 'array-push', path: '/' }, + output: { chunkFormat: "array-push", path: "/" }, } : {}), }); const devServerOptions = { - host: '127.0.0.1', + host: "127.0.0.1", port, }; const server = new Server(devServerOptions, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -70,29 +70,29 @@ describe('target', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); await page.goto(`http://127.0.0.1:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); if ( - target === 'node' || - target === 'async-node' || - target === 'electron-main' || - target === 'electron-preload' || - target === 'electron-renderer' || - target === 'nwjs' || - target === 'node-webkit' + target === "node" || + target === "async-node" || + target === "electron-main" || + target === "electron-preload" || + target === "electron-renderer" || + target === "nwjs" || + target === "node-webkit" ) { const hasRequireOrGlobalError = pageErrors.filter((pageError) => @@ -101,7 +101,7 @@ describe('target', () => { expect(hasRequireOrGlobalError).toBe(true); } else { - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); } await browser.close(); diff --git a/test/e2e/web-socket-communication.test.js b/test/e2e/web-socket-communication.test.js index 43f3f7e572..b7dff05700 100644 --- a/test/e2e/web-socket-communication.test.js +++ b/test/e2e/web-socket-communication.test.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const WebSocket = require('ws'); -const Server = require('../../lib/Server'); -const WebsocketServer = require('../../lib/servers/WebsocketServer'); -const config = require('../fixtures/client-config/webpack.config'); -const runBrowser = require('../helpers/run-browser'); -const port = require('../ports-map')['web-socket-communication']; +const webpack = require("webpack"); +const WebSocket = require("ws"); +const Server = require("../../lib/Server"); +const WebsocketServer = require("../../lib/servers/WebsocketServer"); +const config = require("../fixtures/client-config/webpack.config"); +const runBrowser = require("../helpers/run-browser"); +const port = require("../ports-map")["web-socket-communication"]; -describe('web socket communication', () => { - const webSocketServers = ['ws', 'sockjs']; +describe("web socket communication", () => { + const webSocketServers = ["ws", "sockjs"]; webSocketServers.forEach((websocketServer) => { it(`should work and close web socket client connection when web socket server closed ("${websocketServer}")`, async () => { @@ -17,7 +17,7 @@ describe('web socket communication', () => { const compiler = webpack(config); const devServerOptions = { - host: '127.0.0.1', + host: "127.0.0.1", port, webSocketServer: websocketServer, }; @@ -41,15 +41,15 @@ describe('web socket communication', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); await page.goto(`http://127.0.0.1:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); await new Promise((resolve, reject) => { @@ -74,9 +74,9 @@ describe('web socket communication', () => { }); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -97,7 +97,7 @@ describe('web socket communication', () => { const compiler = webpack(config); const devServerOptions = { - host: '127.0.0.1', + host: "127.0.0.1", port, webSocketServer: websocketServer, }; @@ -121,15 +121,15 @@ describe('web socket communication', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); await page.goto(`http://127.0.0.1:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); await browser.close(); @@ -142,9 +142,9 @@ describe('web socket communication', () => { expect(server.webSocketServer.clients.size).toBe(0); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await new Promise((resolve, reject) => { server.close((error) => { @@ -164,7 +164,7 @@ describe('web socket communication', () => { const compiler = webpack(config); const devServerOptions = { - host: '127.0.0.1', + host: "127.0.0.1", port, webSocketServer: websocketServer, }; @@ -188,15 +188,15 @@ describe('web socket communication', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); await page.goto(`http://127.0.0.1:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); await new Promise((resolve, reject) => { @@ -224,13 +224,13 @@ describe('web socket communication', () => { }); await page.waitForNavigation({ - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -252,9 +252,9 @@ describe('web socket communication', () => { const compiler = webpack(config); const devServerOptions = { - host: '127.0.0.1', + host: "127.0.0.1", port, - webSocketServer: 'ws', + webSocketServer: "ws", }; const server = new Server(devServerOptions, compiler); @@ -283,29 +283,29 @@ describe('web socket communication', () => { let opened = false; let received = false; - ws.on('open', () => { + ws.on("open", () => { opened = true; }); - ws.on('error', (error) => { + ws.on("error", (error) => { reject(error); }); - ws.on('ping', () => { + ws.on("ping", () => { if (opened && received) { ws.close(); } }); - ws.on('message', (data) => { + ws.on("message", (data) => { const message = JSON.parse(data); - if (message.type === 'ok') { + if (message.type === "ok") { received = true; } }); - ws.on('close', () => { + ws.on("close", () => { resolve(); }); }); diff --git a/test/e2e/web-socket-server-and-transport.test.js b/test/e2e/web-socket-server-and-transport.test.js index d248b4d773..30661b81b0 100644 --- a/test/e2e/web-socket-server-and-transport.test.js +++ b/test/e2e/web-socket-server-and-transport.test.js @@ -1,16 +1,16 @@ -'use strict'; - -const webpack = require('webpack'); -const Server = require('../../lib/Server'); -const WebsocketServer = require('../../lib/servers/WebsocketServer'); -const defaultConfig = require('../fixtures/provide-plugin-default/webpack.config'); -const sockjsConfig = require('../fixtures/provide-plugin-sockjs-config/webpack.config'); -const wsConfig = require('../fixtures/provide-plugin-ws-config/webpack.config'); -const customConfig = require('../fixtures/provide-plugin-custom/webpack.config'); -const runBrowser = require('../helpers/run-browser'); -const port = require('../ports-map')['web-socket-server-and-transport']; - -describe('web socket server and transport', () => { +"use strict"; + +const webpack = require("webpack"); +const Server = require("../../lib/Server"); +const WebsocketServer = require("../../lib/servers/WebsocketServer"); +const defaultConfig = require("../fixtures/provide-plugin-default/webpack.config"); +const sockjsConfig = require("../fixtures/provide-plugin-sockjs-config/webpack.config"); +const wsConfig = require("../fixtures/provide-plugin-ws-config/webpack.config"); +const customConfig = require("../fixtures/provide-plugin-custom/webpack.config"); +const runBrowser = require("../helpers/run-browser"); +const port = require("../ports-map")["web-socket-server-and-transport"]; + +describe("web socket server and transport", () => { it('should use default web socket server ("ws")', async () => { const compiler = webpack(defaultConfig); const devServerOptions = { @@ -34,12 +34,12 @@ describe('web socket server and transport', () => { const consoleMessages = []; - page.on('console', (message) => { + page.on("console", (message) => { consoleMessages.push(message); }); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const isCorrectTransport = await page.evaluate( @@ -62,7 +62,7 @@ describe('web socket server and transport', () => { const compiler = webpack(defaultConfig); const devServerOptions = { port, - webSocketServer: 'ws', + webSocketServer: "ws", }; const server = new Server(devServerOptions, compiler); @@ -82,12 +82,12 @@ describe('web socket server and transport', () => { const consoleMessages = []; - page.on('console', (message) => { + page.on("console", (message) => { consoleMessages.push(message); }); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const isCorrectTransport = await page.evaluate( @@ -111,7 +111,7 @@ describe('web socket server and transport', () => { const devServerOptions = { port, webSocketServer: { - type: 'ws', + type: "ws", }, }; const server = new Server(devServerOptions, compiler); @@ -132,12 +132,12 @@ describe('web socket server and transport', () => { const consoleMessages = []; - page.on('console', (message) => { + page.on("console", (message) => { consoleMessages.push(message); }); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const isCorrectTransport = await page.evaluate( @@ -160,7 +160,7 @@ describe('web socket server and transport', () => { const compiler = webpack(sockjsConfig); const devServerOptions = { port, - webSocketServer: 'sockjs', + webSocketServer: "sockjs", }; const server = new Server(devServerOptions, compiler); @@ -180,12 +180,12 @@ describe('web socket server and transport', () => { const consoleMessages = []; - page.on('console', (message) => { + page.on("console", (message) => { consoleMessages.push(message); }); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const isCorrectTransport = await page.evaluate( @@ -209,7 +209,7 @@ describe('web socket server and transport', () => { const devServerOptions = { port, webSocketServer: { - type: 'sockjs', + type: "sockjs", }, }; const server = new Server(devServerOptions, compiler); @@ -230,12 +230,12 @@ describe('web socket server and transport', () => { const consoleMessages = []; - page.on('console', (message) => { + page.on("console", (message) => { consoleMessages.push(message); }); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const isCorrectTransport = await page.evaluate( @@ -254,12 +254,12 @@ describe('web socket server and transport', () => { }); }); - it('should use custom web socket server when specify class', async () => { + it("should use custom web socket server when specify class", async () => { const compiler = webpack(defaultConfig); const devServerOptions = { port, client: { - webSocketTransport: 'ws', + webSocketTransport: "ws", }, webSocketServer: WebsocketServer, }; @@ -281,12 +281,12 @@ describe('web socket server and transport', () => { const consoleMessages = []; - page.on('console', (message) => { + page.on("console", (message) => { consoleMessages.push(message); }); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const isCorrectTransport = await page.evaluate( @@ -305,12 +305,12 @@ describe('web socket server and transport', () => { }); }); - it('should use custom web socket server when specify class using object', async () => { + it("should use custom web socket server when specify class using object", async () => { const compiler = webpack(defaultConfig); const devServerOptions = { port, client: { - webSocketTransport: 'ws', + webSocketTransport: "ws", }, webSocketServer: { type: WebsocketServer, @@ -334,12 +334,12 @@ describe('web socket server and transport', () => { const consoleMessages = []; - page.on('console', (message) => { + page.on("console", (message) => { consoleMessages.push(message); }); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const isCorrectTransport = await page.evaluate( @@ -358,14 +358,14 @@ describe('web socket server and transport', () => { }); }); - it('should use custom web socket server when specify path to class', async () => { + it("should use custom web socket server when specify path to class", async () => { const compiler = webpack(defaultConfig); const devServerOptions = { port, client: { - webSocketTransport: 'ws', + webSocketTransport: "ws", }, - webSocketServer: require.resolve('../../lib/servers/WebsocketServer'), + webSocketServer: require.resolve("../../lib/servers/WebsocketServer"), }; const server = new Server(devServerOptions, compiler); @@ -385,12 +385,12 @@ describe('web socket server and transport', () => { const consoleMessages = []; - page.on('console', (message) => { + page.on("console", (message) => { consoleMessages.push(message); }); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const isCorrectTransport = await page.evaluate( @@ -409,15 +409,15 @@ describe('web socket server and transport', () => { }); }); - it('should use custom web socket server when specify path to class using object', async () => { + it("should use custom web socket server when specify path to class using object", async () => { const compiler = webpack(defaultConfig); const devServerOptions = { port, client: { - webSocketTransport: 'ws', + webSocketTransport: "ws", }, webSocketServer: { - type: require.resolve('../../lib/servers/WebsocketServer'), + type: require.resolve("../../lib/servers/WebsocketServer"), }, }; const server = new Server(devServerOptions, compiler); @@ -438,12 +438,12 @@ describe('web socket server and transport', () => { const consoleMessages = []; - page.on('console', (message) => { + page.on("console", (message) => { consoleMessages.push(message); }); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const isCorrectTransport = await page.evaluate( @@ -462,14 +462,14 @@ describe('web socket server and transport', () => { }); }); - it('should throw an error on wrong path', async () => { + it("should throw an error on wrong path", async () => { expect.assertions(1); const compiler = webpack(defaultConfig); const devServerOptions = { port, webSocketServer: { - type: '/bad/path/to/implementation', + type: "/bad/path/to/implementation", }, }; const server = new Server(devServerOptions, compiler); @@ -502,7 +502,7 @@ describe('web socket server and transport', () => { const devServerOptions = { port, client: { - webSocketTransport: 'sockjs', + webSocketTransport: "sockjs", }, }; const server = new Server(devServerOptions, compiler); @@ -523,12 +523,12 @@ describe('web socket server and transport', () => { const consoleMessages = []; - page.on('console', (message) => { + page.on("console", (message) => { consoleMessages.push(message); }); await page.goto(`http://localhost:${port}/main.js`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const isCorrectTransport = await page.evaluate( @@ -552,7 +552,7 @@ describe('web socket server and transport', () => { const devServerOptions = { port, client: { - webSocketTransport: 'ws', + webSocketTransport: "ws", }, }; const server = new Server(devServerOptions, compiler); @@ -573,12 +573,12 @@ describe('web socket server and transport', () => { const consoleMessages = []; - page.on('console', (message) => { + page.on("console", (message) => { consoleMessages.push(message); }); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const isCorrectTransport = await page.evaluate( @@ -602,9 +602,9 @@ describe('web socket server and transport', () => { const devServerOptions = { port, client: { - webSocketTransport: 'sockjs', + webSocketTransport: "sockjs", }, - webSocketServer: 'sockjs', + webSocketServer: "sockjs", }; const server = new Server(devServerOptions, compiler); @@ -624,12 +624,12 @@ describe('web socket server and transport', () => { const consoleMessages = []; - page.on('console', (message) => { + page.on("console", (message) => { consoleMessages.push(message); }); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const isCorrectTransport = await page.evaluate( @@ -653,9 +653,9 @@ describe('web socket server and transport', () => { const devServerOptions = { port, client: { - webSocketTransport: 'ws', + webSocketTransport: "ws", }, - webSocketServer: 'ws', + webSocketServer: "ws", }; const server = new Server(devServerOptions, compiler); @@ -675,12 +675,12 @@ describe('web socket server and transport', () => { const consoleMessages = []; - page.on('console', (message) => { + page.on("console", (message) => { consoleMessages.push(message); }); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const isCorrectTransport = await page.evaluate( @@ -705,10 +705,10 @@ describe('web socket server and transport', () => { port, client: { webSocketTransport: require.resolve( - '../fixtures/custom-client/CustomSockJSClient' + "../fixtures/custom-client/CustomSockJSClient" ), }, - webSocketServer: 'sockjs', + webSocketServer: "sockjs", }; const server = new Server(devServerOptions, compiler); @@ -728,12 +728,12 @@ describe('web socket server and transport', () => { const consoleMessages = []; - page.on('console', (message) => { + page.on("console", (message) => { consoleMessages.push(message); }); await page.goto(`http://localhost:${port}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const isCorrectTransport = await page.evaluate( diff --git a/test/e2e/web-socket-server-url.test.js b/test/e2e/web-socket-server-url.test.js index 77b613c613..ed07304223 100644 --- a/test/e2e/web-socket-server-url.test.js +++ b/test/e2e/web-socket-server-url.test.js @@ -1,22 +1,22 @@ -'use strict'; +"use strict"; -const express = require('express'); -const webpack = require('webpack'); -const internalIp = require('internal-ip'); -const { createProxyMiddleware } = require('http-proxy-middleware'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/client-config/webpack.config'); -const runBrowser = require('../helpers/run-browser'); -const [port1, port2] = require('../ports-map')['web-socket-server-url']; +const express = require("express"); +const webpack = require("webpack"); +const internalIp = require("internal-ip"); +const { createProxyMiddleware } = require("http-proxy-middleware"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/client-config/webpack.config"); +const runBrowser = require("../helpers/run-browser"); +const [port1, port2] = require("../ports-map")["web-socket-server-url"]; -const webSocketServers = ['ws', 'sockjs']; +const webSocketServers = ["ws", "sockjs"]; -describe('web socket server URL', () => { +describe("web socket server URL", () => { for (const webSocketServer of webSocketServers) { - const websocketURLProtocol = webSocketServer === 'ws' ? 'ws' : 'http'; + const websocketURLProtocol = webSocketServer === "ws" ? "ws" : "http"; it(`should work behind proxy, when hostnames are same and ports are different ("${webSocketServer}")`, async () => { - const devServerHost = '127.0.0.1'; + const devServerHost = "127.0.0.1"; const devServerPort = port1; const proxyHost = devServerHost; const proxyPort = port2; @@ -26,7 +26,7 @@ describe('web socket server URL', () => { webSocketServer, port: devServerPort, host: devServerHost, - allowedHosts: 'all', + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -45,12 +45,12 @@ describe('web socket server URL', () => { function startProxy(callback) { const app = express(); app.use( - '/', + "/", createProxyMiddleware({ target: `http://${devServerHost}:${devServerPort}`, ws: true, changeOrigin: true, - logLevel: 'warn', + logLevel: "warn", }) ); @@ -69,23 +69,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -93,7 +93,7 @@ describe('web socket server URL', () => { } await page.goto(`http://${proxyHost}:${proxyPort}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -102,9 +102,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://${devServerHost}:${devServerPort}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); proxy.close(); await browser.close(); @@ -122,7 +122,7 @@ describe('web socket server URL', () => { }); it(`should work behind proxy, when hostnames are different and ports are same ("${webSocketServer}")`, async () => { - const devServerHost = '127.0.0.1'; + const devServerHost = "127.0.0.1"; const devServerPort = port1; const proxyHost = internalIp.v4.sync(); const proxyPort = port1; @@ -132,7 +132,7 @@ describe('web socket server URL', () => { webSocketServer, port: devServerPort, host: devServerHost, - allowedHosts: 'all', + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -151,12 +151,12 @@ describe('web socket server URL', () => { function startProxy(callback) { const app = express(); app.use( - '/', + "/", createProxyMiddleware({ target: `http://${devServerHost}:${devServerPort}`, ws: true, changeOrigin: true, - logLevel: 'warn', + logLevel: "warn", }) ); @@ -175,23 +175,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -199,7 +199,7 @@ describe('web socket server URL', () => { } await page.goto(`http://${proxyHost}:${proxyPort}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -208,9 +208,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://${devServerHost}:${devServerPort}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); proxy.close(); await browser.close(); @@ -228,7 +228,7 @@ describe('web socket server URL', () => { }); it(`should work behind proxy, when hostnames are different and ports are different ("${webSocketServer}")`, async () => { - const devServerHost = '127.0.0.1'; + const devServerHost = "127.0.0.1"; const devServerPort = port1; const proxyHost = internalIp.v4.sync(); const proxyPort = port2; @@ -243,7 +243,7 @@ describe('web socket server URL', () => { webSocketServer, port: devServerPort, host: devServerHost, - allowedHosts: 'all', + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -262,12 +262,12 @@ describe('web socket server URL', () => { function startProxy(callback) { const app = express(); app.use( - '/', + "/", createProxyMiddleware({ target: `http://${devServerHost}:${devServerPort}`, ws: true, changeOrigin: true, - logLevel: 'warn', + logLevel: "warn", }) ); @@ -286,23 +286,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -310,7 +310,7 @@ describe('web socket server URL', () => { } await page.goto(`http://${proxyHost}:${proxyPort}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -319,9 +319,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://${devServerHost}:${devServerPort}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); proxy.close(); @@ -348,9 +348,9 @@ describe('web socket server URL', () => { const compiler = webpack(config); const devServerOptions = { webSocketServer, - port: 'auto', - host: 'local-ip', - allowedHosts: 'all', + port: "auto", + host: "local-ip", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -373,12 +373,12 @@ describe('web socket server URL', () => { const app = express(); app.use( - '/', + "/", createProxyMiddleware({ target: `http://${resolvedHost}:${resolvedPort}`, ws: true, changeOrigin: true, - logLevel: 'warn', + logLevel: "warn", }) ); @@ -397,23 +397,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -421,7 +421,7 @@ describe('web socket server URL', () => { } await page.goto(`http://${proxyHost}:${proxyPort}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -430,9 +430,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://${resolvedHost}:${resolvedPort}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); proxy.close(); @@ -457,13 +457,13 @@ describe('web socket server URL', () => { const devServerOptions = { client: { webSocketURL: { - protocol: 'ws:', + protocol: "ws:", }, }, webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -485,23 +485,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -509,7 +509,7 @@ describe('web socket server URL', () => { } await page.goto(`http://localhost:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -518,9 +518,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://localhost:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -541,13 +541,13 @@ describe('web socket server URL', () => { const devServerOptions = { client: { webSocketURL: { - protocol: 'auto:', + protocol: "auto:", }, }, webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -569,23 +569,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -593,7 +593,7 @@ describe('web socket server URL', () => { } await page.goto(`http://localhost:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -602,9 +602,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://localhost:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -625,13 +625,13 @@ describe('web socket server URL', () => { const devServerOptions = { client: { webSocketURL: { - protocol: 'http:', + protocol: "http:", }, }, webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -653,23 +653,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -677,7 +677,7 @@ describe('web socket server URL', () => { } await page.goto(`http://localhost:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -686,9 +686,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://localhost:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -709,13 +709,13 @@ describe('web socket server URL', () => { const devServerOptions = { client: { webSocketURL: { - hostname: '127.0.0.1', + hostname: "127.0.0.1", }, }, webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -737,23 +737,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -761,7 +761,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -770,9 +770,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://127.0.0.1:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -793,13 +793,13 @@ describe('web socket server URL', () => { const devServerOptions = { client: { webSocketURL: { - hostname: '0.0.0.0', + hostname: "0.0.0.0", }, }, webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -821,23 +821,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -845,7 +845,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -854,9 +854,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://127.0.0.1:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -882,8 +882,8 @@ describe('web socket server URL', () => { }, webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -905,23 +905,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -929,7 +929,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -938,9 +938,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://127.0.0.1:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -966,8 +966,8 @@ describe('web socket server URL', () => { }, webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -989,23 +989,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -1013,7 +1013,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -1022,9 +1022,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://127.0.0.1:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -1046,19 +1046,19 @@ describe('web socket server URL', () => { webSocketServer: { type: webSocketServer, options: { - host: '0.0.0.0', + host: "0.0.0.0", // "sockjs" doesn't support external server - port: webSocketServer === 'sockjs' ? `${port1}` : `${port2}`, + port: webSocketServer === "sockjs" ? `${port1}` : `${port2}`, }, }, port: port1, - host: '0.0.0.0', + host: "0.0.0.0", client: { webSocketURL: { - port: webSocketServer === 'sockjs' ? `${port1}` : `${port2}`, + port: webSocketServer === "sockjs" ? `${port1}` : `${port2}`, }, }, - allowedHosts: 'all', + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -1080,23 +1080,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -1104,20 +1104,20 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; expect(webSocketRequest.url).toContain( - webSocketServer === 'sockjs' + webSocketServer === "sockjs" ? `${websocketURLProtocol}://127.0.0.1:${port1}/ws` : `${websocketURLProtocol}://127.0.0.1:${port2}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -1143,8 +1143,8 @@ describe('web socket server URL', () => { }, webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -1166,23 +1166,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -1190,7 +1190,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -1199,9 +1199,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://127.0.0.1:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -1222,13 +1222,13 @@ describe('web socket server URL', () => { const devServerOptions = { client: { webSocketURL: { - pathname: '/ws', + pathname: "/ws", }, }, webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -1250,23 +1250,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -1274,7 +1274,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -1283,9 +1283,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://127.0.0.1:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -1306,8 +1306,8 @@ describe('web socket server URL', () => { const devServerOptions = { webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -1329,23 +1329,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -1353,7 +1353,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -1362,9 +1362,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://127.0.0.1:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -1385,13 +1385,13 @@ describe('web socket server URL', () => { const devServerOptions = { client: { webSocketURL: { - username: 'zenitsu', + username: "zenitsu", }, }, webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -1413,23 +1413,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -1437,7 +1437,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -1446,9 +1446,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://zenitsu@127.0.0.1:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -1469,17 +1469,17 @@ describe('web socket server URL', () => { const devServerOptions = { client: { webSocketURL: - webSocketServer === 'ws' + webSocketServer === "ws" ? { - username: 'foo', - password: 'chuntaro', + username: "foo", + password: "chuntaro", } : {}, }, webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -1501,23 +1501,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -1525,21 +1525,21 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; expect(webSocketRequest.url).toContain( // "sockjs" has bug with parsing URL - webSocketServer === 'ws' + webSocketServer === "ws" ? `${websocketURLProtocol}://foo:chuntaro@127.0.0.1:${port1}/ws` : `${websocketURLProtocol}://127.0.0.1:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -1560,14 +1560,14 @@ describe('web socket server URL', () => { const devServerOptions = { client: { webSocketURL: { - username: 'zenitsu', - password: 'chuntaro', + username: "zenitsu", + password: "chuntaro", }, }, webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -1589,23 +1589,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -1613,7 +1613,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -1622,9 +1622,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://zenitsu:chuntaro@127.0.0.1:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -1646,12 +1646,12 @@ describe('web socket server URL', () => { webSocketServer: { type: webSocketServer, options: { - path: '/custom-ws/foo/bar', + path: "/custom-ws/foo/bar", }, }, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -1673,23 +1673,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/custom-ws\/foo\/bar/.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -1697,7 +1697,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -1706,9 +1706,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://127.0.0.1:${port1}/custom-ws/foo/bar` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -1731,12 +1731,12 @@ describe('web socket server URL', () => { webSocketServer: { type: webSocketServer, options: { - path: webSocketServer === 'ws' ? '' : '/custom-ws', + path: webSocketServer === "ws" ? "" : "/custom-ws", }, }, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -1758,23 +1758,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/custom-ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -1782,20 +1782,20 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; expect(webSocketRequest.url).toContain( - webSocketServer === 'ws' + webSocketServer === "ws" ? `${websocketURLProtocol}://127.0.0.1:${port1}` : `${websocketURLProtocol}://127.0.0.1:${port1}/custom-ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -1816,18 +1816,18 @@ describe('web socket server URL', () => { const devServerOptions = { client: { webSocketURL: { - pathname: '/custom-ws/foo/bar', + pathname: "/custom-ws/foo/bar", }, }, webSocketServer: { type: webSocketServer, options: { - path: '/custom-ws/foo/bar', + path: "/custom-ws/foo/bar", }, }, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -1849,23 +1849,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/custom-ws\/foo\/bar/.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -1873,7 +1873,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -1882,9 +1882,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://127.0.0.1:${port1}/custom-ws/foo/bar` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -1905,18 +1905,18 @@ describe('web socket server URL', () => { const devServerOptions = { client: { webSocketURL: { - pathname: '/custom-ws', + pathname: "/custom-ws", }, }, webSocketServer: { type: webSocketServer, options: { - path: '/custom-ws', + path: "/custom-ws", }, }, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -1938,23 +1938,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/custom-ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -1962,7 +1962,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -1971,9 +1971,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://127.0.0.1:${port1}/custom-ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -1995,18 +1995,18 @@ describe('web socket server URL', () => { const devServerOptions = { client: { webSocketURL: { - pathname: webSocketServer === 'ws' ? '/custom-ws/' : '/custom-ws', + pathname: webSocketServer === "ws" ? "/custom-ws/" : "/custom-ws", }, }, webSocketServer: { type: webSocketServer, options: { - path: webSocketServer === 'ws' ? '/custom-ws/' : '/custom-ws', + path: webSocketServer === "ws" ? "/custom-ws/" : "/custom-ws", }, }, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -2028,23 +2028,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/custom-ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -2052,7 +2052,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -2061,9 +2061,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://127.0.0.1:${port1}/custom-ws/` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -2085,18 +2085,18 @@ describe('web socket server URL', () => { const devServerOptions = { client: { webSocketURL: { - pathname: webSocketServer === 'ws' ? '' : '/custom-ws', + pathname: webSocketServer === "ws" ? "" : "/custom-ws", }, }, webSocketServer: { type: webSocketServer, options: { - path: webSocketServer === 'ws' ? '' : '/custom-ws', + path: webSocketServer === "ws" ? "" : "/custom-ws", }, }, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -2118,23 +2118,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/custom-ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -2142,20 +2142,20 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; expect(webSocketRequest.url).toContain( - webSocketServer === 'ws' + webSocketServer === "ws" ? `${websocketURLProtocol}://127.0.0.1:${port1}` : `${websocketURLProtocol}://127.0.0.1:${port1}/custom-ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -2177,19 +2177,19 @@ describe('web socket server URL', () => { const devServerOptions = { client: { webSocketURL: { - pathname: '/custom-ws', + pathname: "/custom-ws", }, }, webSocketServer: { type: webSocketServer, options: - webSocketServer === 'ws' - ? { path: '/custom-ws' } - : { prefix: '/custom-ws' }, + webSocketServer === "ws" + ? { path: "/custom-ws" } + : { prefix: "/custom-ws" }, }, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -2211,23 +2211,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/custom-ws/.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -2235,7 +2235,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -2244,9 +2244,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://127.0.0.1:${port1}/custom-ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -2290,23 +2290,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -2314,7 +2314,7 @@ describe('web socket server URL', () => { } await page.goto(`http://${hostname}:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -2323,9 +2323,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://${hostname}:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -2347,7 +2347,7 @@ describe('web socket server URL', () => { const devServerOptions = { webSocketServer, port: port1, - host: 'local-ip', + host: "local-ip", }; const server = new Server(devServerOptions, compiler); @@ -2369,23 +2369,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -2393,7 +2393,7 @@ describe('web socket server URL', () => { } await page.goto(`http://${hostname}:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -2402,9 +2402,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://${hostname}:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -2426,7 +2426,7 @@ describe('web socket server URL', () => { const devServerOptions = { webSocketServer, port: port1, - host: 'local-ipv4', + host: "local-ipv4", }; const server = new Server(devServerOptions, compiler); @@ -2448,23 +2448,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -2472,7 +2472,7 @@ describe('web socket server URL', () => { } await page.goto(`http://${hostname}:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -2481,9 +2481,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://${hostname}:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -2505,8 +2505,8 @@ describe('web socket server URL', () => { const compiler = webpack(config); const devServerOptions = { webSocketServer, - port: 'auto', - host: '0.0.0.0', + port: "auto", + host: "0.0.0.0", }; const server = new Server(devServerOptions, compiler); @@ -2530,23 +2530,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (request) => { + client.on("Network.webSocketCreated", (request) => { webSocketRequests.push(request); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -2554,7 +2554,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${resolvedFreePort}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -2563,9 +2563,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://127.0.0.1:${resolvedFreePort}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -2588,16 +2588,16 @@ describe('web socket server URL', () => { const devServerOptions = { client: { webSocketURL: { - protocol: 'ws:', - hostname: '127.0.0.1', + protocol: "ws:", + hostname: "127.0.0.1", port: port1, - pathname: '/ws', + pathname: "/ws", }, }, webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -2619,23 +2619,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -2643,7 +2643,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -2652,9 +2652,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://127.0.0.1:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -2678,8 +2678,8 @@ describe('web socket server URL', () => { }, webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -2701,23 +2701,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); const webSocketRequests = []; - if (webSocketServer === 'ws') { + if (webSocketServer === "ws") { const client = page._client; - client.on('Network.webSocketCreated', (test) => { + client.on("Network.webSocketCreated", (test) => { webSocketRequests.push(test); }); } else { - page.on('request', (request) => { + page.on("request", (request) => { if (/\/ws\//.test(request.url())) { webSocketRequests.push({ url: request.url() }); } @@ -2725,7 +2725,7 @@ describe('web socket server URL', () => { } await page.goto(`http://127.0.0.1:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); const webSocketRequest = webSocketRequests[0]; @@ -2734,9 +2734,9 @@ describe('web socket server URL', () => { `${websocketURLProtocol}://127.0.0.1:${port1}/ws` ); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); - expect(pageErrors).toMatchSnapshot('page errors'); + expect(pageErrors).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -2756,12 +2756,12 @@ describe('web socket server URL', () => { const compiler = webpack(config); const devServerOptions = { client: { - webSocketURL: 'unknown://unknown.unknown/unknown', + webSocketURL: "unknown://unknown.unknown/unknown", }, webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -2783,23 +2783,23 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); await page.goto(`http://localhost:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages' + "console messages" ); expect( - pageErrors.map((pageError) => pageError.message.split('\n')[0]) - ).toMatchSnapshot('page errors'); + pageErrors.map((pageError) => pageError.message.split("\n")[0]) + ).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { @@ -2819,12 +2819,12 @@ describe('web socket server URL', () => { const compiler = webpack(config); const devServerOptions = { client: { - webSocketURL: 'ws://unknown.unknown/unknown', + webSocketURL: "ws://unknown.unknown/unknown", }, webSocketServer, port: port1, - host: '0.0.0.0', - allowedHosts: 'all', + host: "0.0.0.0", + allowedHosts: "all", }; const server = new Server(devServerOptions, compiler); @@ -2846,25 +2846,25 @@ describe('web socket server URL', () => { const consoleMessages = []; page - .on('console', (message) => { + .on("console", (message) => { consoleMessages.push(message); }) - .on('pageerror', (error) => { + .on("pageerror", (error) => { pageErrors.push(error); }); await page.goto(`http://localhost:${port1}/main`, { - waitUntil: 'networkidle0', + waitUntil: "networkidle0", }); expect( consoleMessages.map((message) => - message.text().replace(/:[\d]+/g, ':') + message.text().replace(/:[\d]+/g, ":") ) - ).toMatchSnapshot('console messages'); + ).toMatchSnapshot("console messages"); expect( - pageErrors.map((pageError) => pageError.message.split('\n')[0]) - ).toMatchSnapshot('page errors'); + pageErrors.map((pageError) => pageError.message.split("\n")[0]) + ).toMatchSnapshot("page errors"); await browser.close(); await new Promise((resolve, reject) => { diff --git a/test/fixtures/cli-colors-default-stats/foo.js b/test/fixtures/cli-colors-default-stats/foo.js index f88d8b5040..5940e9197c 100644 --- a/test/fixtures/cli-colors-default-stats/foo.js +++ b/test/fixtures/cli-colors-default-stats/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('i am foo!'); +console.log("i am foo!"); diff --git a/test/fixtures/cli-colors-default-stats/webpack.config.js b/test/fixtures/cli-colors-default-stats/webpack.config.js index 4e4bf0d660..85b1edd43c 100644 --- a/test/fixtures/cli-colors-default-stats/webpack.config.js +++ b/test/fixtures/cli-colors-default-stats/webpack.config.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; -const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); +const ExitOnDonePlugin = require("../../helpers/ExitOnDonePlugin"); module.exports = { - mode: 'development', + mode: "development", context: __dirname, - entry: './foo.js', + entry: "./foo.js", plugins: [ExitOnDonePlugin], }; diff --git a/test/fixtures/cli-colors-disabled/foo.js b/test/fixtures/cli-colors-disabled/foo.js index f88d8b5040..5940e9197c 100644 --- a/test/fixtures/cli-colors-disabled/foo.js +++ b/test/fixtures/cli-colors-disabled/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('i am foo!'); +console.log("i am foo!"); diff --git a/test/fixtures/cli-colors-disabled/webpack.config.js b/test/fixtures/cli-colors-disabled/webpack.config.js index 8edb25ec41..d9e3c7347c 100644 --- a/test/fixtures/cli-colors-disabled/webpack.config.js +++ b/test/fixtures/cli-colors-disabled/webpack.config.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); +const ExitOnDonePlugin = require("../../helpers/ExitOnDonePlugin"); module.exports = { - mode: 'development', + mode: "development", stats: { colors: false, }, context: __dirname, - entry: './foo.js', + entry: "./foo.js", plugins: [ExitOnDonePlugin], }; diff --git a/test/fixtures/cli-colors-enabled/foo.js b/test/fixtures/cli-colors-enabled/foo.js index f88d8b5040..5940e9197c 100644 --- a/test/fixtures/cli-colors-enabled/foo.js +++ b/test/fixtures/cli-colors-enabled/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('i am foo!'); +console.log("i am foo!"); diff --git a/test/fixtures/cli-colors-enabled/webpack.config.js b/test/fixtures/cli-colors-enabled/webpack.config.js index e4dc935a8d..09fe154f0a 100644 --- a/test/fixtures/cli-colors-enabled/webpack.config.js +++ b/test/fixtures/cli-colors-enabled/webpack.config.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); +const ExitOnDonePlugin = require("../../helpers/ExitOnDonePlugin"); module.exports = { - mode: 'development', + mode: "development", stats: { colors: true, }, context: __dirname, - entry: './foo.js', + entry: "./foo.js", plugins: [ExitOnDonePlugin], }; diff --git a/test/fixtures/cli/foo.js b/test/fixtures/cli/foo.js index f88d8b5040..5940e9197c 100644 --- a/test/fixtures/cli/foo.js +++ b/test/fixtures/cli/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('i am foo!'); +console.log("i am foo!"); diff --git a/test/fixtures/cli/webpack.config.js b/test/fixtures/cli/webpack.config.js index 46ad3c051a..c4c5c6fcf5 100644 --- a/test/fixtures/cli/webpack.config.js +++ b/test/fixtures/cli/webpack.config.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; -const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); +const ExitOnDonePlugin = require("../../helpers/ExitOnDonePlugin"); module.exports = { - mode: 'development', - stats: 'detailed', + mode: "development", + stats: "detailed", context: __dirname, - entry: './foo.js', + entry: "./foo.js", plugins: [ExitOnDonePlugin], }; diff --git a/test/fixtures/client-config/bar.js b/test/fixtures/client-config/bar.js index 7808a962d9..1ae523febc 100644 --- a/test/fixtures/client-config/bar.js +++ b/test/fixtures/client-config/bar.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('Bar.'); +console.log("Bar."); diff --git a/test/fixtures/client-config/foo.js b/test/fixtures/client-config/foo.js index eab26534f3..3c915dbcb8 100644 --- a/test/fixtures/client-config/foo.js +++ b/test/fixtures/client-config/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('Hey.'); +console.log("Hey."); diff --git a/test/fixtures/client-config/index.html b/test/fixtures/client-config/index.html index fdfcaae91f..5b1eef4511 100644 --- a/test/fixtures/client-config/index.html +++ b/test/fixtures/client-config/index.html @@ -1 +1 @@ - \ No newline at end of file + diff --git a/test/fixtures/client-config/webpack.config.js b/test/fixtures/client-config/webpack.config.js index f988951467..7890aeee50 100644 --- a/test/fixtures/client-config/webpack.config.js +++ b/test/fixtures/client-config/webpack.config.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; const HTMLContent = ` @@ -12,21 +12,21 @@ const HTMLContent = ` `; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { - path: '/', + path: "/", }, infrastructureLogging: { - level: 'warn', + level: "warn", }, plugins: [ { apply(compiler) { - const pluginName = 'html-generator-plugin-test'; - const filename = 'test.html'; + const pluginName = "html-generator-plugin-test"; + const filename = "test.html"; compiler.hooks.thisCompilation.tap(pluginName, (compilation) => { if (compiler.webpack) { diff --git a/test/fixtures/contentbase-config/foo.js b/test/fixtures/contentbase-config/foo.js index eab26534f3..3c915dbcb8 100644 --- a/test/fixtures/contentbase-config/foo.js +++ b/test/fixtures/contentbase-config/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('Hey.'); +console.log("Hey."); diff --git a/test/fixtures/contentbase-config/webpack.config.js b/test/fixtures/contentbase-config/webpack.config.js index 887f1658d4..e0a2dfdbd5 100644 --- a/test/fixtures/contentbase-config/webpack.config.js +++ b/test/fixtures/contentbase-config/webpack.config.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { - publicPath: '/', + publicPath: "/", }, infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/custom-client/CustomSockJSClient.js b/test/fixtures/custom-client/CustomSockJSClient.js index 53f88bd713..a96b5c8c73 100644 --- a/test/fixtures/custom-client/CustomSockJSClient.js +++ b/test/fixtures/custom-client/CustomSockJSClient.js @@ -1,27 +1,27 @@ -'use strict'; +"use strict"; /* eslint-disable no-unused-vars */ -const SockJS = require('sockjs-client/dist/sockjs'); +const SockJS = require("sockjs-client/dist/sockjs"); module.exports = class SockJSClient { constructor(url) { this.sock = new SockJS( - url.replace(/^ws:/i, 'http://').replace(/^wss:/i, 'https://') + url.replace(/^ws:/i, "http://").replace(/^wss:/i, "https://") ); } onOpen(f) { this.sock.onopen = () => { - console.log('open'); + console.log("open"); f(); }; } onClose(f) { this.sock.onclose = () => { - console.log('close'); + console.log("close"); f(); }; } diff --git a/test/fixtures/dev-public-path/foo.js b/test/fixtures/dev-public-path/foo.js index f88d8b5040..5940e9197c 100644 --- a/test/fixtures/dev-public-path/foo.js +++ b/test/fixtures/dev-public-path/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('i am foo!'); +console.log("i am foo!"); diff --git a/test/fixtures/dev-public-path/webpack.config.js b/test/fixtures/dev-public-path/webpack.config.js index f48f87d4cc..2faa9805d1 100644 --- a/test/fixtures/dev-public-path/webpack.config.js +++ b/test/fixtures/dev-public-path/webpack.config.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const { join } = require('path'); +const { join } = require("path"); module.exports = { - mode: 'development', - entry: join(__dirname, 'foo.js'), + mode: "development", + entry: join(__dirname, "foo.js"), devServer: { devMiddleware: { - publicPath: '/foo/bar', + publicPath: "/foo/bar", }, }, }; diff --git a/test/fixtures/dev-server/bar.js b/test/fixtures/dev-server/bar.js index 22bcef09f7..fcd4a4e9a0 100644 --- a/test/fixtures/dev-server/bar.js +++ b/test/fixtures/dev-server/bar.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('I am bar'); +console.log("I am bar"); diff --git a/test/fixtures/dev-server/client-custom-path-config.js b/test/fixtures/dev-server/client-custom-path-config.js index 8dbca32089..1fd42a52d6 100644 --- a/test/fixtures/dev-server/client-custom-path-config.js +++ b/test/fixtures/dev-server/client-custom-path-config.js @@ -1,17 +1,17 @@ -'use strict'; +"use strict"; -const { resolve } = require('path'); -const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); +const { resolve } = require("path"); +const ExitOnDonePlugin = require("../../helpers/ExitOnDonePlugin"); module.exports = { - mode: 'development', - stats: 'detailed', - entry: resolve(__dirname, './foo.js'), + mode: "development", + stats: "detailed", + entry: resolve(__dirname, "./foo.js"), devServer: { webSocketServer: { - type: 'ws', + type: "ws", options: { - path: '/custom/path', + path: "/custom/path", }, }, }, diff --git a/test/fixtures/dev-server/client-default-path-config.js b/test/fixtures/dev-server/client-default-path-config.js index 40bd36db25..2b6af29942 100644 --- a/test/fixtures/dev-server/client-default-path-config.js +++ b/test/fixtures/dev-server/client-default-path-config.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; -const { resolve } = require('path'); -const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); +const { resolve } = require("path"); +const ExitOnDonePlugin = require("../../helpers/ExitOnDonePlugin"); module.exports = { - mode: 'development', - stats: 'detailed', - entry: resolve(__dirname, './foo.js'), + mode: "development", + stats: "detailed", + entry: resolve(__dirname, "./foo.js"), devServer: { webSocketServer: { - type: 'ws', + type: "ws", }, }, plugins: [ExitOnDonePlugin], diff --git a/test/fixtures/dev-server/default-config.js b/test/fixtures/dev-server/default-config.js index 38255f1e3c..caae096ccd 100644 --- a/test/fixtures/dev-server/default-config.js +++ b/test/fixtures/dev-server/default-config.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict"; -const { resolve } = require('path'); -const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); +const { resolve } = require("path"); +const ExitOnDonePlugin = require("../../helpers/ExitOnDonePlugin"); module.exports = { - mode: 'development', - stats: 'detailed', - entry: resolve(__dirname, './foo.js'), + mode: "development", + stats: "detailed", + entry: resolve(__dirname, "./foo.js"), devServer: { - webSocketServer: 'ws', + webSocketServer: "ws", }, plugins: [ExitOnDonePlugin], }; diff --git a/test/fixtures/dev-server/empty-entry.js b/test/fixtures/dev-server/empty-entry.js index ad06ad3136..3c9fb2642d 100644 --- a/test/fixtures/dev-server/empty-entry.js +++ b/test/fixtures/dev-server/empty-entry.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); +const ExitOnDonePlugin = require("../../helpers/ExitOnDonePlugin"); module.exports = { - mode: 'development', - stats: { orphanModules: true, preset: 'detailed' }, + mode: "development", + stats: { orphanModules: true, preset: "detailed" }, entry: {}, devServer: { - webSocketServer: 'ws', + webSocketServer: "ws", }, plugins: [ExitOnDonePlugin], }; diff --git a/test/fixtures/dev-server/foo.js b/test/fixtures/dev-server/foo.js index 051a2d2c21..f9e4e59568 100644 --- a/test/fixtures/dev-server/foo.js +++ b/test/fixtures/dev-server/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('I am foo'); +console.log("I am foo"); diff --git a/test/fixtures/dev-server/multi-entry.js b/test/fixtures/dev-server/multi-entry.js index 3705175f7c..4cddf673af 100644 --- a/test/fixtures/dev-server/multi-entry.js +++ b/test/fixtures/dev-server/multi-entry.js @@ -1,18 +1,18 @@ -'use strict'; +"use strict"; -const { resolve } = require('path'); -const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); +const { resolve } = require("path"); +const ExitOnDonePlugin = require("../../helpers/ExitOnDonePlugin"); module.exports = { - mode: 'development', - stats: 'detailed', + mode: "development", + stats: "detailed", context: __dirname, entry: { - foo: resolve(__dirname, './foo.js'), - bar: resolve(__dirname, './bar.js'), + foo: resolve(__dirname, "./foo.js"), + bar: resolve(__dirname, "./bar.js"), }, devServer: { - webSocketServer: 'ws', + webSocketServer: "ws", }, plugins: [ExitOnDonePlugin], }; diff --git a/test/fixtures/dev-server/target-config.js b/test/fixtures/dev-server/target-config.js index e489fb6206..efe9a01dac 100644 --- a/test/fixtures/dev-server/target-config.js +++ b/test/fixtures/dev-server/target-config.js @@ -1,20 +1,20 @@ -'use strict'; +"use strict"; -const { resolve } = require('path'); -const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); +const { resolve } = require("path"); +const ExitOnDonePlugin = require("../../helpers/ExitOnDonePlugin"); module.exports = { - mode: 'development', - stats: 'detailed', - entry: resolve(__dirname, './foo.js'), - target: ['web'], + mode: "development", + stats: "detailed", + entry: resolve(__dirname, "./foo.js"), + target: ["web"], output: { chunkLoading: false, wasmLoading: false, workerChunkLoading: false, }, devServer: { - webSocketServer: 'ws', + webSocketServer: "ws", }, plugins: [ExitOnDonePlugin], }; diff --git a/test/fixtures/entry-as-descriptor/foo.js b/test/fixtures/entry-as-descriptor/foo.js index f88d8b5040..5940e9197c 100644 --- a/test/fixtures/entry-as-descriptor/foo.js +++ b/test/fixtures/entry-as-descriptor/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('i am foo!'); +console.log("i am foo!"); diff --git a/test/fixtures/entry-as-descriptor/webpack.config.js b/test/fixtures/entry-as-descriptor/webpack.config.js index 5429420f9e..e287b2135a 100644 --- a/test/fixtures/entry-as-descriptor/webpack.config.js +++ b/test/fixtures/entry-as-descriptor/webpack.config.js @@ -1,17 +1,17 @@ -'use strict'; +"use strict"; -const ExitOnDonePlugin = require('../../helpers/ExitOnDonePlugin'); +const ExitOnDonePlugin = require("../../helpers/ExitOnDonePlugin"); module.exports = { - mode: 'development', + mode: "development", context: __dirname, entry: { main: { - import: './foo.js', + import: "./foo.js", }, }, plugins: [ExitOnDonePlugin], infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/entry-as-function/foo.js b/test/fixtures/entry-as-function/foo.js index f88d8b5040..5940e9197c 100644 --- a/test/fixtures/entry-as-function/foo.js +++ b/test/fixtures/entry-as-function/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('i am foo!'); +console.log("i am foo!"); diff --git a/test/fixtures/entry-as-function/webpack.config.js b/test/fixtures/entry-as-function/webpack.config.js index d7e2e488be..cf48f0b924 100644 --- a/test/fixtures/entry-as-function/webpack.config.js +++ b/test/fixtures/entry-as-function/webpack.config.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - entry: () => './foo.js', + entry: () => "./foo.js", plugins: [ { apply(compiler) { - compiler.hooks.done.tap('webpack-dev-server', (stats) => { + compiler.hooks.done.tap("webpack-dev-server", (stats) => { let exitCode = 0; if (stats.hasErrors()) { exitCode = 1; @@ -18,6 +18,6 @@ module.exports = { }, ], infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/historyapifallback-2-config/foo.js b/test/fixtures/historyapifallback-2-config/foo.js index 91bd211ea9..34a6319b28 100644 --- a/test/fixtures/historyapifallback-2-config/foo.js +++ b/test/fixtures/historyapifallback-2-config/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('Hey.'); // eslint-disable-line +console.log("Hey."); // eslint-disable-line diff --git a/test/fixtures/historyapifallback-2-config/webpack.config.js b/test/fixtures/historyapifallback-2-config/webpack.config.js index 386d693e66..f03898aa61 100644 --- a/test/fixtures/historyapifallback-2-config/webpack.config.js +++ b/test/fixtures/historyapifallback-2-config/webpack.config.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { - path: '/', + path: "/", }, infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/historyapifallback-3-config/foo.js b/test/fixtures/historyapifallback-3-config/foo.js index e4a61c5582..588bdc3f47 100644 --- a/test/fixtures/historyapifallback-3-config/foo.js +++ b/test/fixtures/historyapifallback-3-config/foo.js @@ -1,5 +1,5 @@ -'use strict'; +"use strict"; -require('./bar.html'); +require("./bar.html"); -console.log('Hey.'); // eslint-disable-line +console.log("Hey."); // eslint-disable-line diff --git a/test/fixtures/historyapifallback-3-config/webpack.config.js b/test/fixtures/historyapifallback-3-config/webpack.config.js index a9cf1ce7eb..4c15e3556d 100644 --- a/test/fixtures/historyapifallback-3-config/webpack.config.js +++ b/test/fixtures/historyapifallback-3-config/webpack.config.js @@ -1,23 +1,23 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { - path: '/', + path: "/", }, module: { rules: [ { test: /\.html$/, - loader: 'file-loader', - options: { name: 'index.html' }, + loader: "file-loader", + options: { name: "index.html" }, }, ], }, infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/historyapifallback-config/foo.js b/test/fixtures/historyapifallback-config/foo.js index 73ab342060..d6a182976d 100644 --- a/test/fixtures/historyapifallback-config/foo.js +++ b/test/fixtures/historyapifallback-config/foo.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -require('./index.html'); -require('./bar.html'); +require("./index.html"); +require("./bar.html"); -console.log('Hey.'); // eslint-disable-line +console.log("Hey."); // eslint-disable-line diff --git a/test/fixtures/historyapifallback-config/webpack.config.js b/test/fixtures/historyapifallback-config/webpack.config.js index 4abe2f4a5c..12c36e5dc1 100644 --- a/test/fixtures/historyapifallback-config/webpack.config.js +++ b/test/fixtures/historyapifallback-config/webpack.config.js @@ -1,23 +1,23 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { - path: '/', + path: "/", }, module: { rules: [ { test: /\.html$/, - loader: 'file-loader', - options: { name: '[name].[ext]' }, + loader: "file-loader", + options: { name: "[name].[ext]" }, }, ], }, infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/mime-types-config/foo.js b/test/fixtures/mime-types-config/foo.js index 8545da9fb8..739d9bd638 100644 --- a/test/fixtures/mime-types-config/foo.js +++ b/test/fixtures/mime-types-config/foo.js @@ -1,5 +1,5 @@ -'use strict'; +"use strict"; -require('./file.custom'); +require("./file.custom"); -console.log('Hey.'); +console.log("Hey."); diff --git a/test/fixtures/mime-types-config/webpack.config.js b/test/fixtures/mime-types-config/webpack.config.js index bcaa6cf477..6ef7234e41 100644 --- a/test/fixtures/mime-types-config/webpack.config.js +++ b/test/fixtures/mime-types-config/webpack.config.js @@ -1,16 +1,16 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { - path: '/', + path: "/", }, node: false, infrastructureLogging: { - level: 'warn', + level: "warn", }, module: { rules: [ @@ -18,10 +18,10 @@ module.exports = { test: /\.custom$/, use: [ { - loader: 'file-loader', + loader: "file-loader", options: { name() { - return '[name].[ext]'; + return "[name].[ext]"; }, }, }, diff --git a/test/fixtures/module-federation-config/entry1.js b/test/fixtures/module-federation-config/entry1.js index 2f7d8f60a2..dbd0f49a83 100644 --- a/test/fixtures/module-federation-config/entry1.js +++ b/test/fixtures/module-federation-config/entry1.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -module.exports = 'entry1'; +module.exports = "entry1"; diff --git a/test/fixtures/module-federation-config/entry2.js b/test/fixtures/module-federation-config/entry2.js index 1e5846db72..74f9bc577f 100644 --- a/test/fixtures/module-federation-config/entry2.js +++ b/test/fixtures/module-federation-config/entry2.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -module.exports = 'entry2'; +module.exports = "entry2"; diff --git a/test/fixtures/module-federation-config/webpack.config.js b/test/fixtures/module-federation-config/webpack.config.js index 41a00622c0..269e4cab41 100644 --- a/test/fixtures/module-federation-config/webpack.config.js +++ b/test/fixtures/module-federation-config/webpack.config.js @@ -1,16 +1,16 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', - target: 'node', - stats: 'none', + mode: "development", + target: "node", + stats: "none", context: __dirname, - entry: ['./entry1.js', './entry2.js'], + entry: ["./entry1.js", "./entry2.js"], output: { - path: '/', - libraryTarget: 'umd', + path: "/", + libraryTarget: "umd", }, infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/module-federation-config/webpack.multi.config.js b/test/fixtures/module-federation-config/webpack.multi.config.js index 2ab8465fcb..5863c8e14a 100644 --- a/test/fixtures/module-federation-config/webpack.multi.config.js +++ b/test/fixtures/module-federation-config/webpack.multi.config.js @@ -1,18 +1,18 @@ -'use strict'; +"use strict"; module.exports = [ { - mode: 'development', - target: 'node', + mode: "development", + target: "node", context: __dirname, - stats: 'none', - entry: ['./entry1.js', './entry2.js'], + stats: "none", + entry: ["./entry1.js", "./entry2.js"], output: { - path: '/', - libraryTarget: 'umd', + path: "/", + libraryTarget: "umd", }, infrastructureLogging: { - level: 'warn', + level: "warn", }, }, ]; diff --git a/test/fixtures/module-federation-config/webpack.object-entry.config.js b/test/fixtures/module-federation-config/webpack.object-entry.config.js index 08a4f3ebca..43c47a4183 100644 --- a/test/fixtures/module-federation-config/webpack.object-entry.config.js +++ b/test/fixtures/module-federation-config/webpack.object-entry.config.js @@ -1,19 +1,19 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', - target: 'node', - stats: 'none', + mode: "development", + target: "node", + stats: "none", context: __dirname, entry: { - foo: './entry1.js', - main: ['./entry1.js', './entry2.js'], + foo: "./entry1.js", + main: ["./entry1.js", "./entry2.js"], }, output: { - path: '/', - libraryTarget: 'umd', + path: "/", + libraryTarget: "umd", }, infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/module-federation-config/webpack.plugin.js b/test/fixtures/module-federation-config/webpack.plugin.js index 6a064ca1ed..9178e3c600 100644 --- a/test/fixtures/module-federation-config/webpack.plugin.js +++ b/test/fixtures/module-federation-config/webpack.plugin.js @@ -1,25 +1,25 @@ -'use strict'; +"use strict"; const ModuleFederationPlugin = - require('webpack').container.ModuleFederationPlugin; + require("webpack").container.ModuleFederationPlugin; module.exports = { - mode: 'development', - target: 'node', - stats: 'none', + mode: "development", + target: "node", + stats: "none", context: __dirname, - entry: ['./entry1.js'], + entry: ["./entry1.js"], plugins: [ new ModuleFederationPlugin({ - name: 'app1', - library: { type: 'var', name: 'app1' }, - filename: 'remoteEntry.js', + name: "app1", + library: { type: "var", name: "app1" }, + filename: "remoteEntry.js", exposes: { - './entry1': './entry1', + "./entry1": "./entry1", }, }), ], infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/multi-compiler-2-config/foo.js b/test/fixtures/multi-compiler-2-config/foo.js index eab26534f3..3c915dbcb8 100644 --- a/test/fixtures/multi-compiler-2-config/foo.js +++ b/test/fixtures/multi-compiler-2-config/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('Hey.'); +console.log("Hey."); diff --git a/test/fixtures/multi-compiler-2-config/webpack.config.js b/test/fixtures/multi-compiler-2-config/webpack.config.js index 4287acf4f3..e27f4b8aa2 100644 --- a/test/fixtures/multi-compiler-2-config/webpack.config.js +++ b/test/fixtures/multi-compiler-2-config/webpack.config.js @@ -1,28 +1,28 @@ -'use strict'; +"use strict"; module.exports = [ { - mode: 'development', + mode: "development", context: __dirname, - entry: './foo.js', + entry: "./foo.js", output: { - path: '/', + path: "/", }, node: false, infrastructureLogging: { - level: 'warn', + level: "warn", }, }, { - mode: 'development', + mode: "development", context: __dirname, - entry: './foo.js', + entry: "./foo.js", output: { - path: '/', + path: "/", }, node: false, infrastructureLogging: { - level: 'warn', + level: "warn", }, }, ]; diff --git a/test/fixtures/multi-compiler-config/foo.js b/test/fixtures/multi-compiler-config/foo.js index eab26534f3..3c915dbcb8 100644 --- a/test/fixtures/multi-compiler-config/foo.js +++ b/test/fixtures/multi-compiler-config/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('Hey.'); +console.log("Hey."); diff --git a/test/fixtures/multi-compiler-config/webpack.config.js b/test/fixtures/multi-compiler-config/webpack.config.js index cd8f4cf3b4..7b8c2320f1 100644 --- a/test/fixtures/multi-compiler-config/webpack.config.js +++ b/test/fixtures/multi-compiler-config/webpack.config.js @@ -1,17 +1,17 @@ -'use strict'; +"use strict"; module.exports = [ { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { - path: '/', + path: "/", }, node: false, infrastructureLogging: { - level: 'warn', + level: "warn", }, }, ]; diff --git a/test/fixtures/multi-public-path-config/bar.js b/test/fixtures/multi-public-path-config/bar.js index eab26534f3..3c915dbcb8 100644 --- a/test/fixtures/multi-public-path-config/bar.js +++ b/test/fixtures/multi-public-path-config/bar.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('Hey.'); +console.log("Hey."); diff --git a/test/fixtures/multi-public-path-config/baz.js b/test/fixtures/multi-public-path-config/baz.js index eab26534f3..3c915dbcb8 100644 --- a/test/fixtures/multi-public-path-config/baz.js +++ b/test/fixtures/multi-public-path-config/baz.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('Hey.'); +console.log("Hey."); diff --git a/test/fixtures/multi-public-path-config/foo.js b/test/fixtures/multi-public-path-config/foo.js index 9ec01334a7..d2f0aa53dd 100644 --- a/test/fixtures/multi-public-path-config/foo.js +++ b/test/fixtures/multi-public-path-config/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -require('./test.html'); +require("./test.html"); diff --git a/test/fixtures/multi-public-path-config/webpack.config.js b/test/fixtures/multi-public-path-config/webpack.config.js index b6f8a7b48a..b362815740 100644 --- a/test/fixtures/multi-public-path-config/webpack.config.js +++ b/test/fixtures/multi-public-path-config/webpack.config.js @@ -1,58 +1,58 @@ -'use strict'; +"use strict"; -const path = require('path'); +const path = require("path"); module.exports = [ { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { path: __dirname, - filename: 'foo.js', - publicPath: '/bundle1/', + filename: "foo.js", + publicPath: "/bundle1/", }, infrastructureLogging: { - level: 'warn', + level: "warn", }, module: { rules: [ { test: /\.html$/, - loader: 'file-loader', + loader: "file-loader", options: { - name: 'path/to/file.html', + name: "path/to/file.html", }, }, ], }, }, { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './bar.js', + stats: "none", + entry: "./bar.js", output: { - path: path.join(__dirname, 'named'), - filename: 'bar.js', - publicPath: '/bundle2/', + path: path.join(__dirname, "named"), + filename: "bar.js", + publicPath: "/bundle2/", }, - name: 'named', + name: "named", infrastructureLogging: { - level: 'warn', + level: "warn", }, }, { - mode: 'development', + mode: "development", context: __dirname, - entry: './bar.js', + entry: "./bar.js", output: { - path: path.join(__dirname, 'dist'), - filename: 'bar.js', - publicPath: 'auto', + path: path.join(__dirname, "dist"), + filename: "bar.js", + publicPath: "auto", }, - name: 'other', + name: "other", stats: false, }, ]; diff --git a/test/fixtures/overlay-config/foo.js b/test/fixtures/overlay-config/foo.js index eab26534f3..3c915dbcb8 100644 --- a/test/fixtures/overlay-config/foo.js +++ b/test/fixtures/overlay-config/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('Hey.'); +console.log("Hey."); diff --git a/test/fixtures/overlay-config/webpack.config.js b/test/fixtures/overlay-config/webpack.config.js index 386d693e66..f03898aa61 100644 --- a/test/fixtures/overlay-config/webpack.config.js +++ b/test/fixtures/overlay-config/webpack.config.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { - path: '/', + path: "/", }, infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/promise-config/foo.js b/test/fixtures/promise-config/foo.js index f88d8b5040..5940e9197c 100644 --- a/test/fixtures/promise-config/foo.js +++ b/test/fixtures/promise-config/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('i am foo!'); +console.log("i am foo!"); diff --git a/test/fixtures/promise-config/webpack.config.js b/test/fixtures/promise-config/webpack.config.js index 86bb30f80c..a75b90a920 100644 --- a/test/fixtures/promise-config/webpack.config.js +++ b/test/fixtures/promise-config/webpack.config.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; -const { join } = require('path'); +const { join } = require("path"); module.exports = () => new Promise((resolve) => { resolve({ - mode: 'development', - entry: join(__dirname, 'foo.js'), + mode: "development", + entry: join(__dirname, "foo.js"), }); }); diff --git a/test/fixtures/provide-plugin-custom/foo.js b/test/fixtures/provide-plugin-custom/foo.js index 33a9ea7e29..c28b40f73c 100644 --- a/test/fixtures/provide-plugin-custom/foo.js +++ b/test/fixtures/provide-plugin-custom/foo.js @@ -1,7 +1,7 @@ -'use strict'; +"use strict"; // 'npm run prepare' must be run for this to work during testing -const CustomClient = require('../../fixtures/custom-client/CustomSockJSClient'); +const CustomClient = require("../../fixtures/custom-client/CustomSockJSClient"); window.expectedClient = CustomClient; // eslint-disable-next-line camelcase, no-undef diff --git a/test/fixtures/provide-plugin-custom/webpack.config.js b/test/fixtures/provide-plugin-custom/webpack.config.js index c6d889a916..624dc8a648 100644 --- a/test/fixtures/provide-plugin-custom/webpack.config.js +++ b/test/fixtures/provide-plugin-custom/webpack.config.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { - path: '/', + path: "/", }, node: false, infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/provide-plugin-default/foo.js b/test/fixtures/provide-plugin-default/foo.js index dbc1f86da8..7943185c3b 100644 --- a/test/fixtures/provide-plugin-default/foo.js +++ b/test/fixtures/provide-plugin-default/foo.js @@ -1,7 +1,7 @@ -'use strict'; +"use strict"; // 'npm run prepare' must be run for this to work during testing -const WebsocketClient = require('../../../client/clients/WebsocketClient'); +const WebsocketClient = require("../../../client/clients/WebsocketClient"); window.expectedClient = WebsocketClient; // eslint-disable-next-line camelcase, no-undef diff --git a/test/fixtures/provide-plugin-default/webpack.config.js b/test/fixtures/provide-plugin-default/webpack.config.js index c6d889a916..624dc8a648 100644 --- a/test/fixtures/provide-plugin-default/webpack.config.js +++ b/test/fixtures/provide-plugin-default/webpack.config.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { - path: '/', + path: "/", }, node: false, infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/provide-plugin-sockjs-config/foo.js b/test/fixtures/provide-plugin-sockjs-config/foo.js index 4b70afc8ca..ff91e61e5e 100644 --- a/test/fixtures/provide-plugin-sockjs-config/foo.js +++ b/test/fixtures/provide-plugin-sockjs-config/foo.js @@ -1,7 +1,7 @@ -'use strict'; +"use strict"; // 'npm run prepare' must be run for this to work during testing -const SockJSClient = require('../../../client/clients/SockJSClient'); +const SockJSClient = require("../../../client/clients/SockJSClient"); window.expectedClient = SockJSClient; // eslint-disable-next-line camelcase, no-undef diff --git a/test/fixtures/provide-plugin-sockjs-config/webpack.config.js b/test/fixtures/provide-plugin-sockjs-config/webpack.config.js index c6d889a916..624dc8a648 100644 --- a/test/fixtures/provide-plugin-sockjs-config/webpack.config.js +++ b/test/fixtures/provide-plugin-sockjs-config/webpack.config.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { - path: '/', + path: "/", }, node: false, infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/provide-plugin-ws-config/foo.js b/test/fixtures/provide-plugin-ws-config/foo.js index dbc1f86da8..7943185c3b 100644 --- a/test/fixtures/provide-plugin-ws-config/foo.js +++ b/test/fixtures/provide-plugin-ws-config/foo.js @@ -1,7 +1,7 @@ -'use strict'; +"use strict"; // 'npm run prepare' must be run for this to work during testing -const WebsocketClient = require('../../../client/clients/WebsocketClient'); +const WebsocketClient = require("../../../client/clients/WebsocketClient"); window.expectedClient = WebsocketClient; // eslint-disable-next-line camelcase, no-undef diff --git a/test/fixtures/provide-plugin-ws-config/webpack.config.js b/test/fixtures/provide-plugin-ws-config/webpack.config.js index c6d889a916..624dc8a648 100644 --- a/test/fixtures/provide-plugin-ws-config/webpack.config.js +++ b/test/fixtures/provide-plugin-ws-config/webpack.config.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { - path: '/', + path: "/", }, node: false, infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/proxy-config/foo.js b/test/fixtures/proxy-config/foo.js index eab26534f3..3c915dbcb8 100644 --- a/test/fixtures/proxy-config/foo.js +++ b/test/fixtures/proxy-config/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('Hey.'); +console.log("Hey."); diff --git a/test/fixtures/proxy-config/webpack.config.js b/test/fixtures/proxy-config/webpack.config.js index 386d693e66..f03898aa61 100644 --- a/test/fixtures/proxy-config/webpack.config.js +++ b/test/fixtures/proxy-config/webpack.config.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { - path: '/', + path: "/", }, infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/reload-config-2/foo.js b/test/fixtures/reload-config-2/foo.js index 74895c921b..37887d2535 100644 --- a/test/fixtures/reload-config-2/foo.js +++ b/test/fixtures/reload-config-2/foo.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; // eslint-disable-next-line import/no-unresolved -require('./main.css'); +require("./main.css"); diff --git a/test/fixtures/reload-config-2/webpack.config.js b/test/fixtures/reload-config-2/webpack.config.js index 7d9ad3f953..e6b58b3802 100644 --- a/test/fixtures/reload-config-2/webpack.config.js +++ b/test/fixtures/reload-config-2/webpack.config.js @@ -1,23 +1,23 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { - path: '/', + path: "/", }, module: { rules: [ { test: /\.css$/, - use: [{ loader: 'style-loader' }, { loader: 'css-loader' }], + use: [{ loader: "style-loader" }, { loader: "css-loader" }], }, ], }, node: false, infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/reload-config/foo.js b/test/fixtures/reload-config/foo.js index 74895c921b..37887d2535 100644 --- a/test/fixtures/reload-config/foo.js +++ b/test/fixtures/reload-config/foo.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; // eslint-disable-next-line import/no-unresolved -require('./main.css'); +require("./main.css"); diff --git a/test/fixtures/reload-config/webpack.config.js b/test/fixtures/reload-config/webpack.config.js index e357c04176..a4c6cce401 100644 --- a/test/fixtures/reload-config/webpack.config.js +++ b/test/fixtures/reload-config/webpack.config.js @@ -1,23 +1,23 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - entry: './foo.js', - stats: 'none', + entry: "./foo.js", + stats: "none", output: { - path: '/', + path: "/", }, module: { rules: [ { test: /\.css$/, - use: [{ loader: 'style-loader' }, { loader: 'css-loader' }], + use: [{ loader: "style-loader" }, { loader: "css-loader" }], }, ], }, infrastructureLogging: { - level: 'warn', + level: "warn", }, node: false, }; diff --git a/test/fixtures/schema/webpack.config.simple.js b/test/fixtures/schema/webpack.config.simple.js index 651ec13e98..ad290af1fb 100644 --- a/test/fixtures/schema/webpack.config.simple.js +++ b/test/fixtures/schema/webpack.config.simple.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - entry: './foo.js', + entry: "./foo.js", output: { - path: '/', + path: "/", }, infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/simple-config-other/foo.js b/test/fixtures/simple-config-other/foo.js index 2a1f723cc8..27ed09ecfd 100644 --- a/test/fixtures/simple-config-other/foo.js +++ b/test/fixtures/simple-config-other/foo.js @@ -1,5 +1,5 @@ -'use strict'; +"use strict"; console.log( - 'Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Long Line.' + "Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Very Long Line." ); diff --git a/test/fixtures/simple-config-other/webpack.config.js b/test/fixtures/simple-config-other/webpack.config.js index c6d889a916..624dc8a648 100644 --- a/test/fixtures/simple-config-other/webpack.config.js +++ b/test/fixtures/simple-config-other/webpack.config.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { - path: '/', + path: "/", }, node: false, infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/simple-config/foo.js b/test/fixtures/simple-config/foo.js index eab26534f3..3c915dbcb8 100644 --- a/test/fixtures/simple-config/foo.js +++ b/test/fixtures/simple-config/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('Hey.'); +console.log("Hey."); diff --git a/test/fixtures/simple-config/webpack.config.js b/test/fixtures/simple-config/webpack.config.js index c6d889a916..624dc8a648 100644 --- a/test/fixtures/simple-config/webpack.config.js +++ b/test/fixtures/simple-config/webpack.config.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; module.exports = { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './foo.js', + stats: "none", + entry: "./foo.js", output: { - path: '/', + path: "/", }, node: false, infrastructureLogging: { - level: 'warn', + level: "warn", }, }; diff --git a/test/fixtures/static/foo.js b/test/fixtures/static/foo.js index f88d8b5040..5940e9197c 100644 --- a/test/fixtures/static/foo.js +++ b/test/fixtures/static/foo.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('i am foo!'); +console.log("i am foo!"); diff --git a/test/fixtures/static/webpack.config.js b/test/fixtures/static/webpack.config.js index 2ddf10925d..a710816d46 100644 --- a/test/fixtures/static/webpack.config.js +++ b/test/fixtures/static/webpack.config.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; -const path = require('path'); +const path = require("path"); module.exports = { - mode: 'development', - entry: path.resolve(__dirname, 'foo.js'), + mode: "development", + entry: path.resolve(__dirname, "foo.js"), devServer: { - static: path.resolve(__dirname, 'static'), + static: path.resolve(__dirname, "static"), }, }; diff --git a/test/fixtures/universal-compiler-config/client.js b/test/fixtures/universal-compiler-config/client.js index 1bae5186de..3cc4ed1dcb 100644 --- a/test/fixtures/universal-compiler-config/client.js +++ b/test/fixtures/universal-compiler-config/client.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('Hello from the client'); +console.log("Hello from the client"); diff --git a/test/fixtures/universal-compiler-config/server.js b/test/fixtures/universal-compiler-config/server.js index 20b3c3356b..3dfb585f6d 100644 --- a/test/fixtures/universal-compiler-config/server.js +++ b/test/fixtures/universal-compiler-config/server.js @@ -1,3 +1,3 @@ -'use strict'; +"use strict"; -console.log('Hello from the server'); +console.log("Hello from the server"); diff --git a/test/fixtures/universal-compiler-config/webpack.config.js b/test/fixtures/universal-compiler-config/webpack.config.js index af6fbd3512..7a30678b90 100644 --- a/test/fixtures/universal-compiler-config/webpack.config.js +++ b/test/fixtures/universal-compiler-config/webpack.config.js @@ -1,33 +1,33 @@ -'use strict'; +"use strict"; module.exports = [ { - mode: 'development', + mode: "development", context: __dirname, - stats: 'none', - entry: './client.js', + stats: "none", + entry: "./client.js", output: { - path: '/', - filename: 'client.js', + path: "/", + filename: "client.js", }, node: false, infrastructureLogging: { - level: 'warn', + level: "warn", }, }, { - mode: 'development', + mode: "development", context: __dirname, - target: 'node', - stats: 'none', - entry: './server.js', + target: "node", + stats: "none", + entry: "./server.js", output: { - path: '/', - filename: 'server.js', + path: "/", + filename: "server.js", }, node: false, infrastructureLogging: { - level: 'warn', + level: "warn", }, }, ]; diff --git a/test/helpers/ExitOnDonePlugin.js b/test/helpers/ExitOnDonePlugin.js index a49d67ec08..b4ba799c1a 100644 --- a/test/helpers/ExitOnDonePlugin.js +++ b/test/helpers/ExitOnDonePlugin.js @@ -1,8 +1,8 @@ -'use strict'; +"use strict"; module.exports = { apply(compiler) { - compiler.hooks.done.tap('webpack-dev-server', (stats) => { + compiler.hooks.done.tap("webpack-dev-server", (stats) => { let exitCode = 0; if (stats.hasErrors()) { exitCode = 1; diff --git a/test/helpers/conditional-test.js b/test/helpers/conditional-test.js index d420142b29..f3486ed6a3 100644 --- a/test/helpers/conditional-test.js +++ b/test/helpers/conditional-test.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const isWindows = process.platform === 'win32'; +const isWindows = process.platform === "win32"; function skipTestOnWindows(reason) { if (isWindows) { diff --git a/test/helpers/isWebpack5.js b/test/helpers/isWebpack5.js index d3a2eb5975..8ba5b455ff 100644 --- a/test/helpers/isWebpack5.js +++ b/test/helpers/isWebpack5.js @@ -1,7 +1,7 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); +const webpack = require("webpack"); -const isWebpack5 = webpack.version[0] === '5'; +const isWebpack5 = webpack.version[0] === "5"; module.exports = isWebpack5; diff --git a/test/helpers/puppeteer-constants.js b/test/helpers/puppeteer-constants.js index eca1153a54..de7db4f923 100644 --- a/test/helpers/puppeteer-constants.js +++ b/test/helpers/puppeteer-constants.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; module.exports = { reloadReadyDelay: 5000, @@ -7,46 +7,46 @@ module.exports = { awaitServerCloseDelay: 1000, beforeBrowserCloseDelay: 3000, puppeteerArgs: [ - '--disable-background-timer-throttling', - '--disable-breakpad', - '--disable-client-side-phishing-detection', - '--disable-cloud-import', - '--disable-default-apps', - '--disable-dev-shm-usage', - '--disable-extensions', - '--disable-gesture-typing', - '--disable-hang-monitor', - '--disable-infobars', - '--disable-notifications', - '--disable-offer-store-unmasked-wallet-cards', - '--disable-offer-upload-credit-cards', - '--disable-popup-blocking', - '--disable-print-preview', - '--disable-prompt-on-repost', - '--disable-setuid-sandbox', - '--disable-speech-api', - '--disable-sync', - '--disable-tab-for-desktop-share', - '--disable-translate', - '--disable-voice-input', - '--disable-wake-on-wifi', - '--enable-async-dns', - '--enable-simple-cache-backend', - '--enable-tcp-fast-open', - '--enable-webgl', - '--hide-scrollbars', - '--ignore-gpu-blacklist', - '--media-cache-size=33554432', - '--metrics-recording-only', - '--mute-audio', - '--no-default-browser-check', - '--no-first-run', - '--no-pings', - '--no-sandbox', - '--no-zygote', - '--password-store=basic', - '--prerender-from-omnibox=disabled', - '--use-gl=swiftshader', - '--use-mock-keychain', + "--disable-background-timer-throttling", + "--disable-breakpad", + "--disable-client-side-phishing-detection", + "--disable-cloud-import", + "--disable-default-apps", + "--disable-dev-shm-usage", + "--disable-extensions", + "--disable-gesture-typing", + "--disable-hang-monitor", + "--disable-infobars", + "--disable-notifications", + "--disable-offer-store-unmasked-wallet-cards", + "--disable-offer-upload-credit-cards", + "--disable-popup-blocking", + "--disable-print-preview", + "--disable-prompt-on-repost", + "--disable-setuid-sandbox", + "--disable-speech-api", + "--disable-sync", + "--disable-tab-for-desktop-share", + "--disable-translate", + "--disable-voice-input", + "--disable-wake-on-wifi", + "--enable-async-dns", + "--enable-simple-cache-backend", + "--enable-tcp-fast-open", + "--enable-webgl", + "--hide-scrollbars", + "--ignore-gpu-blacklist", + "--media-cache-size=33554432", + "--metrics-recording-only", + "--mute-audio", + "--no-default-browser-check", + "--no-first-run", + "--no-pings", + "--no-sandbox", + "--no-zygote", + "--password-store=basic", + "--prerender-from-omnibox=disabled", + "--use-gl=swiftshader", + "--use-mock-keychain", ], }; diff --git a/test/helpers/run-browser.js b/test/helpers/run-browser.js index da04638119..1934b27693 100644 --- a/test/helpers/run-browser.js +++ b/test/helpers/run-browser.js @@ -1,7 +1,7 @@ -'use strict'; +"use strict"; -const puppeteer = require('puppeteer'); -const { puppeteerArgs } = require('./puppeteer-constants'); +const puppeteer = require("puppeteer"); +const { puppeteerArgs } = require("./puppeteer-constants"); function runBrowser(config) { const options = { @@ -9,7 +9,7 @@ function runBrowser(config) { width: 500, height: 500, }, - userAgent: '', + userAgent: "", ...config, }; diff --git a/test/helpers/snapshotResolver.js b/test/helpers/snapshotResolver.js index c29643c6bb..c245f0460a 100644 --- a/test/helpers/snapshotResolver.js +++ b/test/helpers/snapshotResolver.js @@ -1,7 +1,7 @@ -'use strict'; +"use strict"; -const path = require('path'); -const webpack = require('webpack'); +const path = require("path"); +const webpack = require("webpack"); const [webpackVersion] = webpack.version; const snapshotExtension = `.snap.webpack${webpackVersion}`; @@ -10,16 +10,16 @@ module.exports = { resolveSnapshotPath: (testPath) => path.join( path.dirname(testPath), - '__snapshots__', + "__snapshots__", `${path.basename(testPath)}${snapshotExtension}` ), resolveTestPath: (snapshotPath) => snapshotPath - .replace(`${path.sep}__snapshots__`, '') + .replace(`${path.sep}__snapshots__`, "") .slice(0, -snapshotExtension.length), testPathForConsistencyCheck: path.join( - 'consistency_check', - '__tests__', - 'example.test.js' + "consistency_check", + "__tests__", + "example.test.js" ), }; diff --git a/test/helpers/test-bin.js b/test/helpers/test-bin.js index 4c3b60a4fa..fb6774a5c7 100644 --- a/test/helpers/test-bin.js +++ b/test/helpers/test-bin.js @@ -1,18 +1,18 @@ -'use strict'; +"use strict"; -const os = require('os'); -const path = require('path'); -const execa = require('execa'); -const stripAnsi = require('strip-ansi-v6'); -const internalIp = require('internal-ip'); +const os = require("os"); +const path = require("path"); +const execa = require("execa"); +const stripAnsi = require("strip-ansi-v6"); +const internalIp = require("internal-ip"); const webpackDevServerPath = path.resolve( __dirname, - '../../bin/webpack-dev-server.js' + "../../bin/webpack-dev-server.js" ); const basicConfigPath = path.resolve( __dirname, - '../fixtures/cli/webpack.config.js' + "../fixtures/cli/webpack.config.js" ); const testBin = (testArgs = []) => { @@ -22,40 +22,40 @@ const testBin = (testArgs = []) => { NODE_ENV: process.env.NODE_ENV, }; - if (typeof testArgs === 'string') { - testArgs = testArgs.split(' '); + if (typeof testArgs === "string") { + testArgs = testArgs.split(" "); } let args; - if (testArgs.includes('--help')) { + if (testArgs.includes("--help")) { args = [webpackDevServerPath, ...testArgs]; } else { - const configOptions = testArgs.includes('--config') + const configOptions = testArgs.includes("--config") ? [] - : ['--config', basicConfigPath]; + : ["--config", basicConfigPath]; args = [webpackDevServerPath, ...configOptions, ...testArgs]; } - return execa('node', args, { cwd, env, timeout: 10000 }); + return execa("node", args, { cwd, env, timeout: 10000 }); }; const normalizeStderr = (stderr, options = {}) => { let normalizedStderr = stripAnsi(stderr); normalizedStderr = normalizedStderr - .replace(/\\/g, '/') - .replace(new RegExp(process.cwd().replace(/\\/g, '/'), 'g'), '') - .replace(new RegExp(os.tmpdir().replace(/\\/g, '/'), 'g'), '') - .replace(new RegExp('\\\\.\\pipe'.replace(/\\/g, '/'), 'g'), ''); + .replace(/\\/g, "/") + .replace(new RegExp(process.cwd().replace(/\\/g, "/"), "g"), "") + .replace(new RegExp(os.tmpdir().replace(/\\/g, "/"), "g"), "") + .replace(new RegExp("\\\\.\\pipe".replace(/\\/g, "/"), "g"), ""); const networkIPv4 = internalIp.v4.sync(); if (networkIPv4) { normalizedStderr = normalizedStderr.replace( - new RegExp(networkIPv4, 'g'), - '' + new RegExp(networkIPv4, "g"), + "" ); } @@ -64,48 +64,48 @@ const normalizeStderr = (stderr, options = {}) => { // normalize node warnings normalizedStderr = normalizedStderr.replace( /.*DeprecationWarning.*(\n)*/gm, - '' + "" ); normalizedStderr = normalizedStderr.replace( /.*Use `node --trace-deprecation ...` to show where the warning was created.*(\n)*/gm, - '' + "" ); if (networkIPv6) { normalizedStderr = normalizedStderr.replace( - new RegExp(networkIPv6, 'g'), - '' + new RegExp(networkIPv6, "g"), + "" ); } - normalizedStderr = normalizedStderr.split('\n'); + normalizedStderr = normalizedStderr.split("\n"); normalizedStderr = normalizedStderr.filter( (item) => !/.+wait until bundle finished.*(\n)?/g.test(item) ); - normalizedStderr = normalizedStderr.join('\n'); + normalizedStderr = normalizedStderr.join("\n"); - normalizedStderr = normalizedStderr.replace(/:[0-9]+\//g, ':/'); + normalizedStderr = normalizedStderr.replace(/:[0-9]+\//g, ":/"); if (options.https) { // We have deprecation warning on windows in some cases - normalizedStderr = normalizedStderr.split('\n'); + normalizedStderr = normalizedStderr.split("\n"); normalizedStderr = normalizedStderr.filter( (item) => !/DeprecationWarning: The legacy HTTP parser is deprecated/g.test(item) ); - normalizedStderr = normalizedStderr.join('\n'); + normalizedStderr = normalizedStderr.join("\n"); } if (options.ipv6 && !networkIPv6) { // Github Actions doesnt' support IPv6 on ubuntu in some cases - normalizedStderr = normalizedStderr.split('\n'); + normalizedStderr = normalizedStderr.split("\n"); const ipv4MessageIndex = normalizedStderr.findIndex((item) => /On Your Network \(IPv4\)/.test(item) ); - const protocol = options.https ? 'https' : 'http'; + const protocol = options.https ? "https" : "http"; normalizedStderr.splice( ipv4MessageIndex + 1, @@ -113,7 +113,7 @@ const normalizeStderr = (stderr, options = {}) => { ` [webpack-dev-server] On Your Network (IPv6): ${protocol}://[]:/` ); - normalizedStderr = normalizedStderr.join('\n'); + normalizedStderr = normalizedStderr.join("\n"); } return normalizedStderr; diff --git a/test/helpers/test-server.js b/test/helpers/test-server.js index 4b916cc538..48a9a24088 100644 --- a/test/helpers/test-server.js +++ b/test/helpers/test-server.js @@ -1,7 +1,7 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const Server = require('../../lib/Server'); +const webpack = require("webpack"); +const Server = require("../../lib/Server"); let server; @@ -9,7 +9,7 @@ let server; // (both the server and the compiler) function startFullSetup(config, options, done) { // disable watching by default for tests - if (typeof options.static === 'undefined') { + if (typeof options.static === "undefined") { options.static = false; } else if (options.static === null) { // this provides a way of using the default static value @@ -22,19 +22,19 @@ function startFullSetup(config, options, done) { let port; - if (Object.prototype.hasOwnProperty.call(options, 'port')) { + if (Object.prototype.hasOwnProperty.call(options, "port")) { port = options.port; } else { - console.warn('Using the default port for testing is not recommended'); + console.warn("Using the default port for testing is not recommended"); port = 8080; } let host; - if (Object.prototype.hasOwnProperty.call(options, 'host')) { + if (Object.prototype.hasOwnProperty.call(options, "host")) { host = options.host; } else { - host = 'localhost'; + host = "localhost"; } server.listen(port, host, (error) => { @@ -68,7 +68,7 @@ function startAwaitingCompilationFullSetup(config, options, done) { // wait for compilation, since dev server can start before this // https://github.com/webpack/webpack-dev-server/issues/847 - fullSetup.compiler.hooks.done.tap('done', ready); + fullSetup.compiler.hooks.done.tap("done", ready); return fullSetup; } diff --git a/test/integration/ModuleFederation.test.js b/test/integration/ModuleFederation.test.js index 27625c6fa5..ae5f7498f7 100644 --- a/test/integration/ModuleFederation.test.js +++ b/test/integration/ModuleFederation.test.js @@ -1,27 +1,27 @@ -'use strict'; - -const webpack = require('webpack'); -const request = require('supertest'); -const requireFromString = require('require-from-string'); -const Server = require('../../lib/Server'); -const simpleConfig = require('../fixtures/module-federation-config/webpack.config'); -const objectEntryConfig = require('../fixtures/module-federation-config/webpack.object-entry.config'); -const multiConfig = require('../fixtures/module-federation-config/webpack.multi.config'); -const port = require('../ports-map')['module-federation']; -const isWebpack5 = require('../helpers/isWebpack5'); +"use strict"; + +const webpack = require("webpack"); +const request = require("supertest"); +const requireFromString = require("require-from-string"); +const Server = require("../../lib/Server"); +const simpleConfig = require("../fixtures/module-federation-config/webpack.config"); +const objectEntryConfig = require("../fixtures/module-federation-config/webpack.object-entry.config"); +const multiConfig = require("../fixtures/module-federation-config/webpack.multi.config"); +const port = require("../ports-map")["module-federation"]; +const isWebpack5 = require("../helpers/isWebpack5"); let pluginConfig; if (isWebpack5) { - pluginConfig = require('../fixtures/module-federation-config/webpack.plugin'); + pluginConfig = require("../fixtures/module-federation-config/webpack.plugin"); } -describe('module federation', () => { +describe("module federation", () => { describe.each([ - ['simple multi-entry config', simpleConfig], - ['object multi-entry config', objectEntryConfig], - ['multi compiler config', multiConfig], - ])('%s', (title, config) => { + ["simple multi-entry config", simpleConfig], + ["object multi-entry config", objectEntryConfig], + ["multi compiler config", multiConfig], + ])("%s", (title, config) => { let server; let req; @@ -31,7 +31,7 @@ describe('module federation', () => { server = new Server({ port }, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -53,26 +53,26 @@ describe('module federation', () => { }); }); - it('should use the last entry export', async () => { - const { text, statusCode } = await req.get('/main.js'); + it("should use the last entry export", async () => { + const { text, statusCode } = await req.get("/main.js"); expect(statusCode).toEqual(200); - expect(text).toContain('entry1'); + expect(text).toContain("entry1"); let exports; expect(() => { exports = requireFromString(text); }).not.toThrow(); - expect(exports).toEqual('entry2'); + expect(exports).toEqual("entry2"); }); - if (title === 'object multi-entry config') { - it('should support the named entry export', async () => { - const { text, statusCode } = await req.get('/foo.js'); + if (title === "object multi-entry config") { + it("should support the named entry export", async () => { + const { text, statusCode } = await req.get("/foo.js"); expect(statusCode).toEqual(200); - expect(text).not.toContain('entry2'); + expect(text).not.toContain("entry2"); let exports; @@ -80,12 +80,12 @@ describe('module federation', () => { exports = requireFromString(text); }).not.toThrow(); - expect(exports).toEqual('entry1'); + expect(exports).toEqual("entry1"); }); } }); - (isWebpack5 ? describe : describe.skip)('use plugin', () => { + (isWebpack5 ? describe : describe.skip)("use plugin", () => { let server; let req; @@ -95,7 +95,7 @@ describe('module federation', () => { server = new Server({ port }, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -117,13 +117,13 @@ describe('module federation', () => { }); }); - it('should contain hot script', async () => { - const responseRemoteEntry = await req.get('/remoteEntry.js'); + it("should contain hot script", async () => { + const responseRemoteEntry = await req.get("/remoteEntry.js"); expect(responseRemoteEntry.statusCode).toEqual(200); expect(responseRemoteEntry.text).toMatch(/webpack\/hot\/dev-server\.js/); - const responseMain = await req.get('/main.js'); + const responseMain = await req.get("/main.js"); expect(responseMain.statusCode).toEqual(200); expect(responseMain.text).toMatch(/webpack\/hot\/dev-server\.js/); diff --git a/test/integration/MultiCompiler.test.js b/test/integration/MultiCompiler.test.js index 23c99ea184..5babeba333 100644 --- a/test/integration/MultiCompiler.test.js +++ b/test/integration/MultiCompiler.test.js @@ -1,12 +1,12 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const request = require('supertest'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/multi-compiler-config/webpack.config'); -const port = require('../ports-map')['multi-compiler']; +const webpack = require("webpack"); +const request = require("supertest"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/multi-compiler-config/webpack.config"); +const port = require("../ports-map")["multi-compiler"]; -describe('multi compiler', () => { +describe("multi compiler", () => { let server; let req; @@ -16,7 +16,7 @@ describe('multi compiler', () => { server = new Server({ port }, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -38,11 +38,11 @@ describe('multi compiler', () => { }); }); - it('should handle GET request to bundle', async () => { - const response = await req.get('/main.js'); + it("should handle GET request to bundle", async () => { + const response = await req.get("/main.js"); - expect(response.headers['content-type']).toEqual( - 'application/javascript; charset=utf-8' + expect(response.headers["content-type"]).toEqual( + "application/javascript; charset=utf-8" ); expect(response.status).toEqual(200); }); diff --git a/test/integration/UniversalCompiler.test.js b/test/integration/UniversalCompiler.test.js index 9689dd6fc3..61f0138a19 100644 --- a/test/integration/UniversalCompiler.test.js +++ b/test/integration/UniversalCompiler.test.js @@ -1,12 +1,12 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const request = require('supertest'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/universal-compiler-config/webpack.config'); -const port = require('../ports-map')['universal-compiler']; +const webpack = require("webpack"); +const request = require("supertest"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/universal-compiler-config/webpack.config"); +const port = require("../ports-map")["universal-compiler"]; -describe('universal compiler', () => { +describe("universal compiler", () => { let server; let req; @@ -16,7 +16,7 @@ describe('universal compiler', () => { server = new Server({ port }, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -38,27 +38,27 @@ describe('universal compiler', () => { }); }); - it('client bundle should have the inlined the client runtime', async () => { - const response = await req.get('/client.js'); + it("client bundle should have the inlined the client runtime", async () => { + const response = await req.get("/client.js"); - expect(response.headers['content-type']).toEqual( - 'application/javascript; charset=utf-8' + expect(response.headers["content-type"]).toEqual( + "application/javascript; charset=utf-8" ); expect(response.status).toEqual(200); - expect(response.text).toContain('Hello from the client'); - expect(response.text).toContain('WebsocketClient'); + expect(response.text).toContain("Hello from the client"); + expect(response.text).toContain("WebsocketClient"); }); - it('server bundle should NOT have the inlined the client runtime', async () => { + it("server bundle should NOT have the inlined the client runtime", async () => { // we wouldn't normally request a server bundle // but we'll do it here to check the contents - const response = await req.get('/server.js'); + const response = await req.get("/server.js"); - expect(response.headers['content-type']).toEqual( - 'application/javascript; charset=utf-8' + expect(response.headers["content-type"]).toEqual( + "application/javascript; charset=utf-8" ); expect(response.status).toEqual(200); - expect(response.text).toContain('Hello from the server'); - expect(response.text).not.toContain('WebsocketClient'); + expect(response.text).toContain("Hello from the server"); + expect(response.text).not.toContain("WebsocketClient"); }); }); diff --git a/test/ports-map.js b/test/ports-map.js index e241655e2f..f905462adc 100644 --- a/test/ports-map.js +++ b/test/ports-map.js @@ -1,69 +1,69 @@ -'use strict'; +"use strict"; // important: new port mappings must be added to the bottom of this list const listOfTests = { // CLI tests - 'cli-basic': 1, - 'cli-port-option': 1, + "cli-basic": 1, + "cli-port-option": 1, // e2e tests bundle: 1, - 'sockjs-client': 1, - 'web-socket-client': 1, - 'hot-and-live-reload': 1, + "sockjs-client": 1, + "web-socket-client": 1, + "hot-and-live-reload": 1, logging: 1, overlay: 1, progress: 1, - 'web-socket-server-and-transport': 1, - 'web-socket-server-url': 2, + "web-socket-server-and-transport": 1, + "web-socket-server-url": 2, // integration tests - 'module-federation': 1, - 'multi-compiler': 1, - 'universal-compiler': 1, + "module-federation": 1, + "multi-compiler": 1, + "universal-compiler": 1, // unit tests bonjour: 1, - 'client-option': 1, - 'compress-option': 1, - 'headers-option': 1, - 'history-api-fallback-option': 1, - 'host-option': 1, - 'hot-option': 1, - 'http2-option': 1, - 'https-option': 1, - 'mine-types-option': 1, - 'on-after-setup-middleware-option': 1, - 'on-before-setup-middleware-option': 1, - 'on-listening-option': 1, - 'open-option': 1, - 'port-option': 1, - 'proxy-option': 4, + "client-option": 1, + "compress-option": 1, + "headers-option": 1, + "history-api-fallback-option": 1, + "host-option": 1, + "hot-option": 1, + "http2-option": 1, + "https-option": 1, + "mine-types-option": 1, + "on-after-setup-middleware-option": 1, + "on-before-setup-middleware-option": 1, + "on-listening-option": 1, + "open-option": 1, + "port-option": 1, + "proxy-option": 4, server: 1, - 'setup-exit-signals-option': 1, - 'static-directory-option': 1, - 'static-public-path-option': 1, - 'stats-option': 1, - 'watch-files-option': 1, - 'web-socket-server-option': 1, - 'sockjs-server': 1, - 'web-socket-server': 1, + "setup-exit-signals-option": 1, + "static-directory-option": 1, + "static-public-path-option": 1, + "stats-option": 1, + "watch-files-option": 1, + "web-socket-server-option": 1, + "sockjs-server": 1, + "web-socket-server": 1, routes: 1, - 'web-socket-communication': 1, + "web-socket-communication": 1, ipc: 1, stats: 1, - 'cli-allowed-hosts': 1, - 'cli-bonjour': 1, - 'cli-client': 1, - 'cli-colors': 1, - 'cli-compress': 1, - 'cli-history-api-fallback': 1, - 'cli-host': 1, - 'cli-hot': 1, - 'cli-http2': 1, - 'cli-https': 1, - 'cli-live-reload': 1, - 'cli-open': 1, - 'cli-static': 1, - 'cli-watch-files': 1, - 'cli-web-socket-server': 1, + "cli-allowed-hosts": 1, + "cli-bonjour": 1, + "cli-client": 1, + "cli-colors": 1, + "cli-compress": 1, + "cli-history-api-fallback": 1, + "cli-host": 1, + "cli-hot": 1, + "cli-http2": 1, + "cli-https": 1, + "cli-live-reload": 1, + "cli-open": 1, + "cli-static": 1, + "cli-watch-files": 1, + "cli-web-socket-server": 1, target: 1, entry: 1, }; diff --git a/test/server/Server.test.js b/test/server/Server.test.js index 95ca56feff..2a5b558bce 100644 --- a/test/server/Server.test.js +++ b/test/server/Server.test.js @@ -1,59 +1,59 @@ -'use strict'; +"use strict"; -const { relative, sep } = require('path'); -const http = require('http'); -const webpack = require('webpack'); -const sockjs = require('sockjs/lib/transport'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/simple-config/webpack.config'); -const port = require('../ports-map').server; -const isWebpack5 = require('../helpers/isWebpack5'); +const { relative, sep } = require("path"); +const http = require("http"); +const webpack = require("webpack"); +const sockjs = require("sockjs/lib/transport"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/simple-config/webpack.config"); +const port = require("../ports-map").server; +const isWebpack5 = require("../helpers/isWebpack5"); -jest.mock('sockjs/lib/transport'); +jest.mock("sockjs/lib/transport"); const baseDevConfig = { port, - host: 'localhost', + host: "localhost", static: false, }; -describe('Server', () => { - describe('sockjs', () => { - it('add decorateConnection', () => { +describe("Server", () => { + describe("sockjs", () => { + it("add decorateConnection", () => { expect(typeof sockjs.Session.prototype.decorateConnection).toEqual( - 'function' + "function" ); }); }); - describe('DevServerPlugin', () => { + describe("DevServerPlugin", () => { let entries; function getEntries(server) { if (isWebpack5) { server.middleware.context.compiler.hooks.afterEmit.tap( - 'webpack-dev-server', + "webpack-dev-server", (compilation) => { - const mainDeps = compilation.entries.get('main').dependencies; + const mainDeps = compilation.entries.get("main").dependencies; const globalDeps = compilation.globalEntry.dependencies; entries = globalDeps .concat(mainDeps) - .map((dep) => relative('.', dep.request).split(sep)); + .map((dep) => relative(".", dep.request).split(sep)); } ); } else { entries = server.middleware.context.compiler.options.entry.map((p) => - relative('.', p).split(sep) + relative(".", p).split(sep) ); } } - it('add hot option', (done) => { + it("add hot option", (done) => { const compiler = webpack(config); const server = new Server({ ...baseDevConfig, hot: true }, compiler); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { expect(entries).toMatchSnapshot(); server.close(() => { @@ -61,7 +61,7 @@ describe('Server', () => { }); }); - server.listen(port, 'localhost', (error) => { + server.listen(port, "localhost", (error) => { if (error) { throw error; } @@ -70,17 +70,17 @@ describe('Server', () => { }); }); - it('add hot-only option', (done) => { + it("add hot-only option", (done) => { const compiler = webpack(config); - const server = new Server({ ...baseDevConfig, hot: 'only' }, compiler); + const server = new Server({ ...baseDevConfig, hot: "only" }, compiler); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { expect(entries).toMatchSnapshot(); server.close(done); }); - server.listen(port, 'localhost', (error) => { + server.listen(port, "localhost", (error) => { if (error) { throw error; } @@ -90,17 +90,17 @@ describe('Server', () => { }); // TODO: remove this after plugin support is published - it('should create and run server with old parameters order', (done) => { + it("should create and run server with old parameters order", (done) => { const compiler = webpack(config); const server = new Server(compiler, baseDevConfig); - compiler.hooks.done.tap('webpack-dev-server', () => { - expect(entries).toMatchSnapshot('oldparam'); + compiler.hooks.done.tap("webpack-dev-server", () => { + expect(entries).toMatchSnapshot("oldparam"); server.close(done); }); - server.listen(port, 'localhost', (error) => { + server.listen(port, "localhost", (error) => { if (error) { throw error; } @@ -110,11 +110,11 @@ describe('Server', () => { }); }); - it('test server error reporting', () => { + it("test server error reporting", () => { const compiler = webpack(config); const server = new Server(baseDevConfig, compiler); - const emitError = () => server.server.emit('error', new Error('Error !!!')); + const emitError = () => server.server.emit("error", new Error("Error !!!")); expect(emitError).toThrowError(); @@ -122,16 +122,16 @@ describe('Server', () => { }); // issue: https://github.com/webpack/webpack-dev-server/issues/1724 - describe('express.static.mime.types', () => { + describe("express.static.mime.types", () => { it("should success even if mime.types doesn't exist", (done) => { - jest.mock('express', () => { - const data = jest.requireActual('express'); + jest.mock("express", () => { + const data = jest.requireActual("express"); const { static: st } = data; const { mime } = st; delete mime.types; - expect(typeof mime.types).toEqual('undefined'); + expect(typeof mime.types).toEqual("undefined"); return { ...data, static: { ...st, mime } }; }); @@ -139,18 +139,18 @@ describe('Server', () => { const compiler = webpack(config); const server = new Server(baseDevConfig, compiler); - compiler.hooks.done.tap('webpack-dev-server', (s) => { + compiler.hooks.done.tap("webpack-dev-server", (s) => { const output = server.getStats(s); expect(output.errors.length).toEqual(0); server.close(done); }); - server.listen(port, 'localhost'); + server.listen(port, "localhost"); }); }); - describe('listen', () => { + describe("listen", () => { let compiler; let server; @@ -160,7 +160,7 @@ describe('Server', () => { it('should work and using "port" and "host" from options', (done) => { const options = { - host: 'localhost', + host: "localhost", port, }; @@ -170,7 +170,7 @@ describe('Server', () => { server.listen(undefined, undefined, () => { const info = server.server.address(); - expect(info.address).toBe('127.0.0.1'); + expect(info.address).toBe("127.0.0.1"); expect(info.port).toBe(port); server.close(done); @@ -180,10 +180,10 @@ describe('Server', () => { it('should work and using "port" and "host" from arguments', (done) => { server = new Server({}, compiler); - server.listen(port, '127.0.0.1', () => { + server.listen(port, "127.0.0.1", () => { const info = server.server.address(); - expect(info.address).toBe('127.0.0.1'); + expect(info.address).toBe("127.0.0.1"); expect(info.port).toBe(port); server.close(done); @@ -192,7 +192,7 @@ describe('Server', () => { it('should work and using the same "port" and "host" from options and arguments', (done) => { const options = { - host: 'localhost', + host: "localhost", port, }; @@ -201,7 +201,7 @@ describe('Server', () => { server.listen(options.port, options.host, () => { const info = server.server.address(); - expect(info.address).toBe('127.0.0.1'); + expect(info.address).toBe("127.0.0.1"); expect(info.port).toBe(port); server.close(done); @@ -210,7 +210,7 @@ describe('Server', () => { it('should work and using "port" from arguments and "host" from options', (done) => { const options = { - host: '127.0.0.1', + host: "127.0.0.1", }; server = new Server(options, compiler); @@ -219,7 +219,7 @@ describe('Server', () => { server.listen(port, undefined, () => { const info = server.server.address(); - expect(info.address).toBe('127.0.0.1'); + expect(info.address).toBe("127.0.0.1"); expect(info.port).toBe(port); server.close(done); @@ -234,10 +234,10 @@ describe('Server', () => { server = new Server(options, compiler); // eslint-disable-next-line no-undefined - server.listen(undefined, '127.0.0.1', () => { + server.listen(undefined, "127.0.0.1", () => { const info = server.server.address(); - expect(info.address).toBe('127.0.0.1'); + expect(info.address).toBe("127.0.0.1"); expect(info.port).toBe(port); server.close(done); @@ -246,15 +246,15 @@ describe('Server', () => { it('should log warning when the "port" and "host" options from options different from arguments', (done) => { const options = { - host: '127.0.0.2', - port: '9999', + host: "127.0.0.2", + port: "9999", }; server = new Server(compiler, options); - const loggerWarnSpy = jest.spyOn(server.logger, 'warn'); + const loggerWarnSpy = jest.spyOn(server.logger, "warn"); - server.listen(port, '127.0.0.1', () => { + server.listen(port, "127.0.0.1", () => { const info = server.server.address(); expect(loggerWarnSpy).toHaveBeenNthCalledWith( @@ -265,7 +265,7 @@ describe('Server', () => { 2, 'The "host" specified in options is different from the host passed as an argument. Will be used from arguments.' ); - expect(info.address).toBe('127.0.0.1'); + expect(info.address).toBe("127.0.0.1"); expect(info.port).toBe(port); loggerWarnSpy.mockRestore(); @@ -274,7 +274,7 @@ describe('Server', () => { }); }); - describe('checkHostHeader', () => { + describe("checkHostHeader", () => { let compiler; let server; @@ -288,14 +288,14 @@ describe('Server', () => { }); }); - it('should allow any valid options.client.webSocketURL when host is localhost', () => { + it("should allow any valid options.client.webSocketURL when host is localhost", () => { const options = { client: { - webSocketURL: 'ws://test.host:80', + webSocketURL: "ws://test.host:80", }, }; const headers = { - host: 'localhost', + host: "localhost", }; server = new Server(options, compiler); @@ -305,15 +305,15 @@ describe('Server', () => { } }); - it('should allow any valid options.client.webSocketURL when host is 127.0.0.1', () => { + it("should allow any valid options.client.webSocketURL when host is 127.0.0.1", () => { const options = { client: { - webSocketURL: 'ws://test.host:80', + webSocketURL: "ws://test.host:80", }, }; const headers = { - host: '127.0.0.1', + host: "127.0.0.1", }; server = new Server(options, compiler); @@ -323,16 +323,16 @@ describe('Server', () => { } }); - it('should allow access for every requests using an IP', () => { + it("should allow access for every requests using an IP", () => { const options = {}; const tests = [ - '192.168.1.123', - '192.168.1.2:8080', - '[::1]', - '[::1]:8080', - '[ad42::1de2:54c2:c2fa:1234]', - '[ad42::1de2:54c2:c2fa:1234]:8080', + "192.168.1.123", + "192.168.1.2:8080", + "[::1]", + "[::1]:8080", + "[ad42::1de2:54c2:c2fa:1234]", + "[ad42::1de2:54c2:c2fa:1234]:8080", ]; server = new Server(options, compiler); @@ -349,12 +349,12 @@ describe('Server', () => { it("should not allow hostnames that don't match options.client.webSocketURL", () => { const options = { client: { - webSocketURL: 'ws://test.host:80', + webSocketURL: "ws://test.host:80", }, }; const headers = { - host: 'test.hostname:80', + host: "test.hostname:80", }; server = new Server(options, compiler); @@ -367,11 +367,11 @@ describe('Server', () => { it('should allow urls with scheme for checking origin when the "option.client.webSocketURL" is string', () => { const options = { client: { - webSocketURL: 'ws://test.host:80', + webSocketURL: "ws://test.host:80", }, }; const headers = { - origin: 'https://test.host', + origin: "https://test.host", }; server = new Server(options, compiler); @@ -385,12 +385,12 @@ describe('Server', () => { const options = { client: { webSocketURL: { - hostname: 'test.host', + hostname: "test.host", }, }, }; const headers = { - origin: 'https://test.host', + origin: "https://test.host", }; server = new Server(options, compiler); @@ -401,17 +401,17 @@ describe('Server', () => { }); }); - describe('Invalidate Callback', () => { - describe('Testing callback functions on calling invalidate without callback', () => { - it('should use default `noop` callback', (done) => { + describe("Invalidate Callback", () => { + describe("Testing callback functions on calling invalidate without callback", () => { + it("should use default `noop` callback", (done) => { const compiler = webpack(config); const server = new Server(baseDevConfig, compiler); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(done); }); - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { throw error; } @@ -423,17 +423,17 @@ describe('Server', () => { }); }); - describe('Testing callback functions on calling invalidate with callback', () => { - it('should use `callback` function', (done) => { + describe("Testing callback functions on calling invalidate with callback", () => { + it("should use `callback` function", (done) => { const compiler = webpack(config); const callback = jest.fn(); const server = new Server(baseDevConfig, compiler); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(done); }); - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { throw error; } @@ -446,7 +446,7 @@ describe('Server', () => { }); }); - describe('WEBPACK_SERVE environment variable', () => { + describe("WEBPACK_SERVE environment variable", () => { const OLD_ENV = process.env; beforeEach(() => { @@ -462,16 +462,16 @@ describe('Server', () => { process.env = OLD_ENV; }); - it('should be present', () => { + it("should be present", () => { expect(process.env.WEBPACK_SERVE).toBeUndefined(); - require('../../lib/Server'); + require("../../lib/Server"); expect(process.env.WEBPACK_SERVE).toBe(true); }); }); - describe('Server.getFreePort', () => { + describe("Server.getFreePort", () => { let dummyServers = []; afterEach(() => { @@ -506,11 +506,11 @@ describe('Server', () => { dummyServers.push(server); - server.listen(60000 + i, '0.0.0.0', () => { + server.listen(60000 + i, "0.0.0.0", () => { resolve(); }); - server.on('error', (error) => { + server.on("error", (error) => { reject(error); }); }) @@ -519,7 +519,7 @@ describe('Server', () => { ); } - it('should returns the port when the port is specified', async () => { + it("should returns the port when the port is specified", async () => { const retryCount = 1; process.env.WEBPACK_DEV_SERVER_PORT_RETRY = retryCount; @@ -528,7 +528,7 @@ describe('Server', () => { expect(freePort).toEqual(8082); }); - it('should returns the port when the port is null', async () => { + it("should returns the port when the port is null", async () => { const retryCount = 2; process.env.WEBPACK_DEV_SERVER_PORT_RETRY = retryCount; @@ -538,7 +538,7 @@ describe('Server', () => { expect(freePort).toEqual(60000 + retryCount); }); - it('should returns the port when the port is undefined', async () => { + it("should returns the port when the port is undefined", async () => { const retryCount = 3; process.env.WEBPACK_DEV_SERVER_PORT_RETRY = retryCount; @@ -549,7 +549,7 @@ describe('Server', () => { expect(freePort).toEqual(60000 + retryCount); }); - it('should retry finding the port for up to defaultPortRetry times (number)', async () => { + it("should retry finding the port for up to defaultPortRetry times (number)", async () => { const retryCount = 4; process.env.WEBPACK_DEV_SERVER_PORT_RETRY = retryCount; @@ -559,7 +559,7 @@ describe('Server', () => { expect(freePort).toEqual(60000 + retryCount); }); - it('should retry finding the port for up to defaultPortRetry times (string)', async () => { + it("should retry finding the port for up to defaultPortRetry times (string)", async () => { const retryCount = 5; process.env.WEBPACK_DEV_SERVER_PORT_RETRY = retryCount; @@ -569,7 +569,7 @@ describe('Server', () => { expect(freePort).toEqual(60000 + retryCount); }); - it('should retry finding the port when serial ports are busy', async () => { + it("should retry finding the port when serial ports are busy", async () => { const busyPorts = [60000, 60001, 60002, 60003, 60004, 60005]; process.env.WEBPACK_DEV_SERVER_PORT_RETRY = 1000; @@ -582,9 +582,9 @@ describe('Server', () => { it("should throws the error when the port isn't found", async () => { expect.assertions(1); - jest.mock('portfinder', () => { + jest.mock("portfinder", () => { return { - getPort: (callback) => callback(new Error('busy')), + getPort: (callback) => callback(new Error("busy")), }; }); diff --git a/test/server/allowedHosts-option.test.js b/test/server/allowedHosts-option.test.js index f6f1cf37df..04354bcdbd 100644 --- a/test/server/allowedHosts-option.test.js +++ b/test/server/allowedHosts-option.test.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const internalIp = require('internal-ip'); -const webpack = require('webpack'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/simple-config/webpack.config'); +const internalIp = require("internal-ip"); +const webpack = require("webpack"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/simple-config/webpack.config"); const createServer = (compiler, options) => new Server(options, compiler); -describe('allowedHosts', () => { +describe("allowedHosts", () => { let compiler; let server; @@ -23,12 +23,12 @@ describe('allowedHosts', () => { }); }); - it('should always allow `localhost` if options.allowedHosts is auto', () => { + it("should always allow `localhost` if options.allowedHosts is auto", () => { const options = { - allowedHosts: 'auto', + allowedHosts: "auto", }; const headers = { - host: 'localhost', + host: "localhost", }; server = createServer(compiler, options); @@ -38,7 +38,7 @@ describe('allowedHosts', () => { } }); - it('should always allow value from the `host` options if options.allowedHosts is auto', () => { + it("should always allow value from the `host` options if options.allowedHosts is auto", () => { const networkIP = internalIp.v4.sync(); const options = { host: networkIP, @@ -54,15 +54,15 @@ describe('allowedHosts', () => { } }); - it('should always allow value of the `host` option from the `client.webSocketURL` option if options.allowedHosts is auto', () => { + it("should always allow value of the `host` option from the `client.webSocketURL` option if options.allowedHosts is auto", () => { const options = { - allowedHosts: 'auto', + allowedHosts: "auto", client: { - webSocketURL: 'ws://test.host:80', + webSocketURL: "ws://test.host:80", }, }; const headers = { - host: 'test.host', + host: "test.host", }; server = createServer(compiler, options); @@ -72,12 +72,12 @@ describe('allowedHosts', () => { } }); - it('should always allow any host if options.allowedHosts is all', () => { + it("should always allow any host if options.allowedHosts is all", () => { const options = { - allowedHosts: 'all', + allowedHosts: "all", }; const headers = { - host: 'bad.host', + host: "bad.host", }; server = createServer(compiler, options); @@ -87,8 +87,8 @@ describe('allowedHosts', () => { } }); - it('should allow hosts in allowedHosts', () => { - const tests = ['test.host', 'test2.host', 'test3.host']; + it("should allow hosts in allowedHosts", () => { + const tests = ["test.host", "test2.host", "test3.host"]; const options = { allowedHosts: tests }; server = createServer(compiler, options); @@ -101,18 +101,18 @@ describe('allowedHosts', () => { }); }); - it('should allow hosts that pass a wildcard in allowedHosts', () => { - const options = { allowedHosts: ['.example.com'] }; + it("should allow hosts that pass a wildcard in allowedHosts", () => { + const options = { allowedHosts: [".example.com"] }; server = createServer(compiler, options); const tests = [ - 'www.example.com', - 'subdomain.example.com', - 'example.com', - 'subsubcomain.subdomain.example.com', - 'example.com:80', - 'subdomain.example.com:80', + "www.example.com", + "subdomain.example.com", + "example.com", + "subsubcomain.subdomain.example.com", + "example.com:80", + "subdomain.example.com:80", ]; tests.forEach((test) => { diff --git a/test/server/bonjour-option.test.js b/test/server/bonjour-option.test.js index 7fb3355085..04e54b71c5 100644 --- a/test/server/bonjour-option.test.js +++ b/test/server/bonjour-option.test.js @@ -1,17 +1,17 @@ -'use strict'; +"use strict"; -const os = require('os'); -const config = require('../fixtures/simple-config/webpack.config'); -const testServer = require('../helpers/test-server'); -const port = require('../ports-map').bonjour; +const os = require("os"); +const config = require("../fixtures/simple-config/webpack.config"); +const testServer = require("../helpers/test-server"); +const port = require("../ports-map").bonjour; -describe('bonjour option', () => { +describe("bonjour option", () => { let server; const mockPublish = jest.fn(); const mockUnpublishAll = jest.fn(); beforeAll(() => { - jest.mock('bonjour', () => () => { + jest.mock("bonjour", () => () => { return { publish: mockPublish, unpublishAll: mockUnpublishAll, @@ -24,7 +24,7 @@ describe('bonjour option', () => { mockUnpublishAll.mockReset(); }); - describe('http', () => { + describe("http", () => { beforeEach((done) => { server = testServer.start( config, @@ -40,19 +40,19 @@ describe('bonjour option', () => { server.close(done); }); - it('should call bonjour with correct params', () => { + it("should call bonjour with correct params", () => { expect(mockPublish).toHaveBeenCalledTimes(1); expect(mockPublish).toHaveBeenCalledWith({ name: `Webpack Dev Server ${os.hostname()}:${port}`, port, - type: 'http', - subtypes: ['webpack'], + type: "http", + subtypes: ["webpack"], }); expect(mockUnpublishAll).toHaveBeenCalledTimes(0); }); }); - describe('https option', () => { + describe("https option", () => { beforeEach((done) => { server = testServer.start( config, @@ -69,26 +69,26 @@ describe('bonjour option', () => { server.close(done); }); - it('bonjour should use https when passed in option', () => { + it("bonjour should use https when passed in option", () => { expect(mockPublish).toHaveBeenCalledTimes(1); expect(mockPublish).toHaveBeenCalledWith({ name: `Webpack Dev Server ${os.hostname()}:${port}`, port, - type: 'https', - subtypes: ['webpack'], + type: "https", + subtypes: ["webpack"], }); expect(mockUnpublishAll).toHaveBeenCalledTimes(0); }); }); - describe('bonjour object', () => { + describe("bonjour object", () => { beforeEach((done) => { server = testServer.start( config, { bonjour: { - type: 'https', - protocol: 'udp', + type: "https", + protocol: "udp", }, port, }, @@ -100,27 +100,27 @@ describe('bonjour option', () => { server.close(done); }); - it('applies bonjour options', () => { + it("applies bonjour options", () => { expect(mockPublish).toHaveBeenCalledTimes(1); expect(mockPublish).toHaveBeenCalledWith({ name: `Webpack Dev Server ${os.hostname()}:${port}`, port, - type: 'https', - protocol: 'udp', - subtypes: ['webpack'], + type: "https", + protocol: "udp", + subtypes: ["webpack"], }); expect(mockUnpublishAll).toHaveBeenCalledTimes(0); }); }); - describe('bonjour object and https', () => { + describe("bonjour object and https", () => { beforeEach((done) => { server = testServer.start( config, { bonjour: { - type: 'http', - protocol: 'udp', + type: "http", + protocol: "udp", }, https: true, port, @@ -133,14 +133,14 @@ describe('bonjour option', () => { server.close(done); }); - it('prefers bonjour options over devServer.https', () => { + it("prefers bonjour options over devServer.https", () => { expect(mockPublish).toHaveBeenCalledTimes(1); expect(mockPublish).toHaveBeenCalledWith({ name: `Webpack Dev Server ${os.hostname()}:${port}`, port, - type: 'http', - protocol: 'udp', - subtypes: ['webpack'], + type: "http", + protocol: "udp", + subtypes: ["webpack"], }); expect(mockUnpublishAll).toHaveBeenCalledTimes(0); }); diff --git a/test/server/built-in-routes.test.js b/test/server/built-in-routes.test.js index aeb3503945..354fe7406f 100644 --- a/test/server/built-in-routes.test.js +++ b/test/server/built-in-routes.test.js @@ -1,17 +1,17 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const request = require('supertest'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/simple-config/webpack.config'); -const multiConfig = require('../fixtures/multi-public-path-config/webpack.config'); -const port = require('../ports-map').routes; +const webpack = require("webpack"); +const request = require("supertest"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/simple-config/webpack.config"); +const multiConfig = require("../fixtures/multi-public-path-config/webpack.config"); +const port = require("../ports-map").routes; -describe('routes util', () => { +describe("routes util", () => { let server; let req; - describe('simple config', () => { + describe("simple config", () => { beforeAll(async () => { const compiler = webpack(config); @@ -23,7 +23,7 @@ describe('routes util', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -45,90 +45,90 @@ describe('routes util', () => { }); }); - it('should handles GET request to sockjs bundle', async () => { + it("should handles GET request to sockjs bundle", async () => { const response = await req.get( - '/__webpack_dev_server__/sockjs.bundle.js' + "/__webpack_dev_server__/sockjs.bundle.js" ); - expect(response.headers['content-type']).toEqual( - 'application/javascript' + expect(response.headers["content-type"]).toEqual( + "application/javascript" ); expect(response.statusCode).toEqual(200); }); - it('should handle HEAD request to sockjs bundle', async () => { + it("should handle HEAD request to sockjs bundle", async () => { const response = await req.head( - '/__webpack_dev_server__/sockjs.bundle.js' + "/__webpack_dev_server__/sockjs.bundle.js" ); - expect(response.headers['content-type']).toEqual( - 'application/javascript' + expect(response.headers["content-type"]).toEqual( + "application/javascript" ); expect(response.statusCode).toEqual(200); }); - it('should handle GET request to invalidate endpoint', async () => { - const response = await req.get('/webpack-dev-server/invalidate'); + it("should handle GET request to invalidate endpoint", async () => { + const response = await req.get("/webpack-dev-server/invalidate"); - expect(response.headers['content-type']).not.toEqual('text/html'); + expect(response.headers["content-type"]).not.toEqual("text/html"); expect(response.statusCode).toEqual(200); }); - it('should handle GET request to live html', async () => { - const response = await req.get('/webpack-dev-server/'); + it("should handle GET request to live html", async () => { + const response = await req.get("/webpack-dev-server/"); - expect(response.headers['content-type']).toEqual('text/html'); + expect(response.headers["content-type"]).toEqual("text/html"); expect(response.statusCode).toEqual(200); }); - it('should handle HEAD request to live html', async () => { - const response = await req.head('/webpack-dev-server/'); + it("should handle HEAD request to live html", async () => { + const response = await req.head("/webpack-dev-server/"); - expect(response.headers['content-type']).toEqual('text/html'); + expect(response.headers["content-type"]).toEqual("text/html"); expect(response.statusCode).toEqual(200); }); - it('should handle GET request to directory index', async () => { - const response = await req.get('/webpack-dev-server'); + it("should handle GET request to directory index", async () => { + const response = await req.get("/webpack-dev-server"); - expect(response.headers['content-type']).toEqual('text/html'); + expect(response.headers["content-type"]).toEqual("text/html"); expect(response.statusCode).toEqual(200); expect(response.text).toMatchSnapshot(); }); - it('should handle HEAD request to directory index', async () => { - const response = await req.head('/webpack-dev-server'); + it("should handle HEAD request to directory index", async () => { + const response = await req.head("/webpack-dev-server"); - expect(response.headers['content-type']).toEqual('text/html'); + expect(response.headers["content-type"]).toEqual("text/html"); expect(response.statusCode).toEqual(200); }); - it('should handle GET request to magic async html', async () => { - const response = await req.get('/main'); + it("should handle GET request to magic async html", async () => { + const response = await req.get("/main"); expect(response.statusCode).toEqual(200); }); - it('should handle HEAD request to magic async html', async () => { - const response = await req.head('/main'); + it("should handle HEAD request to magic async html", async () => { + const response = await req.head("/main"); expect(response.statusCode).toEqual(200); }); - it('should handle GET request to main async chunk', async () => { - const response = await req.get('/main.js'); + it("should handle GET request to main async chunk", async () => { + const response = await req.get("/main.js"); expect(response.statusCode).toEqual(200); }); - it('should handle HEAD request to main async chunk', async () => { - const response = await req.head('/main.js'); + it("should handle HEAD request to main async chunk", async () => { + const response = await req.head("/main.js"); expect(response.statusCode).toEqual(200); }); }); - describe('multi config', () => { + describe("multi config", () => { beforeAll(async () => { const compiler = webpack(multiConfig); @@ -140,7 +140,7 @@ describe('routes util', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -162,10 +162,10 @@ describe('routes util', () => { }); }); - it('should handle GET request to directory index and list all middleware directories', async () => { - const response = await req.get('/webpack-dev-server'); + it("should handle GET request to directory index and list all middleware directories", async () => { + const response = await req.get("/webpack-dev-server"); - expect(response.headers['content-type']).toEqual('text/html'); + expect(response.headers["content-type"]).toEqual("text/html"); expect(response.statusCode).toEqual(200); expect(response.text).toMatchSnapshot(); }); diff --git a/test/server/client-option.test.js b/test/server/client-option.test.js index 0e448142d0..ce0ffa4e62 100644 --- a/test/server/client-option.test.js +++ b/test/server/client-option.test.js @@ -1,32 +1,32 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const request = require('supertest'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/simple-config/webpack.config'); -const port = require('../ports-map')['client-option']; +const webpack = require("webpack"); +const request = require("supertest"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/simple-config/webpack.config"); +const port = require("../ports-map")["client-option"]; -describe('client option', () => { +describe("client option", () => { let server; let req; - describe('default behavior', () => { + describe("default behavior", () => { beforeAll(async () => { const compiler = webpack(config); server = new Server( { client: { - webSocketTransport: 'sockjs', + webSocketTransport: "sockjs", }, - webSocketServer: 'sockjs', + webSocketServer: "sockjs", port, }, compiler ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -48,19 +48,19 @@ describe('client option', () => { }); }); - it('overlay true by default', () => { + it("overlay true by default", () => { expect(server.options.client.overlay).toBe(true); }); - it('responds with a 200', async () => { - const response = await req.get('/ws'); + it("responds with a 200", async () => { + const response = await req.get("/ws"); expect(response.statusCode).toEqual(200); }); }); - describe('path option', () => { - const path = '/foo/test/bar'; + describe("path option", () => { + const path = "/foo/test/bar"; beforeAll(async () => { const compiler = webpack(config); @@ -68,14 +68,14 @@ describe('client option', () => { server = new Server( { client: { - webSocketTransport: 'sockjs', + webSocketTransport: "sockjs", }, webSocketServer: { - type: 'sockjs', + type: "sockjs", options: { - host: 'localhost', + host: "localhost", port, - path: '/foo/test/bar', + path: "/foo/test/bar", }, }, port, @@ -84,7 +84,7 @@ describe('client option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -106,15 +106,15 @@ describe('client option', () => { }); }); - it('responds with a 200 second', async () => { + it("responds with a 200 second", async () => { const response = await req.get(path); expect(response.statusCode).toEqual(200); }); }); - describe('configure client entry', () => { - it('disables client entry', async () => { + describe("configure client entry", () => { + it("disables client entry", async () => { const compiler = webpack(config); server = new Server( @@ -126,7 +126,7 @@ describe('client option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -137,7 +137,7 @@ describe('client option', () => { }); }); - const res = await request(server.app).get('/main.js'); + const res = await request(server.app).get("/main.js"); expect(res.text).not.toMatch(/client\/index\.js/); @@ -148,7 +148,7 @@ describe('client option', () => { }); }); - it('disables hot entry', async () => { + it("disables hot entry", async () => { const compiler = webpack(config); server = new Server( @@ -160,7 +160,7 @@ describe('client option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -171,7 +171,7 @@ describe('client option', () => { }); }); - const res = await request(server.app).get('/main.js'); + const res = await request(server.app).get("/main.js"); expect(res.text).not.toMatch(/webpack\/hot\/dev-server\.js/); @@ -183,40 +183,40 @@ describe('client option', () => { }); }); - describe('webSocketTransport', () => { + describe("webSocketTransport", () => { const clientModes = [ { title: 'as a string ("sockjs")', client: { - webSocketTransport: 'sockjs', + webSocketTransport: "sockjs", }, - webSocketServer: 'sockjs', + webSocketServer: "sockjs", shouldThrow: false, }, { title: 'as a path ("sockjs")', client: { webSocketTransport: require.resolve( - '../../client-src/clients/SockJSClient' + "../../client-src/clients/SockJSClient" ), }, - webSocketServer: 'sockjs', + webSocketServer: "sockjs", shouldThrow: false, }, { - title: 'as a nonexistent path', + title: "as a nonexistent path", client: { - webSocketTransport: '/bad/path/to/implementation', + webSocketTransport: "/bad/path/to/implementation", }, - webSocketServer: 'sockjs', + webSocketServer: "sockjs", shouldThrow: true, }, ]; - describe('passed to server', () => { + describe("passed to server", () => { clientModes.forEach((data) => { it(`${data.title} ${ - data.shouldThrow ? 'should throw' : 'should not throw' + data.shouldThrow ? "should throw" : "should not throw" }`, async () => { const compiler = webpack(config); @@ -232,7 +232,7 @@ describe('client option', () => { try { await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); diff --git a/test/server/compress-option.test.js b/test/server/compress-option.test.js index 477fb3dfae..eeec110c58 100644 --- a/test/server/compress-option.test.js +++ b/test/server/compress-option.test.js @@ -1,23 +1,23 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const request = require('supertest'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/simple-config-other/webpack.config'); -const port = require('../ports-map')['compress-option']; +const webpack = require("webpack"); +const request = require("supertest"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/simple-config-other/webpack.config"); +const port = require("../ports-map")["compress-option"]; -describe('compress option', () => { +describe("compress option", () => { let server; let req; - describe('enabled by default when not specified', () => { + describe("enabled by default when not specified", () => { beforeAll(async () => { const compiler = webpack(config); server = new Server({ port }, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -39,15 +39,15 @@ describe('compress option', () => { }); }); - it('request to bundle file', async () => { - const response = await req.get('/main.js'); + it("request to bundle file", async () => { + const response = await req.get("/main.js"); - expect(response.headers['content-encoding']).toEqual('gzip'); + expect(response.headers["content-encoding"]).toEqual("gzip"); expect(response.status).toEqual(200); }); }); - describe('as a true', () => { + describe("as a true", () => { beforeAll(async () => { const compiler = webpack(config); @@ -60,7 +60,7 @@ describe('compress option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -82,15 +82,15 @@ describe('compress option', () => { }); }); - it('request to bundle file', async () => { - const response = await req.get('/main.js'); + it("request to bundle file", async () => { + const response = await req.get("/main.js"); - expect(response.headers['content-encoding']).toEqual('gzip'); + expect(response.headers["content-encoding"]).toEqual("gzip"); expect(response.status).toEqual(200); }); }); - describe('as a false', () => { + describe("as a false", () => { beforeAll(async () => { const compiler = webpack(config); @@ -103,7 +103,7 @@ describe('compress option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -125,11 +125,11 @@ describe('compress option', () => { }); }); - it('request to bundle file', async () => { - const response = await req.get('/main.js'); + it("request to bundle file", async () => { + const response = await req.get("/main.js"); // eslint-disable-next-line no-undefined - expect(response.headers['content-encoding']).toEqual(undefined); + expect(response.headers["content-encoding"]).toEqual(undefined); expect(response.status).toEqual(200); }); }); diff --git a/test/server/headers-option.test.js b/test/server/headers-option.test.js index 5f122b4d99..5bd1beaa89 100644 --- a/test/server/headers-option.test.js +++ b/test/server/headers-option.test.js @@ -1,29 +1,29 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const request = require('supertest'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/simple-config/webpack.config'); -const port = require('../ports-map')['headers-option']; +const webpack = require("webpack"); +const request = require("supertest"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/simple-config/webpack.config"); +const port = require("../ports-map")["headers-option"]; -describe('headers option', () => { +describe("headers option", () => { let server; let req; - describe('as a string', () => { + describe("as a string", () => { beforeAll(async () => { const compiler = webpack(config); server = new Server( { - headers: { 'X-Foo': '1' }, + headers: { "X-Foo": "1" }, port, }, compiler ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -45,28 +45,28 @@ describe('headers option', () => { }); }); - it('GET request with headers', async () => { - const response = await req.get('/main.js'); + it("GET request with headers", async () => { + const response = await req.get("/main.js"); - expect(response.headers['x-foo']).toEqual('1'); + expect(response.headers["x-foo"]).toEqual("1"); expect(response.status).toEqual(200); }); }); - describe('as an array', () => { + describe("as an array", () => { beforeAll(async () => { const compiler = webpack(config); server = new Server( { - headers: { 'X-Bar': ['key1=value1', 'key2=value2'] }, + headers: { "X-Bar": ["key1=value1", "key2=value2"] }, port, }, compiler ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -88,24 +88,24 @@ describe('headers option', () => { }); }); - it('GET request with headers as an array', async () => { + it("GET request with headers as an array", async () => { // https://github.com/webpack/webpack-dev-server/pull/1650#discussion_r254217027 - const expected = 'key1=value1, key2=value2'; - const response = await req.get('/main.js'); + const expected = "key1=value1, key2=value2"; + const response = await req.get("/main.js"); - expect(response.headers['x-bar']).toEqual(expected); + expect(response.headers["x-bar"]).toEqual(expected); expect(response.status).toEqual(200); }); }); - describe('as a function', () => { + describe("as a function", () => { beforeAll(async () => { const compiler = webpack(config); server = new Server( { headers: () => { - return { 'X-Bar': ['key1=value1', 'key2=value2'] }; + return { "X-Bar": ["key1=value1", "key2=value2"] }; }, port, }, @@ -113,7 +113,7 @@ describe('headers option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -135,25 +135,25 @@ describe('headers option', () => { }); }); - it('GET request with headers as a function', async () => { + it("GET request with headers as a function", async () => { // https://github.com/webpack/webpack-dev-server/pull/1650#discussion_r254217027 - const expected = 'key1=value1, key2=value2'; - const response = await req.get('/main.js'); + const expected = "key1=value1, key2=value2"; + const response = await req.get("/main.js"); - expect(response.headers['x-bar']).toEqual(expected); + expect(response.headers["x-bar"]).toEqual(expected); expect(response.status).toEqual(200); }); }); - describe('dev middleware headers take precedence for dev middleware output files', () => { + describe("dev middleware headers take precedence for dev middleware output files", () => { beforeAll(async () => { const compiler = webpack(config); server = new Server( { - headers: { 'X-Foo': '1' }, + headers: { "X-Foo": "1" }, devMiddleware: { - headers: { 'X-Foo': '2' }, + headers: { "X-Foo": "2" }, }, port, }, @@ -161,7 +161,7 @@ describe('headers option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -183,10 +183,10 @@ describe('headers option', () => { }); }); - it('GET request with headers', async () => { - const response = await req.get('/main.js'); + it("GET request with headers", async () => { + const response = await req.get("/main.js"); - expect(response.headers['x-foo']).toEqual('2'); + expect(response.headers["x-foo"]).toEqual("2"); expect(response.status).toEqual(200); }); }); diff --git a/test/server/historyApiFallback-option.test.js b/test/server/historyApiFallback-option.test.js index fd6d2563b2..e3a059e407 100644 --- a/test/server/historyApiFallback-option.test.js +++ b/test/server/historyApiFallback-option.test.js @@ -1,19 +1,19 @@ -'use strict'; - -const path = require('path'); -const webpack = require('webpack'); -const request = require('supertest'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/historyapifallback-config/webpack.config'); -const config2 = require('../fixtures/historyapifallback-2-config/webpack.config'); -const config3 = require('../fixtures/historyapifallback-3-config/webpack.config'); -const port = require('../ports-map')['history-api-fallback-option']; - -describe('historyApiFallback option', () => { +"use strict"; + +const path = require("path"); +const webpack = require("webpack"); +const request = require("supertest"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/historyapifallback-config/webpack.config"); +const config2 = require("../fixtures/historyapifallback-2-config/webpack.config"); +const config3 = require("../fixtures/historyapifallback-3-config/webpack.config"); +const port = require("../ports-map")["history-api-fallback-option"]; + +describe("historyApiFallback option", () => { let server; let req; - describe('as boolean', () => { + describe("as boolean", () => { beforeAll(async () => { const compiler = webpack(config); @@ -26,7 +26,7 @@ describe('historyApiFallback option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -48,25 +48,25 @@ describe('historyApiFallback option', () => { }); }); - it('request to directory', async () => { - const response = await req.get('/foo').accept('html'); + it("request to directory", async () => { + const response = await req.get("/foo").accept("html"); - expect(response.headers['content-type']).toEqual( - 'text/html; charset=utf-8' + expect(response.headers["content-type"]).toEqual( + "text/html; charset=utf-8" ); expect(response.status).toEqual(200); - expect(response.text).toContain('Heyyy'); + expect(response.text).toContain("Heyyy"); }); }); - describe('as object', () => { + describe("as object", () => { beforeAll(async () => { const compiler = webpack(config); server = new Server( { historyApiFallback: { - index: '/bar.html', + index: "/bar.html", }, port, }, @@ -74,7 +74,7 @@ describe('historyApiFallback option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -96,15 +96,15 @@ describe('historyApiFallback option', () => { }); }); - it('request to directory', async () => { - const response = await req.get('/foo').accept('html'); + it("request to directory", async () => { + const response = await req.get("/foo").accept("html"); expect(response.status).toEqual(200); - expect(response.text).toContain('Foobar'); + expect(response.text).toContain("Foobar"); }); }); - describe('as object with static', () => { + describe("as object with static", () => { beforeAll(async () => { const compiler = webpack(config2); @@ -112,10 +112,10 @@ describe('historyApiFallback option', () => { { static: path.resolve( __dirname, - '../fixtures/historyapifallback-2-config' + "../fixtures/historyapifallback-2-config" ), historyApiFallback: { - index: '/bar.html', + index: "/bar.html", }, port, }, @@ -123,7 +123,7 @@ describe('historyApiFallback option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -145,29 +145,29 @@ describe('historyApiFallback option', () => { }); }); - it('historyApiFallback should take preference above directory index', async () => { - const response = await req.get('/foo').accept('html'); + it("historyApiFallback should take preference above directory index", async () => { + const response = await req.get("/foo").accept("html"); expect(response.status).toEqual(200); - expect(response.text).toContain('Foobar'); + expect(response.text).toContain("Foobar"); }); - it('request to directory', async () => { - const response = await req.get('/foo').accept('html'); + it("request to directory", async () => { + const response = await req.get("/foo").accept("html"); expect(response.status).toEqual(200); - expect(response.text).toContain('Foobar'); + expect(response.text).toContain("Foobar"); }); - it('static file should take preference above historyApiFallback', async () => { - const response = await req.get('/random-file').accept('html'); + it("static file should take preference above historyApiFallback", async () => { + const response = await req.get("/random-file").accept("html"); expect(response.status).toEqual(200); - expect(response.body.toString().trim()).toEqual('Random file'); + expect(response.body.toString().trim()).toEqual("Random file"); }); }); - describe('as object with static set to false', () => { + describe("as object with static set to false", () => { beforeAll(async () => { const compiler = webpack(config3); @@ -175,7 +175,7 @@ describe('historyApiFallback option', () => { { static: false, historyApiFallback: { - index: '/bar.html', + index: "/bar.html", }, port, }, @@ -183,7 +183,7 @@ describe('historyApiFallback option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -205,15 +205,15 @@ describe('historyApiFallback option', () => { }); }); - it('historyApiFallback should work and ignore static content', async () => { - const response = await req.get('/index.html').accept('html'); + it("historyApiFallback should work and ignore static content", async () => { + const response = await req.get("/index.html").accept("html"); expect(response.status).toEqual(200); - expect(response.text).toContain('In-memory file'); + expect(response.text).toContain("In-memory file"); }); }); - describe('as object with static and rewrites', () => { + describe("as object with static and rewrites", () => { beforeAll(async () => { const compiler = webpack(config2); @@ -222,17 +222,17 @@ describe('historyApiFallback option', () => { port, static: path.resolve( __dirname, - '../fixtures/historyapifallback-2-config' + "../fixtures/historyapifallback-2-config" ), historyApiFallback: { rewrites: [ { from: /other/, - to: '/other.html', + to: "/other.html", }, { from: /.*/, - to: '/bar.html', + to: "/bar.html", }, ], }, @@ -241,7 +241,7 @@ describe('historyApiFallback option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -263,25 +263,25 @@ describe('historyApiFallback option', () => { }); }); - it('historyApiFallback respect rewrites for index', async () => { - const response = await req.get('/').accept('html'); + it("historyApiFallback respect rewrites for index", async () => { + const response = await req.get("/").accept("html"); expect(response.status).toEqual(200); - expect(response.text).toContain('Foobar'); + expect(response.text).toContain("Foobar"); }); - it('historyApiFallback respect rewrites and shows index for unknown urls', async () => { - const response = await req.get('/acme').accept('html'); + it("historyApiFallback respect rewrites and shows index for unknown urls", async () => { + const response = await req.get("/acme").accept("html"); expect(response.status).toEqual(200); - expect(response.text).toContain('Foobar'); + expect(response.text).toContain("Foobar"); }); - it('historyApiFallback respect any other specified rewrites', async () => { - const response = await req.get('/other').accept('html'); + it("historyApiFallback respect any other specified rewrites", async () => { + const response = await req.get("/other").accept("html"); expect(response.status).toEqual(200); - expect(response.text).toContain('Other file'); + expect(response.text).toContain("Other file"); }); }); @@ -289,14 +289,14 @@ describe('historyApiFallback option', () => { let consoleSpy; beforeAll(async () => { - consoleSpy = jest.spyOn(global.console, 'log'); + consoleSpy = jest.spyOn(global.console, "log"); const compiler = webpack(config); server = new Server( { historyApiFallback: { - index: '/bar.html', + index: "/bar.html", verbose: true, }, port, @@ -305,7 +305,7 @@ describe('historyApiFallback option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -329,17 +329,17 @@ describe('historyApiFallback option', () => { }); }); - it('request to directory and log', async () => { - const response = await req.get('/foo').accept('html'); + it("request to directory and log", async () => { + const response = await req.get("/foo").accept("html"); expect(response.status).toEqual(200); - expect(response.text).toContain('Foobar'); + expect(response.text).toContain("Foobar"); expect(consoleSpy).toHaveBeenCalledWith( - 'Rewriting', - 'GET', - '/foo', - 'to', - '/bar.html' + "Rewriting", + "GET", + "/foo", + "to", + "/bar.html" ); }); }); @@ -348,14 +348,14 @@ describe('historyApiFallback option', () => { let consoleSpy; beforeAll(async () => { - consoleSpy = jest.spyOn(global.console, 'log'); + consoleSpy = jest.spyOn(global.console, "log"); const compiler = webpack(config); server = new Server( { historyApiFallback: { - index: '/bar.html', + index: "/bar.html", logger: consoleSpy, }, port, @@ -364,7 +364,7 @@ describe('historyApiFallback option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -388,22 +388,22 @@ describe('historyApiFallback option', () => { }); }); - it('request to directory and log', async () => { - const response = await req.get('/foo').accept('html'); + it("request to directory and log", async () => { + const response = await req.get("/foo").accept("html"); expect(response.status).toEqual(200); - expect(response.text).toContain('Foobar'); + expect(response.text).toContain("Foobar"); expect(consoleSpy).toHaveBeenCalledWith( - 'Rewriting', - 'GET', - '/foo', - 'to', - '/bar.html' + "Rewriting", + "GET", + "/foo", + "to", + "/bar.html" ); }); }); - describe('in-memory files', () => { + describe("in-memory files", () => { beforeAll(async () => { const compiler = webpack(config3); @@ -411,7 +411,7 @@ describe('historyApiFallback option', () => { { static: path.resolve( __dirname, - '../fixtures/historyapifallback-3-config' + "../fixtures/historyapifallback-3-config" ), historyApiFallback: true, port, @@ -420,7 +420,7 @@ describe('historyApiFallback option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -442,11 +442,11 @@ describe('historyApiFallback option', () => { }); }); - it('should take precedence over static files', async () => { - const response = await req.get('/foo').accept('html'); + it("should take precedence over static files", async () => { + const response = await req.get("/foo").accept("html"); expect(response.status).toEqual(200); - expect(response.text).toContain('In-memory file'); + expect(response.text).toContain("In-memory file"); }); }); }); diff --git a/test/server/host-option.test.js b/test/server/host-option.test.js index fb3255a46b..42cbe1861f 100644 --- a/test/server/host-option.test.js +++ b/test/server/host-option.test.js @@ -1,24 +1,24 @@ -'use strict'; +"use strict"; -const path = require('path'); -const webpack = require('webpack'); -const request = require('supertest'); -const internalIp = require('internal-ip'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/simple-config/webpack.config'); -const port = require('../ports-map')['host-option']; +const path = require("path"); +const webpack = require("webpack"); +const request = require("supertest"); +const internalIp = require("internal-ip"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/simple-config/webpack.config"); +const port = require("../ports-map")["host-option"]; const staticDirectory = path.resolve( __dirname, - '../fixtures/contentbase-config' + "../fixtures/contentbase-config" ); const internalIPv4 = internalIp.v4.sync(); -describe('host option', () => { +describe("host option", () => { let server = null; let req = null; - describe('is not be specified', () => { + describe("is not be specified", () => { beforeAll(async () => { const compiler = webpack(config); @@ -34,7 +34,7 @@ describe('host option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -56,21 +56,21 @@ describe('host option', () => { }); }); - it('server address', () => { + it("server address", () => { const address = server.server.address(); - expect(address.address).toBe('127.0.0.1'); + expect(address.address).toBe("127.0.0.1"); expect(address.port).toBe(port); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.status).toEqual(200); }); }); - describe('is undefined', () => { + describe("is undefined", () => { beforeAll(async () => { const compiler = webpack(config); @@ -88,7 +88,7 @@ describe('host option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '::', (error) => { + server.listen(port, "::", (error) => { if (error) { reject(error); @@ -110,21 +110,21 @@ describe('host option', () => { }); }); - it('server address', () => { + it("server address", () => { const address = server.server.address(); - expect(address.address).toBe('::'); + expect(address.address).toBe("::"); expect(address.port).toBe(port); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.status).toEqual(200); }); }); - describe('is 127.0.0.1 (IPv4)', () => { + describe("is 127.0.0.1 (IPv4)", () => { beforeAll(async () => { const compiler = webpack(config); @@ -134,14 +134,14 @@ describe('host option', () => { directory: staticDirectory, watch: false, }, - host: '127.0.0.1', + host: "127.0.0.1", port, }, compiler ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -163,21 +163,21 @@ describe('host option', () => { }); }); - it('server address', () => { + it("server address", () => { const address = server.server.address(); - expect(address.address).toBe('127.0.0.1'); + expect(address.address).toBe("127.0.0.1"); expect(address.port).toBe(port); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.status).toEqual(200); }); }); - describe('is localhost', () => { + describe("is localhost", () => { beforeAll(async () => { const compiler = webpack(config); @@ -187,14 +187,14 @@ describe('host option', () => { directory: staticDirectory, watch: false, }, - host: 'localhost', + host: "localhost", port, }, compiler ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -216,21 +216,21 @@ describe('host option', () => { }); }); - it('server address', () => { + it("server address", () => { const address = server.server.address(); - expect(address.address).toBe('127.0.0.1'); + expect(address.address).toBe("127.0.0.1"); expect(address.port).toBe(port); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.status).toEqual(200); }); }); - describe('is 0.0.0.0', () => { + describe("is 0.0.0.0", () => { beforeAll(async () => { const compiler = webpack(config); @@ -240,14 +240,14 @@ describe('host option', () => { directory: staticDirectory, watch: false, }, - host: '0.0.0.0', + host: "0.0.0.0", port, }, compiler ); await new Promise((resolve, reject) => { - server.listen(port, '0.0.0.0', (error) => { + server.listen(port, "0.0.0.0", (error) => { if (error) { reject(error); @@ -269,21 +269,21 @@ describe('host option', () => { }); }); - it('server address', () => { + it("server address", () => { const address = server.server.address(); - expect(address.address).toBe('0.0.0.0'); + expect(address.address).toBe("0.0.0.0"); expect(address.port).toBe(port); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.status).toEqual(200); }); }); - describe('is local-ip', () => { + describe("is local-ip", () => { beforeAll(async () => { const compiler = webpack(config); @@ -293,7 +293,7 @@ describe('host option', () => { directory: staticDirectory, watch: false, }, - host: 'local-ip', + host: "local-ip", port, }, compiler @@ -322,21 +322,21 @@ describe('host option', () => { }); }); - it('server address', () => { + it("server address", () => { const address = server.server.address(); expect(address.address).toBe(internalIPv4); expect(address.port).toBe(port); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.status).toEqual(200); }); }); - describe('is local-ipv4', () => { + describe("is local-ipv4", () => { beforeAll(async () => { const compiler = webpack(config); @@ -346,7 +346,7 @@ describe('host option', () => { directory: staticDirectory, watch: false, }, - host: 'local-ipv4', + host: "local-ipv4", port, }, compiler @@ -375,15 +375,15 @@ describe('host option', () => { }); }); - it('server address', () => { + it("server address", () => { const address = server.server.address(); expect(address.address).toBe(internalIPv4); expect(address.port).toBe(port); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.status).toEqual(200); }); diff --git a/test/server/hot-option.test.js b/test/server/hot-option.test.js index eabc24c89a..9b0d48e9cb 100644 --- a/test/server/hot-option.test.js +++ b/test/server/hot-option.test.js @@ -1,24 +1,24 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const request = require('supertest'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/client-config/webpack.config'); -const multiCompilerConfig = require('../fixtures/multi-compiler-config/webpack.config'); -const port = require('../ports-map')['hot-option']; +const webpack = require("webpack"); +const request = require("supertest"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/client-config/webpack.config"); +const multiCompilerConfig = require("../fixtures/multi-compiler-config/webpack.config"); +const port = require("../ports-map")["hot-option"]; -describe('hot option', () => { +describe("hot option", () => { let server; let req; - describe('simple hot config entries', () => { + describe("simple hot config entries", () => { beforeAll(async () => { const compiler = webpack(config); server = new Server({ port }, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -40,28 +40,28 @@ describe('hot option', () => { }); }); - it('should include hot script in the bundle', async () => { - const response = await req.get('/main.js'); + it("should include hot script in the bundle", async () => { + const response = await req.get("/main.js"); expect(response.status).toEqual(200); - expect(response.text).toContain('webpack/hot/dev-server.js'); + expect(response.text).toContain("webpack/hot/dev-server.js"); }); }); - describe('simple hot-only config entries', () => { + describe("simple hot-only config entries", () => { beforeAll(async () => { const compiler = webpack(config); server = new Server( { port, - hot: 'only', + hot: "only", }, compiler ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -83,22 +83,22 @@ describe('hot option', () => { }); }); - it('should include hot-only script in the bundle', async () => { - const response = await req.get('/main.js'); + it("should include hot-only script in the bundle", async () => { + const response = await req.get("/main.js"); expect(response.status).toEqual(200); - expect(response.text).toContain('webpack/hot/only-dev-server.js'); + expect(response.text).toContain("webpack/hot/only-dev-server.js"); }); }); - describe('multi compiler hot config entries', () => { + describe("multi compiler hot config entries", () => { beforeAll(async () => { const compiler = webpack(multiCompilerConfig); server = new Server({ port }, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -120,22 +120,22 @@ describe('hot option', () => { }); }); - it('should include hot script in the bundle', async () => { - const response = await req.get('/main.js'); + it("should include hot script in the bundle", async () => { + const response = await req.get("/main.js"); expect(response.status).toEqual(200); - expect(response.text).toContain('webpack/hot/dev-server.js'); + expect(response.text).toContain("webpack/hot/dev-server.js"); }); }); - describe('hot disabled entries', () => { + describe("hot disabled entries", () => { beforeAll(async () => { const compiler = webpack(multiCompilerConfig); server = new Server({ port, hot: false }, compiler); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -157,8 +157,8 @@ describe('hot option', () => { }); }); - it('should NOT include hot script in the bundle', async () => { - const response = await req.get('/main.js'); + it("should NOT include hot script in the bundle", async () => { + const response = await req.get("/main.js"); expect(response.status).toEqual(200); expect(response.text).not.toMatch(/webpack\/hot\/dev-server\.js/); @@ -168,14 +168,14 @@ describe('hot option', () => { // the following cases check to make sure that the HMR // plugin is actually added - describe('simple hot config HMR plugin', () => { - it('should register the HMR plugin before compilation is complete', async () => { + describe("simple hot config HMR plugin", () => { + it("should register the HMR plugin before compilation is complete", async () => { let pluginFound = false; const compiler = webpack(config); compiler.hooks.compilation.intercept({ register: (tapInfo) => { - if (tapInfo.name === 'HotModuleReplacementPlugin') { + if (tapInfo.name === "HotModuleReplacementPlugin") { pluginFound = true; } @@ -186,7 +186,7 @@ describe('hot option', () => { const serverInTest = new Server({ port }, compiler); await new Promise((resolve, reject) => { - serverInTest.listen(port, '127.0.0.1', (error) => { + serverInTest.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -207,14 +207,14 @@ describe('hot option', () => { }); }); - describe('multi compiler hot config HMR plugin', () => { - it('should register the HMR plugin before compilation is complete', async () => { + describe("multi compiler hot config HMR plugin", () => { + it("should register the HMR plugin before compilation is complete", async () => { let pluginFound = false; const compiler = webpack(multiCompilerConfig); compiler.compilers[0].hooks.compilation.intercept({ register: (tapInfo) => { - if (tapInfo.name === 'HotModuleReplacementPlugin') { + if (tapInfo.name === "HotModuleReplacementPlugin") { pluginFound = true; } @@ -225,7 +225,7 @@ describe('hot option', () => { const serverInTest = new Server({ port }, compiler); await new Promise((resolve, reject) => { - serverInTest.listen(port, '127.0.0.1', (error) => { + serverInTest.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -246,14 +246,14 @@ describe('hot option', () => { }); }); - describe('hot disabled HMR plugin', () => { - it('should NOT register the HMR plugin before compilation is complete', async () => { + describe("hot disabled HMR plugin", () => { + it("should NOT register the HMR plugin before compilation is complete", async () => { let pluginFound = false; const compiler = webpack(config); compiler.hooks.compilation.intercept({ register: (tapInfo) => { - if (tapInfo.name === 'HotModuleReplacementPlugin') { + if (tapInfo.name === "HotModuleReplacementPlugin") { pluginFound = true; } @@ -264,7 +264,7 @@ describe('hot option', () => { const serverInTest = new Server({ port, hot: false }, compiler); await new Promise((resolve, reject) => { - serverInTest.listen(port, '127.0.0.1', (error) => { + serverInTest.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); diff --git a/test/server/http2-option.test.js b/test/server/http2-option.test.js index 1fc25b85e7..413b2293b4 100644 --- a/test/server/http2-option.test.js +++ b/test/server/http2-option.test.js @@ -1,23 +1,23 @@ -'use strict'; +"use strict"; -const path = require('path'); -const http2 = require('http2'); -const webpack = require('webpack'); -const request = require('supertest'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/contentbase-config/webpack.config'); -const port = require('../ports-map')['http2-option']; +const path = require("path"); +const http2 = require("http2"); +const webpack = require("webpack"); +const request = require("supertest"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/contentbase-config/webpack.config"); +const port = require("../ports-map")["http2-option"]; const staticDirectory = path.resolve( __dirname, - '../fixtures/contentbase-config/public' + "../fixtures/contentbase-config/public" ); describe('"http2" option', () => { let server; let req; - describe('http2 works with https', () => { + describe("http2 works with https", () => { beforeAll(async () => { const compiler = webpack(config); @@ -32,7 +32,7 @@ describe('"http2" option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -54,27 +54,27 @@ describe('"http2" option', () => { }); }); - it('confirm http2 client can connect', (done) => { + it("confirm http2 client can connect", (done) => { const client = http2.connect(`https://localhost:${port}`, { rejectUnauthorized: false, }); - client.on('error', (err) => console.error(err)); + client.on("error", (err) => console.error(err)); - const http2Req = client.request({ ':path': '/' }); + const http2Req = client.request({ ":path": "/" }); - http2Req.on('response', (headers) => { - expect(headers[':status']).toEqual(200); + http2Req.on("response", (headers) => { + expect(headers[":status"]).toEqual(200); }); - http2Req.setEncoding('utf8'); + http2Req.setEncoding("utf8"); - let data = ''; + let data = ""; - http2Req.on('data', (chunk) => { + http2Req.on("data", (chunk) => { data += chunk; }); - http2Req.on('end', () => { + http2Req.on("end", () => { expect(data).toEqual(expect.stringMatching(/Heyo/)); done(); }); @@ -82,7 +82,7 @@ describe('"http2" option', () => { }); }); - describe('server works with http2 option, but without https option', () => { + describe("server works with http2 option, but without https option", () => { beforeAll(async () => { const compiler = webpack(config); @@ -96,7 +96,7 @@ describe('"http2" option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -118,15 +118,15 @@ describe('"http2" option', () => { }); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.status).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); }); - describe('https without http2 disables HTTP/2', () => { + describe("https without http2 disables HTTP/2", () => { beforeAll(async () => { const compiler = webpack(config); @@ -141,7 +141,7 @@ describe('"http2" option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -163,12 +163,12 @@ describe('"http2" option', () => { }); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.status).toEqual(200); - expect(response.text).toContain('Heyo'); - expect(response.res.httpVersion).not.toEqual('2.0'); + expect(response.text).toContain("Heyo"); + expect(response.res.httpVersion).not.toEqual("2.0"); }); }); }); diff --git a/test/server/https-option.test.js b/test/server/https-option.test.js index eb91d5463a..a18065bdcf 100644 --- a/test/server/https-option.test.js +++ b/test/server/https-option.test.js @@ -1,28 +1,28 @@ -'use strict'; +"use strict"; -const path = require('path'); -const fs = require('graceful-fs'); -const request = require('supertest'); -const webpack = require('webpack'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/contentbase-config/webpack.config'); -const { skipTestOnWindows } = require('../helpers/conditional-test'); -const port = require('../ports-map')['https-option']; +const path = require("path"); +const fs = require("graceful-fs"); +const request = require("supertest"); +const webpack = require("webpack"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/contentbase-config/webpack.config"); +const { skipTestOnWindows } = require("../helpers/conditional-test"); +const port = require("../ports-map")["https-option"]; const httpsCertificateDirectory = path.resolve( __dirname, - '../fixtures/https-certificate' + "../fixtures/https-certificate" ); const contentBasePublic = path.resolve( __dirname, - '../fixtures/contentbase-config/public' + "../fixtures/contentbase-config/public" ); -describe('https option', () => { +describe("https option", () => { let server; let req; - describe('as a boolean', () => { + describe("as a boolean", () => { beforeAll(async () => { const compiler = webpack(config); @@ -39,7 +39,7 @@ describe('https option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '::', (error) => { + server.listen(port, "::", (error) => { if (error) { reject(error); @@ -61,15 +61,15 @@ describe('https option', () => { }); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.status).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); }); - describe('as an object when cacert, pfx, key and cert are buffer', () => { + describe("as an object when cacert, pfx, key and cert are buffer", () => { beforeAll(async () => { const compiler = webpack(config); @@ -81,18 +81,18 @@ describe('https option', () => { }, https: { cacert: fs.readFileSync( - path.join(httpsCertificateDirectory, 'ca.pem') + path.join(httpsCertificateDirectory, "ca.pem") ), pfx: fs.readFileSync( - path.join(httpsCertificateDirectory, 'server.pfx') + path.join(httpsCertificateDirectory, "server.pfx") ), key: fs.readFileSync( - path.join(httpsCertificateDirectory, 'server.key') + path.join(httpsCertificateDirectory, "server.key") ), cert: fs.readFileSync( - path.join(httpsCertificateDirectory, 'server.crt') + path.join(httpsCertificateDirectory, "server.crt") ), - passphrase: 'webpack-dev-server', + passphrase: "webpack-dev-server", }, port, }, @@ -100,7 +100,7 @@ describe('https option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '::', (error) => { + server.listen(port, "::", (error) => { if (error) { reject(error); @@ -122,15 +122,15 @@ describe('https option', () => { }); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.status).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); }); - describe('as an object when cacert, pfx, key and cert are paths', () => { + describe("as an object when cacert, pfx, key and cert are paths", () => { beforeAll(async () => { const compiler = webpack(config); @@ -138,11 +138,11 @@ describe('https option', () => { { static: contentBasePublic, https: { - cacert: path.join(httpsCertificateDirectory, 'ca.pem'), - pfx: path.join(httpsCertificateDirectory, 'server.pfx'), - key: path.join(httpsCertificateDirectory, 'server.key'), - cert: path.join(httpsCertificateDirectory, 'server.crt'), - passphrase: 'webpack-dev-server', + cacert: path.join(httpsCertificateDirectory, "ca.pem"), + pfx: path.join(httpsCertificateDirectory, "server.pfx"), + key: path.join(httpsCertificateDirectory, "server.key"), + cert: path.join(httpsCertificateDirectory, "server.crt"), + passphrase: "webpack-dev-server", }, port, }, @@ -150,7 +150,7 @@ describe('https option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '::', (error) => { + server.listen(port, "::", (error) => { if (error) { reject(error); @@ -172,16 +172,16 @@ describe('https option', () => { }); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.status).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); }); - describe('as an object when cacert, pfx, key and cert are symlinks', () => { - if (skipTestOnWindows('Symlinks are not supported on Windows')) { + describe("as an object when cacert, pfx, key and cert are symlinks", () => { + if (skipTestOnWindows("Symlinks are not supported on Windows")) { return; } @@ -195,11 +195,11 @@ describe('https option', () => { watch: false, }, https: { - cacert: path.join(httpsCertificateDirectory, 'ca-symlink.pem'), - pfx: path.join(httpsCertificateDirectory, 'server-symlink.pfx'), - key: path.join(httpsCertificateDirectory, 'server-symlink.key'), - cert: path.join(httpsCertificateDirectory, 'server-symlink.crt'), - passphrase: 'webpack-dev-server', + cacert: path.join(httpsCertificateDirectory, "ca-symlink.pem"), + pfx: path.join(httpsCertificateDirectory, "server-symlink.pfx"), + key: path.join(httpsCertificateDirectory, "server-symlink.key"), + cert: path.join(httpsCertificateDirectory, "server-symlink.crt"), + passphrase: "webpack-dev-server", }, port, }, @@ -207,7 +207,7 @@ describe('https option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '::', (error) => { + server.listen(port, "::", (error) => { if (error) { reject(error); @@ -229,15 +229,15 @@ describe('https option', () => { }); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.status).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); }); - describe('as an object when cacert, pfx, key and cert are raw strings', () => { + describe("as an object when cacert, pfx, key and cert are raw strings", () => { beforeAll(async () => { const compiler = webpack(config); @@ -249,19 +249,19 @@ describe('https option', () => { }, https: { cacert: fs - .readFileSync(path.join(httpsCertificateDirectory, 'ca.pem')) + .readFileSync(path.join(httpsCertificateDirectory, "ca.pem")) .toString(), // pfx can't be string because it is binary format pfx: fs.readFileSync( - path.join(httpsCertificateDirectory, 'server.pfx') + path.join(httpsCertificateDirectory, "server.pfx") ), key: fs - .readFileSync(path.join(httpsCertificateDirectory, 'server.key')) + .readFileSync(path.join(httpsCertificateDirectory, "server.key")) .toString(), cert: fs - .readFileSync(path.join(httpsCertificateDirectory, 'server.crt')) + .readFileSync(path.join(httpsCertificateDirectory, "server.crt")) .toString(), - passphrase: 'webpack-dev-server', + passphrase: "webpack-dev-server", }, port, }, @@ -269,7 +269,7 @@ describe('https option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '::', (error) => { + server.listen(port, "::", (error) => { if (error) { reject(error); @@ -291,11 +291,11 @@ describe('https option', () => { }); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.status).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); }); @@ -312,18 +312,18 @@ describe('https option', () => { https: { requestCert: true, cacert: fs.readFileSync( - path.join(httpsCertificateDirectory, 'ca.pem') + path.join(httpsCertificateDirectory, "ca.pem") ), pfx: fs.readFileSync( - path.join(httpsCertificateDirectory, 'server.pfx') + path.join(httpsCertificateDirectory, "server.pfx") ), key: fs.readFileSync( - path.join(httpsCertificateDirectory, 'server.key') + path.join(httpsCertificateDirectory, "server.key") ), cert: fs.readFileSync( - path.join(httpsCertificateDirectory, 'server.crt') + path.join(httpsCertificateDirectory, "server.crt") ), - passphrase: 'webpack-dev-server', + passphrase: "webpack-dev-server", }, port, }, @@ -331,7 +331,7 @@ describe('https option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '::', (error) => { + server.listen(port, "::", (error) => { if (error) { reject(error); @@ -353,11 +353,11 @@ describe('https option', () => { }); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.status).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); }); }); diff --git a/test/server/mimeTypes-option.test.js b/test/server/mimeTypes-option.test.js index ea342f47de..6df1b1e744 100644 --- a/test/server/mimeTypes-option.test.js +++ b/test/server/mimeTypes-option.test.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const request = require('supertest'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/mime-types-config/webpack.config'); -const port = require('../ports-map')['mine-types-option']; +const webpack = require("webpack"); +const request = require("supertest"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/mime-types-config/webpack.config"); +const port = require("../ports-map")["mine-types-option"]; describe('"mimeTypes" option', () => { - describe('as an object with a remapped type', () => { + describe("as an object with a remapped type", () => { let server; let req; @@ -18,7 +18,7 @@ describe('"mimeTypes" option', () => { { devMiddleware: { mimeTypes: { - js: 'application/octet-stream', + js: "application/octet-stream", }, }, port, @@ -27,7 +27,7 @@ describe('"mimeTypes" option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -49,17 +49,17 @@ describe('"mimeTypes" option', () => { }); }); - it('requests file with different js mime type', async () => { - const response = await req.get('/main.js'); + it("requests file with different js mime type", async () => { + const response = await req.get("/main.js"); expect(response.status).toEqual(200); - expect(response.headers['content-type']).toEqual( - 'application/octet-stream' + expect(response.headers["content-type"]).toEqual( + "application/octet-stream" ); }); }); - describe('as an object with a custom type', () => { + describe("as an object with a custom type", () => { let server; let req; @@ -70,7 +70,7 @@ describe('"mimeTypes" option', () => { { devMiddleware: { mimeTypes: { - custom: 'text/html', + custom: "text/html", }, }, port, @@ -79,7 +79,7 @@ describe('"mimeTypes" option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -101,12 +101,12 @@ describe('"mimeTypes" option', () => { }); }); - it('requests file with custom mime type', async () => { - const response = await req.get('/file.custom'); + it("requests file with custom mime type", async () => { + const response = await req.get("/file.custom"); expect(response.status).toEqual(200); - expect(response.headers['content-type']).toEqual( - 'text/html; charset=utf-8' + expect(response.headers["content-type"]).toEqual( + "text/html; charset=utf-8" ); }); }); diff --git a/test/server/onAfterSetupMiddleware-option.test.js b/test/server/onAfterSetupMiddleware-option.test.js index b332664875..74725d6969 100644 --- a/test/server/onAfterSetupMiddleware-option.test.js +++ b/test/server/onAfterSetupMiddleware-option.test.js @@ -1,12 +1,12 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const request = require('supertest'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/simple-config/webpack.config'); -const port = require('../ports-map')['on-after-setup-middleware-option']; +const webpack = require("webpack"); +const request = require("supertest"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/simple-config/webpack.config"); +const port = require("../ports-map")["on-after-setup-middleware-option"]; -describe('onAfterSetupMiddleware option', () => { +describe("onAfterSetupMiddleware option", () => { let server; let req; @@ -17,19 +17,19 @@ describe('onAfterSetupMiddleware option', () => { { onAfterSetupMiddleware: (self) => { if (!self.app) { - throw new Error('app is not defined'); + throw new Error("app is not defined"); } if (!self.compiler) { - throw new Error('compiler is not defined'); + throw new Error("compiler is not defined"); } - self.app.get('/after/some/path', (_, response) => { - response.send('after'); + self.app.get("/after/some/path", (_, response) => { + response.send("after"); }); - self.app.post('/after/some/path', (_, response) => { - response.send('after POST'); + self.app.post("/after/some/path", (_, response) => { + response.send("after POST"); }); }, port, @@ -38,7 +38,7 @@ describe('onAfterSetupMiddleware option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -60,23 +60,23 @@ describe('onAfterSetupMiddleware option', () => { }); }); - it('should handle after route', async () => { - const response = await req.get('/after/some/path'); + it("should handle after route", async () => { + const response = await req.get("/after/some/path"); - expect(response.headers['content-type']).toEqual( - 'text/html; charset=utf-8' + expect(response.headers["content-type"]).toEqual( + "text/html; charset=utf-8" ); expect(response.status).toEqual(200); - expect(response.text).toBe('after'); + expect(response.text).toBe("after"); }); - it('should handle POST requests to after route', async () => { - const response = await req.post('/after/some/path'); + it("should handle POST requests to after route", async () => { + const response = await req.post("/after/some/path"); - expect(response.headers['content-type']).toEqual( - 'text/html; charset=utf-8' + expect(response.headers["content-type"]).toEqual( + "text/html; charset=utf-8" ); expect(response.status).toEqual(200); - expect(response.text).toBe('after POST'); + expect(response.text).toBe("after POST"); }); }); diff --git a/test/server/onBeforeSetupMiddleware-option.test.js b/test/server/onBeforeSetupMiddleware-option.test.js index 9681d36b63..50cf5c9f8d 100644 --- a/test/server/onBeforeSetupMiddleware-option.test.js +++ b/test/server/onBeforeSetupMiddleware-option.test.js @@ -1,12 +1,12 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const request = require('supertest'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/simple-config/webpack.config'); -const port = require('../ports-map')['on-before-setup-middleware-option']; +const webpack = require("webpack"); +const request = require("supertest"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/simple-config/webpack.config"); +const port = require("../ports-map")["on-before-setup-middleware-option"]; -describe('onBeforeSetupMiddleware option', () => { +describe("onBeforeSetupMiddleware option", () => { let server; let req; @@ -17,15 +17,15 @@ describe('onBeforeSetupMiddleware option', () => { { onBeforeSetupMiddleware: (self) => { if (!self.app) { - throw new Error('app is not defined'); + throw new Error("app is not defined"); } if (!self.compiler) { - throw new Error('compiler is not defined'); + throw new Error("compiler is not defined"); } - self.app.get('/before/some/path', (_, response) => { - response.send('before'); + self.app.get("/before/some/path", (_, response) => { + response.send("before"); }); }, port, @@ -34,7 +34,7 @@ describe('onBeforeSetupMiddleware option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -55,13 +55,13 @@ describe('onBeforeSetupMiddleware option', () => { }); }); - it('should handle before route', async () => { - const response = await req.get('/before/some/path'); + it("should handle before route", async () => { + const response = await req.get("/before/some/path"); - expect(response.headers['content-type']).toEqual( - 'text/html; charset=utf-8' + expect(response.headers["content-type"]).toEqual( + "text/html; charset=utf-8" ); expect(response.status).toEqual(200); - expect(response.text).toBe('before'); + expect(response.text).toBe("before"); }); }); diff --git a/test/server/onListening-option.test.js b/test/server/onListening-option.test.js index 16f61d608e..d7d165edaa 100644 --- a/test/server/onListening-option.test.js +++ b/test/server/onListening-option.test.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/simple-config/webpack.config'); -const port = require('../ports-map')['on-listening-option']; +const webpack = require("webpack"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/simple-config/webpack.config"); +const port = require("../ports-map")["on-listening-option"]; -describe('onListening option', () => { +describe("onListening option", () => { let server; let onListeningIsRunning = false; @@ -16,7 +16,7 @@ describe('onListening option', () => { { onListening: (devServer) => { if (!devServer) { - throw new Error('webpack-dev-server is not defined'); + throw new Error("webpack-dev-server is not defined"); } onListeningIsRunning = true; @@ -27,7 +27,7 @@ describe('onListening option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -47,7 +47,7 @@ describe('onListening option', () => { }); }); - it('should runs onListening callback', () => { + it("should runs onListening callback", () => { expect(onListeningIsRunning).toBe(true); }); }); diff --git a/test/server/open-option.test.js b/test/server/open-option.test.js index b6e0dd4cd1..c529981eb6 100644 --- a/test/server/open-option.test.js +++ b/test/server/open-option.test.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; -const internalIp = require('internal-ip'); -const webpack = require('webpack'); -const open = require('open'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/simple-config/webpack.config'); -const port = require('../ports-map')['open-option']; +const internalIp = require("internal-ip"); +const webpack = require("webpack"); +const open = require("open"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/simple-config/webpack.config"); +const port = require("../ports-map")["open-option"]; -jest.mock('open'); +jest.mock("open"); open.mockImplementation(() => { return { @@ -36,7 +36,7 @@ describe('"open" option', () => { }); }); - it('should work with unspecified host', (done) => { + it("should work with unspecified host", (done) => { server = new Server( { open: true, @@ -45,7 +45,7 @@ describe('"open" option', () => { compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://localhost:${port}/`, { wait: false, @@ -68,7 +68,7 @@ describe('"open" option', () => { compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`https://localhost:${port}/`, { wait: false, @@ -82,7 +82,7 @@ describe('"open" option', () => { }); it("should work with '0.0.0.0' host", (done) => { - const host = '0.0.0.0'; + const host = "0.0.0.0"; server = new Server( { host, @@ -92,7 +92,7 @@ describe('"open" option', () => { compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${host}:${port}/`, { wait: false, @@ -106,7 +106,7 @@ describe('"open" option', () => { }); it("should work with '::' host", (done) => { - const host = '::'; + const host = "::"; server = new Server( { host, @@ -116,7 +116,7 @@ describe('"open" option', () => { compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://[${host}]:${port}/`, { wait: false, @@ -130,7 +130,7 @@ describe('"open" option', () => { }); it("should work with 'localhost' host", (done) => { - const host = 'localhost'; + const host = "localhost"; server = new Server( { host, @@ -140,7 +140,7 @@ describe('"open" option', () => { compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${host}:${port}/`, { wait: false, @@ -154,7 +154,7 @@ describe('"open" option', () => { }); it("should work with '127.0.0.1' host", (done) => { - const host = '127.0.0.1'; + const host = "127.0.0.1"; server = new Server( { host, @@ -164,7 +164,7 @@ describe('"open" option', () => { compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${host}:${port}/`, { wait: false, @@ -178,7 +178,7 @@ describe('"open" option', () => { }); it("should work with '::1' host", (done) => { - const host = '::1'; + const host = "::1"; server = new Server( { host, @@ -188,7 +188,7 @@ describe('"open" option', () => { compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://[${host}]:${port}/`, { wait: false, @@ -210,7 +210,7 @@ describe('"open" option', () => { compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${internalIPv4}:${port}/`, { wait: false, @@ -223,8 +223,8 @@ describe('"open" option', () => { server.listen(port, internalIPv4); }); - it('should work with boolean', (done) => { - const host = 'localhost'; + it("should work with boolean", (done) => { + const host = "localhost"; server = new Server( { host, @@ -234,7 +234,7 @@ describe('"open" option', () => { compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${host}:${port}/`, { wait: false, @@ -248,7 +248,7 @@ describe('"open" option', () => { }); it("should work with boolean but don't close with 'false' value", (done) => { - const host = 'localhost'; + const host = "localhost"; server = new Server( { host, @@ -258,7 +258,7 @@ describe('"open" option', () => { compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).not.toHaveBeenCalled(); @@ -269,18 +269,18 @@ describe('"open" option', () => { server.listen(port, host); }); - it('should work with relative string', (done) => { - const host = 'localhost'; + it("should work with relative string", (done) => { + const host = "localhost"; server = new Server( { host, port, - open: 'index.html', + open: "index.html", }, compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${host}:${port}/index.html`, { wait: false, @@ -294,17 +294,17 @@ describe('"open" option', () => { }); it('should work with "" pattern', (done) => { - const host = 'localhost'; + const host = "localhost"; server = new Server( { host, port, - open: '', + open: "", }, compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${host}:${port}/`, { wait: false, @@ -318,17 +318,17 @@ describe('"open" option', () => { }); it('should work with relative string starting with "/"', (done) => { - const host = 'localhost'; + const host = "localhost"; server = new Server( { host, port, - open: '/index.html', + open: "/index.html", }, compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${host}:${port}/index.html`, { wait: false, @@ -341,18 +341,18 @@ describe('"open" option', () => { server.listen(port, host); }); - it('should work with absolute string', (done) => { - const host = 'localhost'; + it("should work with absolute string", (done) => { + const host = "localhost"; server = new Server( { open: `http://${host}:${port}/index.html`, port, - host: 'localhost', + host: "localhost", }, compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${host}:${port}/index.html`, { wait: false, @@ -365,18 +365,18 @@ describe('"open" option', () => { server.listen(port, host); }); - it('should work with multiple relative strings', (done) => { - const host = 'localhost'; + it("should work with multiple relative strings", (done) => { + const host = "localhost"; server = new Server( { - host: 'localhost', + host: "localhost", port, - open: ['first.html', 'second.html'], + open: ["first.html", "second.html"], }, compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenNthCalledWith( 1, @@ -400,11 +400,11 @@ describe('"open" option', () => { server.listen(port, host); }); - it('should work with multiple absolute strings', (done) => { - const host = 'localhost'; + it("should work with multiple absolute strings", (done) => { + const host = "localhost"; server = new Server( { - host: 'localhost', + host: "localhost", port, open: [ `http://${host}:${port}/first.html`, @@ -414,7 +414,7 @@ describe('"open" option', () => { compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenNthCalledWith( 1, @@ -439,17 +439,17 @@ describe('"open" option', () => { }); it('should work with "" pattern in multiple strings', (done) => { - const host = 'localhost'; + const host = "localhost"; server = new Server( { - host: 'localhost', + host: "localhost", port, - open: ['', 'second.html'], + open: ["", "second.html"], }, compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenNthCalledWith(1, `http://${host}:${port}/`, { wait: false, @@ -469,8 +469,8 @@ describe('"open" option', () => { server.listen(port, host); }); - it('should work with empty object', (done) => { - const host = 'localhost'; + it("should work with empty object", (done) => { + const host = "localhost"; server = new Server( { host, @@ -480,7 +480,7 @@ describe('"open" option', () => { compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${host}:${port}/`, { wait: false, @@ -494,19 +494,19 @@ describe('"open" option', () => { }); it("should work with object and with the 'target' option", (done) => { - const host = 'localhost'; + const host = "localhost"; server = new Server( { host, port, open: { - target: 'index.html', + target: "index.html", }, }, compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${host}:${port}/index.html`, { wait: false, @@ -520,19 +520,19 @@ describe('"open" option', () => { }); it("should work with object and with multiple values of the 'target' option", (done) => { - const host = 'localhost'; + const host = "localhost"; server = new Server( { host, port, open: { - target: ['first.html', 'second.html'], + target: ["first.html", "second.html"], }, }, compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenNthCalledWith( 1, @@ -557,22 +557,22 @@ describe('"open" option', () => { }); it("should work with object and with the 'app' option", (done) => { - const host = 'localhost'; + const host = "localhost"; server = new Server( { host, port, open: { - app: 'google-chrome', + app: "google-chrome", }, }, compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${host}:${port}/`, { - app: { name: 'google-chrome' }, + app: { name: "google-chrome" }, wait: false, }); @@ -584,22 +584,22 @@ describe('"open" option', () => { }); it("should work with object and with the 'app' and 'arguments' options", (done) => { - const host = 'localhost'; + const host = "localhost"; server = new Server( { host, port, open: { - app: { name: 'google-chrome', arguments: ['--incognito'] }, + app: { name: "google-chrome", arguments: ["--incognito"] }, }, }, compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${host}:${port}/`, { - app: { name: 'google-chrome', arguments: ['--incognito'] }, + app: { name: "google-chrome", arguments: ["--incognito"] }, wait: false, }); @@ -611,23 +611,23 @@ describe('"open" option', () => { }); it('should work with object with "target" and "app" options', (done) => { - const host = 'localhost'; + const host = "localhost"; server = new Server( { host, port, open: { - target: 'index.html', - app: 'google-chrome', + target: "index.html", + app: "google-chrome", }, }, compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${host}:${port}/index.html`, { - app: { name: 'google-chrome' }, + app: { name: "google-chrome" }, wait: false, }); @@ -639,23 +639,23 @@ describe('"open" option', () => { }); it('should work with pattern in "target" and "app" options', (done) => { - const host = 'localhost'; + const host = "localhost"; server = new Server( { host, port, open: { - target: '', - app: 'google-chrome', + target: "", + app: "google-chrome", }, }, compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${host}:${port}/`, { - app: { name: 'google-chrome' }, + app: { name: "google-chrome" }, wait: false, }); @@ -667,27 +667,27 @@ describe('"open" option', () => { }); it("should work with object, with multiple value of the 'target' option and with the 'app' and 'arguments' options", (done) => { - const host = 'localhost'; + const host = "localhost"; server = new Server( { host, port, open: { - target: ['first.html', 'second.html'], - app: { name: 'google-chrome', arguments: ['--incognito'] }, + target: ["first.html", "second.html"], + app: { name: "google-chrome", arguments: ["--incognito"] }, }, }, compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenNthCalledWith( 1, `http://${host}:${port}/first.html`, { wait: false, - app: { name: 'google-chrome', arguments: ['--incognito'] }, + app: { name: "google-chrome", arguments: ["--incognito"] }, } ); expect(open).toHaveBeenNthCalledWith( @@ -695,7 +695,7 @@ describe('"open" option', () => { `http://${host}:${port}/second.html`, { wait: false, - app: { name: 'google-chrome', arguments: ['--incognito'] }, + app: { name: "google-chrome", arguments: ["--incognito"] }, } ); @@ -707,27 +707,27 @@ describe('"open" option', () => { }); it("should work with object, with multiple value of the 'target' option (relative and absolute URLs) and with the 'app' option with arguments", (done) => { - const host = 'localhost'; + const host = "localhost"; server = new Server( { host, port, open: { - target: ['first.html', `http://${host}:${port}/second.html`], - app: { name: 'google-chrome', arguments: ['--incognito'] }, + target: ["first.html", `http://${host}:${port}/second.html`], + app: { name: "google-chrome", arguments: ["--incognito"] }, }, }, compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenNthCalledWith( 1, `http://${host}:${port}/first.html`, { wait: false, - app: { name: 'google-chrome', arguments: ['--incognito'] }, + app: { name: "google-chrome", arguments: ["--incognito"] }, } ); expect(open).toHaveBeenNthCalledWith( @@ -735,7 +735,7 @@ describe('"open" option', () => { `http://${host}:${port}/second.html`, { wait: false, - app: { name: 'google-chrome', arguments: ['--incognito'] }, + app: { name: "google-chrome", arguments: ["--incognito"] }, } ); @@ -746,35 +746,35 @@ describe('"open" option', () => { server.listen(port, host); }); - it('should work with pattern in multiple open options', (done) => { - const host = 'localhost'; + it("should work with pattern in multiple open options", (done) => { + const host = "localhost"; server = new Server( { host, port, open: [ { - target: '', - app: 'google-chrome', + target: "", + app: "google-chrome", }, { - target: '', - app: 'firefox', + target: "", + app: "firefox", }, ], }, compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${host}:${port}/`, { - app: { name: 'google-chrome' }, + app: { name: "google-chrome" }, wait: false, }); expect(open).toHaveBeenCalledWith(`http://${host}:${port}/`, { - app: { name: 'firefox' }, + app: { name: "firefox" }, wait: false, }); @@ -785,33 +785,33 @@ describe('"open" option', () => { server.listen(port, host); }); - it('should work with multiple open options without target', (done) => { - const host = 'localhost'; + it("should work with multiple open options without target", (done) => { + const host = "localhost"; server = new Server( { host, port, open: [ { - app: 'google-chrome', + app: "google-chrome", }, { - app: 'firefox', + app: "firefox", }, ], }, compiler ); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://${host}:${port}/`, { - app: { name: 'google-chrome' }, + app: { name: "google-chrome" }, wait: false, }); expect(open).toHaveBeenCalledWith(`http://${host}:${port}/`, { - app: { name: 'firefox' }, + app: { name: "firefox" }, wait: false, }); @@ -832,9 +832,9 @@ describe('"open" option', () => { }, compiler ); - const loggerWarnSpy = jest.spyOn(server.logger, 'warn'); + const loggerWarnSpy = jest.spyOn(server.logger, "warn"); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith(`http://localhost:${port}/`, { wait: false, @@ -856,14 +856,14 @@ describe('"open" option', () => { server = new Server( { - open: 'index.html', + open: "index.html", port, }, compiler ); - const loggerWarnSpy = jest.spyOn(server.logger, 'warn'); + const loggerWarnSpy = jest.spyOn(server.logger, "warn"); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith( `http://localhost:${port}/index.html`, @@ -889,21 +889,21 @@ describe('"open" option', () => { server = new Server( { open: { - target: 'index.html', - app: 'google-chrome', + target: "index.html", + app: "google-chrome", }, port, }, compiler ); - const loggerWarnSpy = jest.spyOn(server.logger, 'warn'); + const loggerWarnSpy = jest.spyOn(server.logger, "warn"); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith( `http://localhost:${port}/index.html`, { - app: { name: 'google-chrome' }, + app: { name: "google-chrome" }, wait: false, } ); @@ -925,26 +925,26 @@ describe('"open" option', () => { server = new Server( { open: { - target: 'index.html', + target: "index.html", app: { - name: 'google-chrome', - arguments: ['--incognito', '--new-window'], + name: "google-chrome", + arguments: ["--incognito", "--new-window"], }, }, port, }, compiler ); - const loggerWarnSpy = jest.spyOn(server.logger, 'warn'); + const loggerWarnSpy = jest.spyOn(server.logger, "warn"); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenCalledWith( `http://localhost:${port}/index.html`, { app: { - name: 'google-chrome', - arguments: ['--incognito', '--new-window'], + name: "google-chrome", + arguments: ["--incognito", "--new-window"], }, wait: false, } @@ -967,19 +967,19 @@ describe('"open" option', () => { server = new Server( { open: { - target: ['first.html', `http://localhost:${port}/second.html`], + target: ["first.html", `http://localhost:${port}/second.html`], app: { - name: 'google-chrome', - arguments: ['--incognito', '--new-window'], + name: "google-chrome", + arguments: ["--incognito", "--new-window"], }, }, port, }, compiler ); - const loggerWarnSpy = jest.spyOn(server.logger, 'warn'); + const loggerWarnSpy = jest.spyOn(server.logger, "warn"); - compiler.hooks.done.tap('webpack-dev-server', () => { + compiler.hooks.done.tap("webpack-dev-server", () => { server.close(() => { expect(open).toHaveBeenNthCalledWith( 1, @@ -987,8 +987,8 @@ describe('"open" option', () => { { wait: false, app: { - name: 'google-chrome', - arguments: ['--incognito', '--new-window'], + name: "google-chrome", + arguments: ["--incognito", "--new-window"], }, } ); @@ -998,8 +998,8 @@ describe('"open" option', () => { { wait: false, app: { - name: 'google-chrome', - arguments: ['--incognito', '--new-window'], + name: "google-chrome", + arguments: ["--incognito", "--new-window"], }, } ); diff --git a/test/server/port-option.test.js b/test/server/port-option.test.js index 8115178944..06bf4abfda 100644 --- a/test/server/port-option.test.js +++ b/test/server/port-option.test.js @@ -1,22 +1,22 @@ -'use strict'; +"use strict"; -const path = require('path'); -const webpack = require('webpack'); -const request = require('supertest'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/simple-config/webpack.config'); -const port = require('../ports-map')['port-option']; +const path = require("path"); +const webpack = require("webpack"); +const request = require("supertest"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/simple-config/webpack.config"); +const port = require("../ports-map")["port-option"]; const staticDirectory = path.resolve( __dirname, - '../fixtures/contentbase-config' + "../fixtures/contentbase-config" ); describe('"port" option', () => { let server = null; let req = null; - describe('is not be specified', () => { + describe("is not be specified", () => { beforeAll(async () => { const compiler = webpack(config); @@ -32,7 +32,7 @@ describe('"port" option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -54,22 +54,22 @@ describe('"port" option', () => { }); }); - it('server address', () => { + it("server address", () => { const address = server.server.address(); - expect(address.address).toBe('127.0.0.1'); + expect(address.address).toBe("127.0.0.1"); // Random port expect(address.port).toBeDefined(); }); - it('then Request to index', async () => { - const response = await req.get('/'); + it("then Request to index", async () => { + const response = await req.get("/"); expect(response.statusCode).toEqual(200); }); }); - describe('is undefined', () => { + describe("is undefined", () => { beforeAll(async () => { const compiler = webpack(config); @@ -86,7 +86,7 @@ describe('"port" option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -108,28 +108,28 @@ describe('"port" option', () => { }); }); - it('server address', () => { + it("server address", () => { const address = server.server.address(); - expect(address.address).toBe('127.0.0.1'); + expect(address.address).toBe("127.0.0.1"); // Random port expect(address.port).toBeDefined(); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.statusCode).toEqual(200); }); }); - describe('is auto', () => { + describe("is auto", () => { beforeAll(async () => { const compiler = webpack(config); server = new Server( { - port: 'auto', + port: "auto", static: { directory: staticDirectory, watch: false, @@ -139,7 +139,7 @@ describe('"port" option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -161,16 +161,16 @@ describe('"port" option', () => { }); }); - it('server address', () => { + it("server address", () => { const address = server.server.address(); - expect(address.address).toBe('127.0.0.1'); + expect(address.address).toBe("127.0.0.1"); // Random port expect(address.port).toBeDefined(); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.statusCode).toEqual(200); }); @@ -182,7 +182,7 @@ describe('"port" option', () => { server = new Server( { - port: '33333', + port: "33333", static: { directory: staticDirectory, watch: false, @@ -192,7 +192,7 @@ describe('"port" option', () => { ); await new Promise((resolve, reject) => { - server.listen('33333', '127.0.0.1', (error) => { + server.listen("33333", "127.0.0.1", (error) => { if (error) { reject(error); @@ -214,21 +214,21 @@ describe('"port" option', () => { }); }); - it('server address', () => { + it("server address", () => { const address = server.server.address(); - expect(address.address).toBe('127.0.0.1'); + expect(address.address).toBe("127.0.0.1"); expect(address.port).toBe(33333); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.statusCode).toEqual(200); }); }); - describe('is 33333', () => { + describe("is 33333", () => { beforeAll(async () => { const compiler = webpack(config); @@ -244,7 +244,7 @@ describe('"port" option', () => { ); await new Promise((resolve, reject) => { - server.listen(33333, '127.0.0.1', (error) => { + server.listen(33333, "127.0.0.1", (error) => { if (error) { reject(error); @@ -266,15 +266,15 @@ describe('"port" option', () => { }); }); - it('server address', () => { + it("server address", () => { const address = server.server.address(); - expect(address.address).toBe('127.0.0.1'); + expect(address.address).toBe("127.0.0.1"); expect(address.port).toBe(33333); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.statusCode).toEqual(200); }); diff --git a/test/server/proxy-option.test.js b/test/server/proxy-option.test.js index 38f6eb4f10..0ac1ce158e 100644 --- a/test/server/proxy-option.test.js +++ b/test/server/proxy-option.test.js @@ -1,48 +1,48 @@ -'use strict'; - -const path = require('path'); -const request = require('supertest'); -const express = require('express'); -const bodyParser = require('body-parser'); -const WebSocket = require('ws'); -const webpack = require('webpack'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/proxy-config/webpack.config'); -const [port1, port2, port3, port4] = require('../ports-map')['proxy-option']; +"use strict"; + +const path = require("path"); +const request = require("supertest"); +const express = require("express"); +const bodyParser = require("body-parser"); +const WebSocket = require("ws"); +const webpack = require("webpack"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/proxy-config/webpack.config"); +const [port1, port2, port3, port4] = require("../ports-map")["proxy-option"]; const WebSocketServer = WebSocket.Server; -const staticDirectory = path.resolve(__dirname, '../fixtures/proxy-config'); +const staticDirectory = path.resolve(__dirname, "../fixtures/proxy-config"); const proxyOptionPathsAsProperties = { - '/proxy1': { + "/proxy1": { target: `http://localhost:${port1}`, }, - '/api/proxy2': { + "/api/proxy2": { target: `http://localhost:${port2}`, - pathRewrite: { '^/api': '' }, + pathRewrite: { "^/api": "" }, }, - '/foo': { + "/foo": { bypass(req) { if (/\.html$/.test(req.path)) { - return '/index.html'; + return "/index.html"; } return null; }, }, - '/proxyfalse': { + "/proxyfalse": { bypass(req) { if (/\/proxyfalse$/.test(req.path)) { return false; } }, }, - '/proxy/async': { + "/proxy/async": { bypass(req, res) { if (/\/proxy\/async$/.test(req.path)) { return new Promise((resolve) => { setTimeout(() => { - res.end('proxy async response'); + res.end("proxy async response"); resolve(true); }, 10); }); @@ -57,12 +57,12 @@ const proxyOption = { }; const proxyOptionOfArray = [ - { context: '/proxy1', target: proxyOption.target }, + { context: "/proxy1", target: proxyOption.target }, function proxy(req, res, next) { return { - context: '/api/proxy2', + context: "/api/proxy2", target: `http://localhost:${port2}`, - pathRewrite: { '^/api': '' }, + pathRewrite: { "^/api": "" }, bypass: () => { if (req && req.query.foo) { res.end(`foo+${next.name}+${typeof next}`); @@ -73,7 +73,7 @@ const proxyOptionOfArray = [ }, ]; -describe('proxy option', () => { +describe("proxy option", () => { let proxyServer1; let proxyServer2; @@ -81,14 +81,14 @@ describe('proxy option', () => { const proxyApp1 = express(); const proxyApp2 = express(); - proxyApp1.get('/proxy1', (req, res) => { - res.send('from proxy1'); + proxyApp1.get("/proxy1", (req, res) => { + res.send("from proxy1"); }); - proxyApp1.get('/api', (req, res) => { - res.send('api response from proxy1'); + proxyApp1.get("/api", (req, res) => { + res.send("api response from proxy1"); }); - proxyApp2.get('/proxy2', (req, res) => { - res.send('from proxy2'); + proxyApp2.get("/proxy2", (req, res) => { + res.send("from proxy2"); }); await new Promise((resolve) => { @@ -118,7 +118,7 @@ describe('proxy option', () => { }); } - describe('as an object of paths with properties', () => { + describe("as an object of paths with properties", () => { let server; let req; @@ -138,7 +138,7 @@ describe('proxy option', () => { ); await new Promise((resolve, reject) => { - server.listen(port3, '127.0.0.1', (error) => { + server.listen(port3, "127.0.0.1", (error) => { if (error) { reject(error); @@ -164,62 +164,62 @@ describe('proxy option', () => { await closeProxyServers(); }); - describe('target', () => { - it('respects a proxy option when a request path is matched', async () => { - const response = await req.get('/proxy1'); + describe("target", () => { + it("respects a proxy option when a request path is matched", async () => { + const response = await req.get("/proxy1"); expect(response.status).toEqual(200); - expect(response.text).toContain('from proxy1'); + expect(response.text).toContain("from proxy1"); }); }); - describe('pathRewrite', () => { - it('respects a pathRewrite option', async () => { - const response = await req.get('/api/proxy2'); + describe("pathRewrite", () => { + it("respects a pathRewrite option", async () => { + const response = await req.get("/api/proxy2"); expect(response.status).toEqual(200); - expect(response.text).toContain('from proxy2'); + expect(response.text).toContain("from proxy2"); }); }); - describe('bypass', () => { - it('can rewrite a request path', async () => { - const response = await req.get('/foo/bar.html'); + describe("bypass", () => { + it("can rewrite a request path", async () => { + const response = await req.get("/foo/bar.html"); expect(response.status).toEqual(200); - expect(response.text).toContain('Hello'); + expect(response.text).toContain("Hello"); }); - it('can rewrite a request path regardless of the target defined a bypass option', async () => { - const response = await req.get('/baz/hoge.html'); + it("can rewrite a request path regardless of the target defined a bypass option", async () => { + const response = await req.get("/baz/hoge.html"); expect(response.status).toEqual(200); - expect(response.text).toContain('Hello'); + expect(response.text).toContain("Hello"); }); - it('should pass through a proxy when a bypass function returns null', async () => { - const response = await req.get('/foo.js'); + it("should pass through a proxy when a bypass function returns null", async () => { + const response = await req.get("/foo.js"); expect(response.status).toEqual(200); - expect(response.text).toContain('Hey'); + expect(response.text).toContain("Hey"); }); - it('should not pass through a proxy when a bypass function returns false', async () => { - const response = await req.get('/proxyfalse'); + it("should not pass through a proxy when a bypass function returns false", async () => { + const response = await req.get("/proxyfalse"); expect(response.status).toEqual(404); }); - it('should wait if bypass returns promise', async () => { - const response = await req.get('/proxy/async'); + it("should wait if bypass returns promise", async () => { + const response = await req.get("/proxy/async"); expect(response.status).toEqual(200); - expect(response.text).toContain('proxy async response'); + expect(response.text).toContain("proxy async response"); }); }); }); - describe('as an option is an object', () => { + describe("as an option is an object", () => { let server; let req; @@ -239,7 +239,7 @@ describe('proxy option', () => { ); await new Promise((resolve, reject) => { - server.listen(port3, '127.0.0.1', (error) => { + server.listen(port3, "127.0.0.1", (error) => { if (error) { reject(error); @@ -265,15 +265,15 @@ describe('proxy option', () => { await closeProxyServers(); }); - it('respects a proxy option', async () => { - const response = await req.get('/proxy1'); + it("respects a proxy option", async () => { + const response = await req.get("/proxy1"); expect(response.status).toEqual(200); - expect(response.text).toContain('from proxy1'); + expect(response.text).toContain("from proxy1"); }); }); - describe('as an array', () => { + describe("as an array", () => { let server; let req; @@ -293,7 +293,7 @@ describe('proxy option', () => { ); await new Promise((resolve, reject) => { - server.listen(port3, '127.0.0.1', (error) => { + server.listen(port3, "127.0.0.1", (error) => { if (error) { reject(error); @@ -319,29 +319,29 @@ describe('proxy option', () => { await closeProxyServers(); }); - it('respects a proxy option', async () => { - const response = await req.get('/proxy1'); + it("respects a proxy option", async () => { + const response = await req.get("/proxy1"); expect(response.status).toEqual(200); - expect(response.text).toContain('from proxy1'); + expect(response.text).toContain("from proxy1"); }); - it('respects a proxy option of function', async () => { - const response = await req.get('/api/proxy2'); + it("respects a proxy option of function", async () => { + const response = await req.get("/api/proxy2"); expect(response.status).toEqual(200); - expect(response.text).toContain('from proxy2'); + expect(response.text).toContain("from proxy2"); }); - it('should allow req, res, and next', async () => { - const response = await req.get('/api/proxy2?foo=true'); + it("should allow req, res, and next", async () => { + const response = await req.get("/api/proxy2?foo=true"); expect(response.statusCode).toEqual(200); - expect(response.text).toEqual('foo+next+function'); + expect(response.text).toEqual("foo+next+function"); }); }); - describe('should sharing a proxy option', () => { + describe("should sharing a proxy option", () => { let server; let req; let listener; @@ -360,8 +360,8 @@ describe('proxy option', () => { watch: false, }, proxy: { - '/proxy1': proxyTarget, - '/proxy2': proxyTarget, + "/proxy1": proxyTarget, + "/proxy2": proxyTarget, }, port: port3, }, @@ -369,7 +369,7 @@ describe('proxy option', () => { ); await new Promise((resolve, reject) => { - server.listen(port3, '127.0.0.1', (error) => { + server.listen(port3, "127.0.0.1", (error) => { if (error) { reject(error); @@ -382,8 +382,8 @@ describe('proxy option', () => { const proxy = express(); - proxy.get('*', (proxyReq, res) => { - res.send('from proxy'); + proxy.get("*", (proxyReq, res) => { + res.send("from proxy"); }); listener = proxy.listen(port1); @@ -405,28 +405,28 @@ describe('proxy option', () => { }); }); - it('respects proxy1 option', async () => { - const response = await req.get('/proxy1'); + it("respects proxy1 option", async () => { + const response = await req.get("/proxy1"); expect(response.status).toEqual(200); - expect(response.text).toContain('from proxy'); + expect(response.text).toContain("from proxy"); }); - it('respects proxy2 option', async () => { - const response = await req.get('/proxy2'); + it("respects proxy2 option", async () => { + const response = await req.get("/proxy2"); expect(response.status).toEqual(200); - expect(response.text).toContain('from proxy'); + expect(response.text).toContain("from proxy"); }); }); - describe('should handles external websocket upgrade', () => { + describe("should handles external websocket upgrade", () => { let ws; let server; let webSocketServer; let responseMessage; - const webSocketServerTypes = ['sockjs', 'ws']; + const webSocketServerTypes = ["sockjs", "ws"]; webSocketServerTypes.forEach((webSocketServerType) => { describe(`with webSocketServerType: ${webSocketServerType}`, () => { @@ -442,7 +442,7 @@ describe('proxy option', () => { webSocketServer: webSocketServerType, proxy: [ { - context: '/', + context: "/", target: `http://localhost:${port4}`, ws: true, }, @@ -453,7 +453,7 @@ describe('proxy option', () => { ); await new Promise((resolve, reject) => { - server.listen(port3, '127.0.0.1', (error) => { + server.listen(port3, "127.0.0.1", (error) => { if (error) { reject(error); @@ -465,8 +465,8 @@ describe('proxy option', () => { }); webSocketServer = new WebSocketServer({ port: port4 }); - webSocketServer.on('connection', (connection) => { - connection.on('message', (message) => { + webSocketServer.on("connection", (connection) => { + connection.on("message", (message) => { connection.send(message); }); }); @@ -475,18 +475,18 @@ describe('proxy option', () => { beforeEach((done) => { ws = new WebSocket(`ws://localhost:${port3}/proxy3/socket`); - ws.on('message', (message) => { + ws.on("message", (message) => { responseMessage = message; done(); }); - ws.on('open', () => { - ws.send('foo'); + ws.on("open", () => { + ws.send("foo"); }); }); - it('Should receive response', () => { - expect(responseMessage).toEqual('foo'); + it("Should receive response", () => { + expect(responseMessage).toEqual("foo"); }); afterAll(async () => { @@ -502,7 +502,7 @@ describe('proxy option', () => { }); }); - describe('should supports http methods', () => { + describe("should supports http methods", () => { let server; let req; let listener; @@ -520,7 +520,7 @@ describe('proxy option', () => { watch: false, }, proxy: { - '**': proxyTarget, + "**": proxyTarget, }, port: port3, }, @@ -528,7 +528,7 @@ describe('proxy option', () => { ); await new Promise((resolve, reject) => { - server.listen(port3, '127.0.0.1', (error) => { + server.listen(port3, "127.0.0.1", (error) => { if (error) { reject(error); @@ -549,7 +549,7 @@ describe('proxy option', () => { // This forces Express to try to decode URLs, which is needed for the test // associated with the middleware below. - proxy.all('*', (_req, res, next) => { + proxy.all("*", (_req, res, next) => { next(); }); // We must define all 4 params in order for this to be detected as an @@ -557,31 +557,31 @@ describe('proxy option', () => { // eslint-disable-next-line no-unused-vars proxy.use((error, proxyReq, res, next) => { res.status(500); - res.send('error from proxy'); + res.send("error from proxy"); }); - proxy.get('/get', (proxyReq, res) => { - res.send('GET method from proxy'); + proxy.get("/get", (proxyReq, res) => { + res.send("GET method from proxy"); }); - proxy.head('/head', (proxyReq, res) => { - res.send('HEAD method from proxy'); + proxy.head("/head", (proxyReq, res) => { + res.send("HEAD method from proxy"); }); - proxy.post('/post-x-www-form-urlencoded', (proxyReq, res) => { + proxy.post("/post-x-www-form-urlencoded", (proxyReq, res) => { const id = proxyReq.body.id; res.status(200).send(`POST method from proxy (id: ${id})`); }); - proxy.post('/post-application-json', (proxyReq, res) => { + proxy.post("/post-application-json", (proxyReq, res) => { const id = proxyReq.body.id; res.status(200).send({ answer: `POST method from proxy (id: ${id})` }); }); - proxy.delete('/delete', (proxyReq, res) => { - res.send('DELETE method from proxy'); + proxy.delete("/delete", (proxyReq, res) => { + res.send("DELETE method from proxy"); }); listener = proxy.listen(port1); @@ -602,57 +602,57 @@ describe('proxy option', () => { }); }); - it('errors', async () => { - const response = await req.get('/%'); + it("errors", async () => { + const response = await req.get("/%"); expect(response.status).toEqual(500); - expect(response.text).toContain('error from proxy'); + expect(response.text).toContain("error from proxy"); }); - it('GET method', async () => { - const response = await req.get('/get'); + it("GET method", async () => { + const response = await req.get("/get"); expect(response.status).toEqual(200); - expect(response.text).toContain('GET method from proxy'); + expect(response.text).toContain("GET method from proxy"); }); - it('HEAD method', async () => { - const response = await req.head('/head'); + it("HEAD method", async () => { + const response = await req.head("/head"); expect(response.status).toEqual(200); }); - it('POST method (application/x-www-form-urlencoded)', async () => { + it("POST method (application/x-www-form-urlencoded)", async () => { const response = await req - .post('/post-x-www-form-urlencoded') - .send('id=1'); + .post("/post-x-www-form-urlencoded") + .send("id=1"); expect(response.status).toEqual(200); - expect(response.text).toContain('POST method from proxy (id: 1)'); + expect(response.text).toContain("POST method from proxy (id: 1)"); }); - it('POST method (application/json)', async () => { + it("POST method (application/json)", async () => { const response = await req - .post('/post-application-json') - .send({ id: '1' }) - .set('Accept', 'application/json'); + .post("/post-application-json") + .send({ id: "1" }) + .set("Accept", "application/json"); expect(response.status).toEqual(200); - expect(response.headers['content-type']).toEqual( - 'application/json; charset=utf-8' + expect(response.headers["content-type"]).toEqual( + "application/json; charset=utf-8" ); - expect(response.text).toContain('POST method from proxy (id: 1)'); + expect(response.text).toContain("POST method from proxy (id: 1)"); }); - it('DELETE method', async () => { - const response = await req.delete('/delete'); + it("DELETE method", async () => { + const response = await req.delete("/delete"); expect(response.status).toEqual(200); - expect(response.text).toContain('DELETE method from proxy'); + expect(response.text).toContain("DELETE method from proxy"); }); }); - describe('should work in multi compiler mode', () => { + describe("should work in multi compiler mode", () => { let server; let req; @@ -666,7 +666,7 @@ describe('proxy option', () => { watch: false, }, proxy: { - '*': { + "*": { context: () => true, target: `http://localhost:${port1}`, }, @@ -677,7 +677,7 @@ describe('proxy option', () => { ); await new Promise((resolve, reject) => { - server.listen(port3, '127.0.0.1', (error) => { + server.listen(port3, "127.0.0.1", (error) => { if (error) { reject(error); @@ -703,15 +703,15 @@ describe('proxy option', () => { await closeProxyServers(); }); - it('respects a proxy option', async () => { - const response = await req.get('/proxy1'); + it("respects a proxy option", async () => { + const response = await req.get("/proxy1"); expect(response.status).toEqual(200); - expect(response.text).toContain('from proxy1'); + expect(response.text).toContain("from proxy1"); }); }); - describe('should work and respect `logProvider` and `logLevel` options', () => { + describe("should work and respect `logProvider` and `logLevel` options", () => { let server; let req; let customLogProvider; @@ -734,10 +734,10 @@ describe('proxy option', () => { watch: false, }, proxy: { - '/my-path': { - target: 'http://unknown:1234', + "/my-path": { + target: "http://unknown:1234", logProvider: () => customLogProvider, - logLevel: 'error', + logLevel: "error", }, }, port: port3, @@ -746,7 +746,7 @@ describe('proxy option', () => { ); await new Promise((resolve, reject) => { - server.listen(port3, '127.0.0.1', (error) => { + server.listen(port3, "127.0.0.1", (error) => { if (error) { reject(error); @@ -772,16 +772,16 @@ describe('proxy option', () => { await closeProxyServers(); }); - describe('target', () => { - it('respects a proxy option when a request path is matched', async () => { - await req.get('/my-path'); + describe("target", () => { + it("respects a proxy option when a request path is matched", async () => { + await req.get("/my-path"); expect(customLogProvider.error).toHaveBeenCalledTimes(1); }); }); }); - describe('should work and respect the `logLevel` option with `silent` value', () => { + describe("should work and respect the `logLevel` option with `silent` value", () => { let server; let req; let customLogProvider; @@ -804,10 +804,10 @@ describe('proxy option', () => { watch: false, }, proxy: { - '/my-path': { - target: 'http://unknown:1234', + "/my-path": { + target: "http://unknown:1234", logProvider: () => customLogProvider, - logLevel: 'silent', + logLevel: "silent", }, }, port: port3, @@ -816,7 +816,7 @@ describe('proxy option', () => { ); await new Promise((resolve, reject) => { - server.listen(port3, '127.0.0.1', (error) => { + server.listen(port3, "127.0.0.1", (error) => { if (error) { reject(error); @@ -842,16 +842,16 @@ describe('proxy option', () => { await closeProxyServers(); }); - describe('target', () => { - it('respects a proxy option when a request path is matched', async () => { - await req.get('/my-path'); + describe("target", () => { + it("respects a proxy option when a request path is matched", async () => { + await req.get("/my-path"); expect(customLogProvider.error).toHaveBeenCalledTimes(0); }); }); }); - describe('should work and respect the `infrastructureLogging.level` option', () => { + describe("should work and respect the `infrastructureLogging.level` option", () => { let server; let req; let customLogProvider; @@ -867,7 +867,7 @@ describe('proxy option', () => { const compiler = webpack({ ...config, - infrastructureLogging: { level: 'error' }, + infrastructureLogging: { level: "error" }, }); server = new Server( @@ -877,8 +877,8 @@ describe('proxy option', () => { watch: false, }, proxy: { - '/my-path': { - target: 'http://unknown:1234', + "/my-path": { + target: "http://unknown:1234", logProvider: () => customLogProvider, }, }, @@ -888,7 +888,7 @@ describe('proxy option', () => { ); await new Promise((resolve, reject) => { - server.listen(port3, '127.0.0.1', (error) => { + server.listen(port3, "127.0.0.1", (error) => { if (error) { reject(error); @@ -914,16 +914,16 @@ describe('proxy option', () => { await closeProxyServers(); }); - describe('target', () => { - it('respects a proxy option when a request path is matched', async () => { - await req.get('/my-path'); + describe("target", () => { + it("respects a proxy option when a request path is matched", async () => { + await req.get("/my-path"); expect(customLogProvider.error).toHaveBeenCalledTimes(1); }); }); }); - describe('should work and respect the `infrastructureLogging.level` option with `none` value', () => { + describe("should work and respect the `infrastructureLogging.level` option with `none` value", () => { let server; let req; let customLogProvider; @@ -939,7 +939,7 @@ describe('proxy option', () => { const compiler = webpack({ ...config, - infrastructureLogging: { level: 'none' }, + infrastructureLogging: { level: "none" }, }); server = new Server( @@ -949,8 +949,8 @@ describe('proxy option', () => { watch: false, }, proxy: { - '/my-path': { - target: 'http://unknown:1234', + "/my-path": { + target: "http://unknown:1234", logProvider: () => customLogProvider, }, }, @@ -960,7 +960,7 @@ describe('proxy option', () => { ); await new Promise((resolve, reject) => { - server.listen(port3, '127.0.0.1', (error) => { + server.listen(port3, "127.0.0.1", (error) => { if (error) { reject(error); @@ -982,9 +982,9 @@ describe('proxy option', () => { }); }); - describe('target', () => { - it('respects a proxy option when a request path is matched', async () => { - await req.get('/my-path'); + describe("target", () => { + it("respects a proxy option when a request path is matched", async () => { + await req.get("/my-path"); expect(customLogProvider.error).toHaveBeenCalledTimes(0); }); diff --git a/test/server/setupExitSignals-option.test.js b/test/server/setupExitSignals-option.test.js index a8334dcf6a..6dbc3f72fe 100644 --- a/test/server/setupExitSignals-option.test.js +++ b/test/server/setupExitSignals-option.test.js @@ -1,16 +1,16 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/simple-config/webpack.config'); -const port = require('../ports-map')['setup-exit-signals-option']; +const webpack = require("webpack"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/simple-config/webpack.config"); +const port = require("../ports-map")["setup-exit-signals-option"]; -describe('setupExitSignals option', () => { +describe("setupExitSignals option", () => { let server; let exitSpy; let killSpy; let stdinResumeSpy; - const signals = ['SIGINT', 'SIGTERM']; + const signals = ["SIGINT", "SIGTERM"]; beforeEach(async () => { const compiler = webpack(config); @@ -24,7 +24,7 @@ describe('setupExitSignals option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -35,11 +35,11 @@ describe('setupExitSignals option', () => { }); }); - exitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {}); + exitSpy = jest.spyOn(process, "exit").mockImplementation(() => {}); stdinResumeSpy = jest - .spyOn(process.stdin, 'resume') + .spyOn(process.stdin, "resume") .mockImplementation(() => {}); - killSpy = jest.spyOn(server.server, 'kill'); + killSpy = jest.spyOn(server.server, "kill"); }); afterEach(async () => { @@ -48,7 +48,7 @@ describe('setupExitSignals option', () => { signals.forEach((signal) => { process.removeAllListeners(signal); }); - process.stdin.removeAllListeners('end'); + process.stdin.removeAllListeners("end"); await new Promise((resolve) => { server.close(() => { @@ -57,7 +57,7 @@ describe('setupExitSignals option', () => { }); }); - it.each(signals)('should close and exit on %s', (signal, done) => { + it.each(signals)("should close and exit on %s", (signal, done) => { process.emit(signal); process.nextTick(() => { expect(killSpy.mock.calls.length).toEqual(1); diff --git a/test/server/static-directory-option.test.js b/test/server/static-directory-option.test.js index c377fccb20..4cbd8a91ce 100644 --- a/test/server/static-directory-option.test.js +++ b/test/server/static-directory-option.test.js @@ -1,27 +1,27 @@ -'use strict'; +"use strict"; -const path = require('path'); -const fs = require('graceful-fs'); -const webpack = require('webpack'); -const request = require('supertest'); -const Server = require('../../lib/Server'); -const testServer = require('../helpers/test-server'); -const config = require('../fixtures/contentbase-config/webpack.config'); -const port = require('../ports-map')['static-directory-option']; +const path = require("path"); +const fs = require("graceful-fs"); +const webpack = require("webpack"); +const request = require("supertest"); +const Server = require("../../lib/Server"); +const testServer = require("../helpers/test-server"); +const config = require("../fixtures/contentbase-config/webpack.config"); +const port = require("../ports-map")["static-directory-option"]; const staticDirectory = path.resolve( __dirname, - '../fixtures/contentbase-config' + "../fixtures/contentbase-config" ); -const publicDirectory = path.resolve(staticDirectory, 'public'); -const otherPublicDirectory = path.resolve(staticDirectory, 'other'); +const publicDirectory = path.resolve(staticDirectory, "public"); +const otherPublicDirectory = path.resolve(staticDirectory, "other"); -describe('static.directory option', () => { +describe("static.directory option", () => { let server; let req; - describe('to directory', () => { - const nestedFile = path.resolve(publicDirectory, 'assets/example.txt'); + describe("to directory", () => { + const nestedFile = path.resolve(publicDirectory, "assets/example.txt"); beforeAll(async () => { const compiler = webpack(config); @@ -38,7 +38,7 @@ describe('static.directory option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -62,41 +62,41 @@ describe('static.directory option', () => { fs.truncateSync(nestedFile); }); - it('Request to index', async () => { - const response = await req.get('/'); + it("Request to index", async () => { + const response = await req.get("/"); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); - it('Request to other file', async () => { - const response = await req.get('/other.html'); + it("Request to other file", async () => { + const response = await req.get("/other.html"); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Other html'); + expect(response.text).toContain("Other html"); }); - it('Watches folder recursively', (done) => { + it("Watches folder recursively", (done) => { // chokidar emitted a change, // meaning it watched the file correctly - server.staticWatchers[0].on('change', () => { + server.staticWatchers[0].on("change", () => { done(); }); // change a file manually setTimeout(() => { - fs.writeFileSync(nestedFile, 'Heyo', 'utf8'); + fs.writeFileSync(nestedFile, "Heyo", "utf8"); }, 1000); }); - it('watch node_modules', (done) => { - const filePath = path.join(publicDirectory, 'node_modules', 'index.html'); + it("watch node_modules", (done) => { + const filePath = path.join(publicDirectory, "node_modules", "index.html"); - fs.writeFileSync(filePath, 'foo', 'utf8'); + fs.writeFileSync(filePath, "foo", "utf8"); // chokidar emitted a change, // meaning it watched the file correctly - server.staticWatchers[0].on('change', () => { + server.staticWatchers[0].on("change", () => { fs.unlinkSync(filePath); done(); @@ -104,12 +104,12 @@ describe('static.directory option', () => { // change a file manually setTimeout(() => { - fs.writeFileSync(filePath, 'bar', 'utf8'); + fs.writeFileSync(filePath, "bar", "utf8"); }, 1000); }); }); - describe('test listing files in folders without index.html using the option static.serveIndex:false', () => { + describe("test listing files in folders without index.html using the option static.serveIndex:false", () => { beforeAll(async () => { const compiler = webpack(config); @@ -126,7 +126,7 @@ describe('static.directory option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -149,20 +149,20 @@ describe('static.directory option', () => { }); it("shouldn't list the files inside the assets folder (404)", async () => { - const response = await req.get('/assets/'); + const response = await req.get("/assets/"); expect(response.statusCode).toEqual(404); }); - it('should show Heyo. because bar has index.html inside it (200)', async () => { - const response = await req.get('/bar/'); + it("should show Heyo. because bar has index.html inside it (200)", async () => { + const response = await req.get("/bar/"); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); }); - describe('test listing files in folders without index.html using the option static.serveIndex:true', () => { + describe("test listing files in folders without index.html using the option static.serveIndex:true", () => { beforeAll(async () => { const compiler = webpack(config); @@ -179,7 +179,7 @@ describe('static.directory option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -201,21 +201,21 @@ describe('static.directory option', () => { }); }); - it('should list the files inside the assets folder (200)', async () => { - const response = await req.get('/assets/'); + it("should list the files inside the assets folder (200)", async () => { + const response = await req.get("/assets/"); expect(response.statusCode).toEqual(200); }); - it('should show Heyo. because bar has index.html inside it (200)', async () => { - const response = await req.get('/bar/'); + it("should show Heyo. because bar has index.html inside it (200)", async () => { + const response = await req.get("/bar/"); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); }); - describe('test listing files in folders without index.html using the option static.serveIndex default (true)', () => { + describe("test listing files in folders without index.html using the option static.serveIndex default (true)", () => { beforeAll(async () => { const compiler = webpack(config); @@ -231,7 +231,7 @@ describe('static.directory option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -253,21 +253,21 @@ describe('static.directory option', () => { }); }); - it('should list the files inside the assets folder (200)', async () => { - const response = await req.get('/assets/'); + it("should list the files inside the assets folder (200)", async () => { + const response = await req.get("/assets/"); expect(response.statusCode).toEqual(200); }); - it('should show Heyo. because bar has index.html inside it (200)', async () => { - const response = await req.get('/bar/'); + it("should show Heyo. because bar has index.html inside it (200)", async () => { + const response = await req.get("/bar/"); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); }); - describe('to directories', () => { + describe("to directories", () => { beforeAll(async () => { const compiler = webpack(config); @@ -280,7 +280,7 @@ describe('static.directory option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -302,45 +302,45 @@ describe('static.directory option', () => { }); }); - it('Request to first directory', async () => { - const response = await req.get('/'); + it("Request to first directory", async () => { + const response = await req.get("/"); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); - it('Request to second directory', async () => { - const response = await req.get('/foo.html'); + it("Request to second directory", async () => { + const response = await req.get("/foo.html"); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Foo!'); + expect(response.text).toContain("Foo!"); }); }); - describe('testing single & multiple external paths', () => { + describe("testing single & multiple external paths", () => { afterEach((done) => { testServer.close(() => { done(); }); }); - it('Should throw exception (external url)', (done) => { + it("Should throw exception (external url)", (done) => { try { // eslint-disable-next-line no-unused-vars server = testServer.start(config, { - static: 'https://example.com/', + static: "https://example.com/", }); expect(true).toBe(false); } catch (e) { expect(e.message).toBe( - 'Using a URL as static.directory is not supported' + "Using a URL as static.directory is not supported" ); done(); } }); - it('Should not throw exception (local path with lower case first character)', (done) => { + it("Should not throw exception (local path with lower case first character)", (done) => { testServer.start( config, { @@ -361,7 +361,7 @@ describe('static.directory option', () => { config, { static: { - directory: 'c:\\absolute\\path\\to\\content-base', + directory: "c:\\absolute\\path\\to\\content-base", watch: true, }, port, @@ -375,7 +375,7 @@ describe('static.directory option', () => { config, { static: { - directory: 'C:\\absolute\\path\\to\\content-base', + directory: "C:\\absolute\\path\\to\\content-base", watch: true, }, port, @@ -384,27 +384,27 @@ describe('static.directory option', () => { ); }); - it('Should throw exception (array with absolute url)', (done) => { + it("Should throw exception (array with absolute url)", (done) => { try { // eslint-disable-next-line no-unused-vars server = testServer.start(config, { - static: [publicDirectory, 'https://example.com/'], + static: [publicDirectory, "https://example.com/"], }); expect(true).toBe(false); } catch (e) { expect(e.message).toBe( - 'Using a URL as static.directory is not supported' + "Using a URL as static.directory is not supported" ); done(); } }); }); - describe('default to PWD', () => { + describe("default to PWD", () => { beforeAll(async () => { jest - .spyOn(process, 'cwd') + .spyOn(process, "cwd") .mockImplementation(() => path.resolve(staticDirectory)); const compiler = webpack(config); @@ -419,7 +419,7 @@ describe('static.directory option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -441,18 +441,18 @@ describe('static.directory option', () => { }); }); - it('Request to page', async () => { - const response = await req.get('/index.html'); + it("Request to page", async () => { + const response = await req.get("/index.html"); expect(response.statusCode).toEqual(200); }); }); - describe('disable', () => { + describe("disable", () => { beforeAll(async () => { // This is a somewhat weird test, but it is important that we mock // the PWD here, and test if /other.html in our "fake" PWD really is not requested. - jest.spyOn(process, 'cwd').mockImplementation(() => publicDirectory); + jest.spyOn(process, "cwd").mockImplementation(() => publicDirectory); const compiler = webpack(config); @@ -465,7 +465,7 @@ describe('static.directory option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -487,8 +487,8 @@ describe('static.directory option', () => { }); }); - it('Request to page', async () => { - const response = await req.get('/other.html'); + it("Request to page", async () => { + const response = await req.get("/other.html"); expect(response.statusCode).toBe(404); }); diff --git a/test/server/static-publicPath-option.test.js b/test/server/static-publicPath-option.test.js index 7bd47463d8..bbf5a5bb79 100644 --- a/test/server/static-publicPath-option.test.js +++ b/test/server/static-publicPath-option.test.js @@ -1,26 +1,26 @@ -'use strict'; +"use strict"; -const path = require('path'); -const request = require('supertest'); -const webpack = require('webpack'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/contentbase-config/webpack.config'); -const port = require('../ports-map')['static-public-path-option']; +const path = require("path"); +const request = require("supertest"); +const webpack = require("webpack"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/contentbase-config/webpack.config"); +const port = require("../ports-map")["static-public-path-option"]; const staticDirectory = path.resolve( __dirname, - '../fixtures/contentbase-config' + "../fixtures/contentbase-config" ); -const publicDirectory = path.resolve(staticDirectory, 'public'); -const otherPublicDirectory = path.resolve(staticDirectory, 'other'); -const staticPublicPath = '/serve-content-base-at-this-url'; -const otherStaticPublicPath = '/serve-other-content-at-this-url'; +const publicDirectory = path.resolve(staticDirectory, "public"); +const otherPublicDirectory = path.resolve(staticDirectory, "other"); +const staticPublicPath = "/serve-content-base-at-this-url"; +const otherStaticPublicPath = "/serve-other-content-at-this-url"; -describe('static.publicPath option', () => { +describe("static.publicPath option", () => { let server; let req; - describe('to directory', () => { + describe("to directory", () => { beforeAll(async () => { const compiler = webpack(config); @@ -37,7 +37,7 @@ describe('static.publicPath option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -59,22 +59,22 @@ describe('static.publicPath option', () => { }); }); - it('Request to index', async () => { + it("Request to index", async () => { const response = await req.get(`${staticPublicPath}/`); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); - it('Request to other file', async () => { + it("Request to other file", async () => { const response = await req.get(`${staticPublicPath}/other.html`); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Other html'); + expect(response.text).toContain("Other html"); }); }); - describe('test listing files in folders without index.html using the option static.serveIndex:false', () => { + describe("test listing files in folders without index.html using the option static.serveIndex:false", () => { beforeAll(async () => { const compiler = webpack(config); @@ -92,7 +92,7 @@ describe('static.publicPath option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -120,15 +120,15 @@ describe('static.publicPath option', () => { expect(response.statusCode).toEqual(404); }); - it('should show Heyo. because bar has index.html inside it (200)', async () => { + it("should show Heyo. because bar has index.html inside it (200)", async () => { const response = await req.get(`${staticPublicPath}/bar/`); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); }); - describe('test listing files in folders without index.html using the option static.serveIndex:true', () => { + describe("test listing files in folders without index.html using the option static.serveIndex:true", () => { beforeAll(async () => { const compiler = webpack(config); @@ -146,7 +146,7 @@ describe('static.publicPath option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -168,21 +168,21 @@ describe('static.publicPath option', () => { }); }); - it('should list the files inside the assets folder (200)', async () => { + it("should list the files inside the assets folder (200)", async () => { const response = await req.get(`${staticPublicPath}/assets/`); expect(response.statusCode).toEqual(200); }); - it('should show Heyo. because bar has index.html inside it (200)', async () => { + it("should show Heyo. because bar has index.html inside it (200)", async () => { const response = await req.get(`${staticPublicPath}/bar/`); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); }); - describe('test listing files in folders without index.html using the option static.serveIndex default (true)', () => { + describe("test listing files in folders without index.html using the option static.serveIndex default (true)", () => { beforeAll(async () => { const compiler = webpack(config); @@ -199,7 +199,7 @@ describe('static.publicPath option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -221,21 +221,21 @@ describe('static.publicPath option', () => { }); }); - it('should list the files inside the assets folder (200)', async () => { + it("should list the files inside the assets folder (200)", async () => { const response = await req.get(`${staticPublicPath}/assets/`); expect(response.statusCode).toEqual(200); }); - it('should show Heyo. because bar has index.html inside it (200)', async () => { + it("should show Heyo. because bar has index.html inside it (200)", async () => { const response = await req.get(`${staticPublicPath}/bar/`); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); }); - describe('to directories', () => { + describe("to directories", () => { beforeAll(async () => { const compiler = webpack(config); @@ -257,7 +257,7 @@ describe('static.publicPath option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -279,24 +279,24 @@ describe('static.publicPath option', () => { }); }); - it('Request to first directory', async () => { + it("Request to first directory", async () => { const response = await req.get(`${staticPublicPath}/`); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); - it('Request to second directory', async () => { + it("Request to second directory", async () => { const response = await req.get(`${staticPublicPath}/foo.html`); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Foo!'); + expect(response.text).toContain("Foo!"); }); }); - describe('default to PWD', () => { + describe("default to PWD", () => { beforeAll(async () => { - jest.spyOn(process, 'cwd').mockImplementation(() => staticDirectory); + jest.spyOn(process, "cwd").mockImplementation(() => staticDirectory); const compiler = webpack(config); @@ -311,7 +311,7 @@ describe('static.publicPath option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -333,14 +333,14 @@ describe('static.publicPath option', () => { }); }); - it('Request to page', async () => { + it("Request to page", async () => { const response = await req.get(`${staticPublicPath}/index.html`); expect(response.statusCode).toEqual(200); }); }); - describe('Content type', () => { + describe("Content type", () => { beforeAll(async () => { const compiler = webpack(config); @@ -356,7 +356,7 @@ describe('static.publicPath option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -378,14 +378,14 @@ describe('static.publicPath option', () => { }); }); - it('Request foo.wasm', async () => { + it("Request foo.wasm", async () => { const response = await req.get(`${staticPublicPath}/foo.wasm`); - expect(response.headers['content-type']).toBe('application/wasm'); + expect(response.headers["content-type"]).toBe("application/wasm"); }); }); - describe('to ignore other methods than GET and HEAD', () => { + describe("to ignore other methods than GET and HEAD", () => { beforeAll(async () => { const compiler = webpack(config); @@ -402,7 +402,7 @@ describe('static.publicPath option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -424,44 +424,44 @@ describe('static.publicPath option', () => { }); }); - it('GET request', async () => { + it("GET request", async () => { const response = await req.get(`${staticPublicPath}/`); expect(response.statusCode).toEqual(200); }); - it('HEAD request', async () => { + it("HEAD request", async () => { const response = await req.head(`${staticPublicPath}/`); expect(response.statusCode).toEqual(200); }); - it('POST request', async () => { + it("POST request", async () => { const response = await req.post(`${staticPublicPath}/`); expect(response.statusCode).toEqual(404); }); - it('PUT request', async () => { + it("PUT request", async () => { const response = await req.put(`${staticPublicPath}/`); expect(response.statusCode).toEqual(404); }); - it('DELETE request', async () => { + it("DELETE request", async () => { const response = await req.delete(`${staticPublicPath}/`); expect(response.statusCode).toEqual(404); }); - it('PATCH request', async () => { + it("PATCH request", async () => { const response = await req.patch(`${staticPublicPath}/`); expect(response.statusCode).toEqual(404); }); }); - describe('multiple static.publicPath entries', () => { + describe("multiple static.publicPath entries", () => { beforeAll(async () => { const compiler = webpack(config); @@ -485,7 +485,7 @@ describe('static.publicPath option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -507,29 +507,29 @@ describe('static.publicPath option', () => { }); }); - it('Request the first path to index', async () => { + it("Request the first path to index", async () => { const response = await req.get(`${staticPublicPath}/`); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); - it('Request the first path to other file', async () => { + it("Request the first path to other file", async () => { const response = await req.get(`${staticPublicPath}/other.html`); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Other html'); + expect(response.text).toContain("Other html"); }); - it('Request the second path to foo', async () => { + it("Request the second path to foo", async () => { const response = await req.get(`${otherStaticPublicPath}/foo.html`); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Foo!'); + expect(response.text).toContain("Foo!"); }); }); - describe('multiple static.publicPath entries with publicPath array', () => { + describe("multiple static.publicPath entries with publicPath array", () => { beforeAll(async () => { const compiler = webpack(config); @@ -553,7 +553,7 @@ describe('static.publicPath option', () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -575,32 +575,32 @@ describe('static.publicPath option', () => { }); }); - it('Request the first path to index', async () => { + it("Request the first path to index", async () => { const response = await req.get(`${staticPublicPath}/`); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Heyo'); + expect(response.text).toContain("Heyo"); }); - it('Request the first path to other file', async () => { + it("Request the first path to other file", async () => { const response = await req.get(`${staticPublicPath}/other.html`); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Other html'); + expect(response.text).toContain("Other html"); }); - it('Request the first path to foo', async () => { + it("Request the first path to foo", async () => { const response = await req.get(`${staticPublicPath}/foo.html`); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Foo!'); + expect(response.text).toContain("Foo!"); }); - it('Request the second path to foo', async () => { + it("Request the second path to foo", async () => { const response = await req.get(`${staticPublicPath}/foo.html`); expect(response.statusCode).toEqual(200); - expect(response.text).toContain('Foo!'); + expect(response.text).toContain("Foo!"); }); }); }); diff --git a/test/server/utils/DevServerPlugin.test.js b/test/server/utils/DevServerPlugin.test.js index ae0b9ca58f..ea863895a9 100644 --- a/test/server/utils/DevServerPlugin.test.js +++ b/test/server/utils/DevServerPlugin.test.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict"; -const path = require('path'); -const webpack = require('webpack'); -const DevServerPlugin = require('../../../lib/utils/DevServerPlugin'); -const isWebpack5 = require('../../helpers/isWebpack5'); -const config = require('../../fixtures/simple-config/webpack.config'); +const path = require("path"); +const webpack = require("webpack"); +const DevServerPlugin = require("../../../lib/utils/DevServerPlugin"); +const isWebpack5 = require("../../helpers/isWebpack5"); +const config = require("../../fixtures/simple-config/webpack.config"); -const normalize = (entry) => entry.split(path.sep).join('/'); +const normalize = (entry) => entry.split(path.sep).join("/"); -describe('DevServerPlugin util', () => { +describe("DevServerPlugin util", () => { async function getEntries(compiler) { return compiler.options.entry; } @@ -18,13 +18,13 @@ describe('DevServerPlugin util', () => { const compiler = webpack(webpackOptions); const devServerOptions = { client: { - webSocketTransport: 'sockjs', + webSocketTransport: "sockjs", webSocketURL: {}, }, webSocketServer: { - type: 'sockjs', + type: "sockjs", options: { - host: '0.0.0.0', + host: "0.0.0.0", }, }, }; @@ -32,7 +32,7 @@ describe('DevServerPlugin util', () => { const plugin = new DevServerPlugin(devServerOptions); plugin.apply(compiler); - expect('plugins' in webpackOptions).toBeFalsy(); + expect("plugins" in webpackOptions).toBeFalsy(); }); it("should doesn't add the HMR plugin if not hot and empty plugins", () => { @@ -40,13 +40,13 @@ describe('DevServerPlugin util', () => { const compiler = webpack(webpackOptions); const devServerOptions = { client: { - webSocketTransport: 'sockjs', + webSocketTransport: "sockjs", webSocketURL: {}, }, webSocketServer: { - type: 'sockjs', + type: "sockjs", options: { - host: '0.0.0.0', + host: "0.0.0.0", }, }, }; @@ -58,8 +58,8 @@ describe('DevServerPlugin util', () => { }); it("should doesn't add the HMR plugin if not hot and some plugins", () => { - const existingPlugin1 = new webpack.BannerPlugin('happy birthday'); - const existingPlugin2 = new webpack.DefinePlugin({ foo: 'bar' }); + const existingPlugin1 = new webpack.BannerPlugin("happy birthday"); + const existingPlugin2 = new webpack.DefinePlugin({ foo: "bar" }); const webpackOptions = { ...config, plugins: [existingPlugin1, existingPlugin2], @@ -67,13 +67,13 @@ describe('DevServerPlugin util', () => { const compiler = webpack(webpackOptions); const devServerOptions = { client: { - webSocketTransport: 'sockjs', + webSocketTransport: "sockjs", webSocketURL: {}, }, webSocketServer: { - type: 'sockjs', + type: "sockjs", options: { - host: '0.0.0.0', + host: "0.0.0.0", }, }, }; @@ -85,7 +85,7 @@ describe('DevServerPlugin util', () => { }); it("should doesn't add the HMR plugin again if it's already there", () => { - const existingPlugin = new webpack.BannerPlugin('bruce'); + const existingPlugin = new webpack.BannerPlugin("bruce"); const webpackOptions = { ...config, plugins: [new webpack.HotModuleReplacementPlugin(), existingPlugin], @@ -94,13 +94,13 @@ describe('DevServerPlugin util', () => { const devServerOptions = { hot: true, client: { - webSocketTransport: 'sockjs', + webSocketTransport: "sockjs", webSocketURL: {}, }, webSocketServer: { - type: 'sockjs', + type: "sockjs", options: { - host: '0.0.0.0', + host: "0.0.0.0", }, }, }; @@ -115,20 +115,20 @@ describe('DevServerPlugin util', () => { }); (isWebpack5 ? it.skip : it)( - 'should can prevent duplicate entries from successive calls', + "should can prevent duplicate entries from successive calls", async () => { const webpackOptions = { ...config }; const compiler = webpack(webpackOptions); const devServerOptions = { hot: true, client: { - webSocketTransport: 'sockjs', + webSocketTransport: "sockjs", webSocketURL: {}, }, webSocketServer: { - type: 'sockjs', + type: "sockjs", options: { - host: '0.0.0.0', + host: "0.0.0.0", }, }, }; @@ -143,7 +143,7 @@ describe('DevServerPlugin util', () => { expect(entries.length).toEqual(3); const result = entries.filter((entry) => - normalize(entry).includes('webpack/hot/dev-server') + normalize(entry).includes("webpack/hot/dev-server") ); expect(result.length).toEqual(1); } @@ -151,19 +151,19 @@ describe('DevServerPlugin util', () => { // 'npm run prepare' must be done for this test to pass const sockjsClientPath = require.resolve( - '../../../client/clients/SockJSClient' + "../../../client/clients/SockJSClient" ); - describe('getWebsocketTransport', () => { + describe("getWebsocketTransport", () => { it("should work with client.webSocketTransport: 'sockjs'", () => { let result; expect(() => { const devServerPlugin = new DevServerPlugin({ client: { - webSocketTransport: 'sockjs', + webSocketTransport: "sockjs", }, - webSocketServer: 'sockjs', + webSocketServer: "sockjs", }); result = devServerPlugin.getWebsocketTransport(); @@ -172,7 +172,7 @@ describe('DevServerPlugin util', () => { expect(result).toEqual(sockjsClientPath); }); - it('should work with client.webSocketTransport: SockJSClient full path', () => { + it("should work with client.webSocketTransport: SockJSClient full path", () => { let result; expect(() => { @@ -180,7 +180,7 @@ describe('DevServerPlugin util', () => { client: { webSocketTransport: sockjsClientPath, }, - webSocketServer: 'sockjs', + webSocketServer: "sockjs", }); result = devServerPlugin.getWebsocketTransport(); @@ -189,44 +189,44 @@ describe('DevServerPlugin util', () => { expect(result).toEqual(sockjsClientPath); }); - it('should throw with client.webSocketTransport: bad path', () => { + it("should throw with client.webSocketTransport: bad path", () => { expect(() => { const devServerPlugin = new DevServerPlugin({ client: { - webSocketTransport: '/bad/path/to/implementation', + webSocketTransport: "/bad/path/to/implementation", }, - webSocketServer: 'sockjs', + webSocketServer: "sockjs", }); devServerPlugin.getWebsocketTransport(); }).toThrow(/client.webSocketTransport must be a string/); }); - it('should throw with webSocketTransportMode.client: bad type', () => { + it("should throw with webSocketTransportMode.client: bad type", () => { expect(() => { const devServerPlugin = new DevServerPlugin({ client: { webSocketTransport: 1, }, - webSocketServer: 'sockjs', + webSocketServer: "sockjs", }); devServerPlugin.getWebsocketTransport(); }).toThrow(/client.webSocketTransport must be a string/); }); - it('should throw with client.webSocketTransport: unimplemented client', () => { + it("should throw with client.webSocketTransport: unimplemented client", () => { expect(() => { const devServerPlugin = new DevServerPlugin({ client: { - webSocketTransport: 'foo', + webSocketTransport: "foo", }, - webSocketServer: 'sockjs', + webSocketServer: "sockjs", }); devServerPlugin.getWebsocketTransport(); }).toThrow( - 'When you use custom web socket implementation you must explicitly specify client.webSocketTransport' + "When you use custom web socket implementation you must explicitly specify client.webSocketTransport" ); }); }); diff --git a/test/server/utils/getCompilerConfigArray.test.js b/test/server/utils/getCompilerConfigArray.test.js index 4595b94341..afa08ab6b5 100644 --- a/test/server/utils/getCompilerConfigArray.test.js +++ b/test/server/utils/getCompilerConfigArray.test.js @@ -1,47 +1,47 @@ -'use strict'; +"use strict"; -const webpack = require('webpack'); -const getCompilerConfigArray = require('../../../lib/utils/getCompilerConfigArray'); -const isWebpack5 = require('../../helpers/isWebpack5'); +const webpack = require("webpack"); +const getCompilerConfigArray = require("../../../lib/utils/getCompilerConfigArray"); +const isWebpack5 = require("../../helpers/isWebpack5"); -describe('getCompilerConfigArray', () => { - it('should get config array from single compiler', () => { +describe("getCompilerConfigArray", () => { + it("should get config array from single compiler", () => { const compiler = webpack({ - stats: 'errors-only', + stats: "errors-only", }); const configArr = getCompilerConfigArray(compiler); expect(configArr.length).toEqual(1); const stats = configArr[0].stats; if (isWebpack5) { expect(stats).toEqual({ - preset: 'errors-only', + preset: "errors-only", }); } else { - expect(stats).toEqual('errors-only'); + expect(stats).toEqual("errors-only"); } }); - it('should get config array from multi compiler', () => { + it("should get config array from multi compiler", () => { const compiler = webpack([ { - stats: 'none', + stats: "none", }, { - stats: 'errors-only', + stats: "errors-only", }, ]); const configArr = getCompilerConfigArray(compiler); expect(configArr.length).toEqual(2); if (isWebpack5) { expect(configArr[0].stats).toEqual({ - preset: 'none', + preset: "none", }); expect(configArr[1].stats).toEqual({ - preset: 'errors-only', + preset: "errors-only", }); } else { - expect(configArr[0].stats).toEqual('none'); - expect(configArr[1].stats).toEqual('errors-only'); + expect(configArr[0].stats).toEqual("none"); + expect(configArr[1].stats).toEqual("errors-only"); } }); }); diff --git a/test/server/utils/normalizeOptions.test.js b/test/server/utils/normalizeOptions.test.js index f43e829832..a6e12819c7 100644 --- a/test/server/utils/normalizeOptions.test.js +++ b/test/server/utils/normalizeOptions.test.js @@ -1,67 +1,67 @@ -'use strict'; +"use strict"; -const path = require('path'); -const webpack = require('webpack'); -const normalizeOptions = require('../../../lib/utils/normalizeOptions'); +const path = require("path"); +const webpack = require("webpack"); +const normalizeOptions = require("../../../lib/utils/normalizeOptions"); -describe('normalizeOptions', () => { +describe("normalizeOptions", () => { const cases = [ { - title: 'no options', + title: "no options", multiCompiler: false, options: {}, optionsResults: null, }, { - title: 'port string', + title: "port string", multiCompiler: false, options: { - port: '9000', + port: "9000", }, optionsResults: null, }, { - title: 'client.webSocketTransport sockjs string', + title: "client.webSocketTransport sockjs string", multiCompiler: false, options: { client: { - webSocketTransport: 'sockjs', + webSocketTransport: "sockjs", }, }, optionsResults: null, }, { - title: 'client.webSocketTransport ws string', + title: "client.webSocketTransport ws string", multiCompiler: false, options: { client: { - webSocketTransport: 'ws', + webSocketTransport: "ws", }, }, optionsResults: null, }, { title: - 'client.webSocketTransport ws string and webSocketServer ws string', + "client.webSocketTransport ws string and webSocketServer ws string", multiCompiler: false, options: { client: { - webSocketTransport: 'ws', + webSocketTransport: "ws", }, - webSocketServer: 'ws', + webSocketServer: "ws", }, optionsResults: null, }, { - title: 'webSocketServer custom server path', + title: "webSocketServer custom server path", multiCompiler: false, options: { - webSocketServer: '/path/to/custom/server/', + webSocketServer: "/path/to/custom/server/", }, optionsResults: null, }, { - title: 'webSocketServer custom server class', + title: "webSocketServer custom server class", multiCompiler: false, options: { webSocketServer: class CustomServerImplementation {}, @@ -69,18 +69,18 @@ describe('normalizeOptions', () => { optionsResults: null, }, { - title: 'client.webSocketTransport ws string and webSocketServer object', + title: "client.webSocketTransport ws string and webSocketServer object", multiCompiler: false, options: { client: { - webSocketTransport: 'ws', + webSocketTransport: "ws", }, webSocketServer: { - type: 'ws', + type: "ws", options: { - host: 'myhost', + host: "myhost", port: 9999, - path: '/ws', + path: "/ws", }, }, }, @@ -88,40 +88,40 @@ describe('normalizeOptions', () => { }, { title: - 'client.webSocketTransport ws string and webSocketServer object with port as string', + "client.webSocketTransport ws string and webSocketServer object with port as string", multiCompiler: false, options: { client: { - webSocketTransport: 'ws', + webSocketTransport: "ws", }, webSocketServer: { - type: 'ws', + type: "ws", options: { - host: 'myhost', - port: '8080', - path: '/ws', + host: "myhost", + port: "8080", + path: "/ws", }, }, }, optionsResults: null, }, { - title: 'client custom webSocketTransport path', + title: "client custom webSocketTransport path", multiCompiler: false, options: { client: { - webSocketTransport: '/path/to/custom/client/', + webSocketTransport: "/path/to/custom/client/", }, }, optionsResults: null, }, { - title: 'client host and port', + title: "client host and port", multiCompiler: false, options: { client: { webSocketURL: { - hostname: 'my.host', + hostname: "my.host", port: 9000, }, }, @@ -129,57 +129,57 @@ describe('normalizeOptions', () => { optionsResults: null, }, { - title: 'client host and string port', + title: "client host and string port", multiCompiler: false, options: { client: { webSocketURL: { - hostname: 'my.host', - port: '9000', + hostname: "my.host", + port: "9000", }, }, }, optionsResults: null, }, { - title: 'client path', + title: "client path", multiCompiler: false, options: { client: { webSocketURL: { - pathname: '/custom/path/', + pathname: "/custom/path/", }, }, }, optionsResults: null, }, { - title: 'username and password', + title: "username and password", multiCompiler: false, options: { client: { webSocketURL: { - username: 'zenitsu', - password: 'chuntaro', + username: "zenitsu", + password: "chuntaro", }, }, }, optionsResults: null, }, { - title: 'client path without leading/ending slashes', + title: "client path without leading/ending slashes", multiCompiler: false, options: { client: { webSocketURL: { - pathname: 'custom/path', + pathname: "custom/path", }, }, }, optionsResults: null, }, { - title: 'liveReload is true', + title: "liveReload is true", multiCompiler: false, options: { liveReload: true, @@ -187,7 +187,7 @@ describe('normalizeOptions', () => { optionsResults: null, }, { - title: 'liveReload is false', + title: "liveReload is false", multiCompiler: false, options: { liveReload: false, @@ -195,7 +195,7 @@ describe('normalizeOptions', () => { optionsResults: null, }, { - title: 'hot is true', + title: "hot is true", multiCompiler: false, options: { hot: true, @@ -203,7 +203,7 @@ describe('normalizeOptions', () => { optionsResults: null, }, { - title: 'hot is false', + title: "hot is false", multiCompiler: false, options: { hot: false, @@ -211,15 +211,15 @@ describe('normalizeOptions', () => { optionsResults: null, }, { - title: 'hot is only', + title: "hot is only", multiCompiler: false, options: { - hot: 'only', + hot: "only", }, optionsResults: null, }, { - title: 'dev is set', + title: "dev is set", multiCompiler: false, options: { devMiddleware: { @@ -229,7 +229,7 @@ describe('normalizeOptions', () => { optionsResults: null, }, { - title: 'static is true', + title: "static is true", multiCompiler: false, options: { static: true, @@ -237,7 +237,7 @@ describe('normalizeOptions', () => { optionsResults: null, }, { - title: 'static is false', + title: "static is false", multiCompiler: false, options: { static: false, @@ -245,92 +245,92 @@ describe('normalizeOptions', () => { optionsResults: null, }, { - title: 'static is string', + title: "static is string", multiCompiler: false, options: { - static: '/static/path', + static: "/static/path", }, optionsResults: null, }, { - title: 'static is an array of strings', + title: "static is an array of strings", multiCompiler: false, options: { - static: ['/static/path1', '/static/path2'], + static: ["/static/path1", "/static/path2"], }, optionsResults: null, }, { - title: 'static is an array of static objects', + title: "static is an array of static objects", multiCompiler: false, options: { static: [ { - directory: '/static/path1', + directory: "/static/path1", }, { - publicPath: '/static/public/path', + publicPath: "/static/public/path", }, ], }, optionsResults: null, }, { - title: 'static is an array of strings and static objects', + title: "static is an array of strings and static objects", multiCompiler: false, options: { static: [ - '/static/path1', + "/static/path1", { - publicPath: '/static/public/path/', + publicPath: "/static/public/path/", }, ], }, optionsResults: null, }, { - title: 'static is an object', + title: "static is an object", multiCompiler: false, options: { static: { - directory: '/static/path', + directory: "/static/path", }, }, optionsResults: null, }, { - title: 'static directory is an absolute url and throws error', + title: "static directory is an absolute url and throws error", multiCompiler: false, options: { static: { - directory: 'http://localhost:8080', + directory: "http://localhost:8080", }, }, optionsResults: null, - throws: 'Using a URL as static.directory is not supported', + throws: "Using a URL as static.directory is not supported", }, { - title: 'static publicPath is a string', + title: "static publicPath is a string", multiCompiler: false, options: { static: { - publicPath: '/static/public/path/', + publicPath: "/static/public/path/", }, }, optionsResults: null, }, { - title: 'static publicPath is an array', + title: "static publicPath is an array", multiCompiler: false, options: { static: { - publicPath: ['/static/public/path1/', '/static/public/path2/'], + publicPath: ["/static/public/path1/", "/static/public/path2/"], }, }, optionsResults: null, }, { - title: 'static watch is false', + title: "static watch is false", multiCompiler: false, options: { static: { @@ -340,7 +340,7 @@ describe('normalizeOptions', () => { optionsResults: null, }, { - title: 'static watch is true', + title: "static watch is true", multiCompiler: false, options: { static: { @@ -350,7 +350,7 @@ describe('normalizeOptions', () => { optionsResults: null, }, { - title: 'static watch is an object', + title: "static watch is an object", multiCompiler: false, options: { static: { @@ -362,7 +362,7 @@ describe('normalizeOptions', () => { optionsResults: null, }, { - title: 'static serveIndex is false', + title: "static serveIndex is false", multiCompiler: false, options: { static: { @@ -372,7 +372,7 @@ describe('normalizeOptions', () => { optionsResults: null, }, { - title: 'static serveIndex is true', + title: "static serveIndex is true", multiCompiler: false, options: { static: { @@ -382,7 +382,7 @@ describe('normalizeOptions', () => { optionsResults: null, }, { - title: 'static serveIndex is an object', + title: "static serveIndex is an object", multiCompiler: false, options: { static: { @@ -395,7 +395,7 @@ describe('normalizeOptions', () => { }, { - title: 'single compiler watchOptions is object', + title: "single compiler watchOptions is object", multiCompiler: false, options: {}, optionsResults: null, @@ -407,7 +407,7 @@ describe('normalizeOptions', () => { }, }, { - title: 'single compiler watchOptions is object with watch false', + title: "single compiler watchOptions is object with watch false", multiCompiler: false, options: {}, optionsResults: null, @@ -419,7 +419,7 @@ describe('normalizeOptions', () => { }, }, { - title: 'single compiler watchOptions is object with static watch true', + title: "single compiler watchOptions is object with static watch true", multiCompiler: false, options: { static: { @@ -436,7 +436,7 @@ describe('normalizeOptions', () => { }, { title: - 'single compiler watchOptions is object with static watch overriding it', + "single compiler watchOptions is object with static watch overriding it", multiCompiler: false, options: { static: { @@ -454,7 +454,7 @@ describe('normalizeOptions', () => { }, }, { - title: 'multi compiler watchOptions is set', + title: "multi compiler watchOptions is set", multiCompiler: true, options: {}, optionsResults: null, @@ -470,10 +470,10 @@ describe('normalizeOptions', () => { ], }, { - title: 'allowedHosts is set', + title: "allowedHosts is set", multiCompiler: false, options: { - allowedHosts: 'all', + allowedHosts: "all", }, optionsResults: null, }, @@ -485,14 +485,14 @@ describe('normalizeOptions', () => { beforeAll(() => { let webpackConfig; if (data.multiCompiler) { - webpackConfig = require('../../fixtures/multi-compiler-config/webpack.config'); + webpackConfig = require("../../fixtures/multi-compiler-config/webpack.config"); if (Array.isArray(data.webpackConfig)) { webpackConfig = data.webpackConfig.map((config, index) => { return { ...webpackConfig[index], ...config }; }); } } else { - webpackConfig = require('../../fixtures/simple-config/webpack.config'); + webpackConfig = require("../../fixtures/simple-config/webpack.config"); if (data.webpackConfig) { webpackConfig = { ...webpackConfig, @@ -504,7 +504,7 @@ describe('normalizeOptions', () => { compiler = webpack(webpackConfig); }); - it('should set correct options', () => { + it("should set correct options", () => { const originalContentBase = data.options.contentBase; if (data.throws) { expect(() => { @@ -526,10 +526,10 @@ describe('normalizeOptions', () => { if (data.options.static) { data.options.static.forEach((staticOpts) => { - if (staticOpts.directory === path.join(process.cwd(), 'public')) { + if (staticOpts.directory === path.join(process.cwd(), "public")) { // give an indication in the snapshot that this is the // current working directory - staticOpts.directory = 'CWD'; + staticOpts.directory = "CWD"; } }); } diff --git a/test/server/watchFiles-option.test.js b/test/server/watchFiles-option.test.js index aac4046b6d..2cdcb662ca 100644 --- a/test/server/watchFiles-option.test.js +++ b/test/server/watchFiles-option.test.js @@ -1,23 +1,23 @@ -'use strict'; +"use strict"; -const path = require('path'); -const webpack = require('webpack'); -const fs = require('graceful-fs'); -const chokidar = require('chokidar'); -const Server = require('../../lib/Server'); -const config = require('../fixtures/contentbase-config/webpack.config'); -const port = require('../ports-map')['watch-files-option']; +const path = require("path"); +const webpack = require("webpack"); +const fs = require("graceful-fs"); +const chokidar = require("chokidar"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/contentbase-config/webpack.config"); +const port = require("../ports-map")["watch-files-option"]; const watchDir = path.resolve( __dirname, - '../fixtures/contentbase-config/public' + "../fixtures/contentbase-config/public" ); describe("'watchFiles' option", () => { let server; - describe('should work with string and path to file', () => { - const file = path.join(watchDir, 'assets/example.txt'); + describe("should work with string and path to file", () => { + const file = path.join(watchDir, "assets/example.txt"); beforeAll(async () => { const compiler = webpack(config); @@ -31,7 +31,7 @@ describe("'watchFiles' option", () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -53,8 +53,8 @@ describe("'watchFiles' option", () => { fs.truncateSync(file); }); - it('should reload on file content changed', (done) => { - server.staticWatchers[0].on('change', (changedPath) => { + it("should reload on file content changed", (done) => { + server.staticWatchers[0].on("change", (changedPath) => { expect(changedPath).toBe(file); done(); @@ -62,13 +62,13 @@ describe("'watchFiles' option", () => { // change file content setTimeout(() => { - fs.writeFileSync(file, 'Kurosaki Ichigo', 'utf8'); + fs.writeFileSync(file, "Kurosaki Ichigo", "utf8"); }, 1000); }); }); - describe('should work with string and path to dir', () => { - const file = path.join(watchDir, 'assets/example.txt'); + describe("should work with string and path to dir", () => { + const file = path.join(watchDir, "assets/example.txt"); beforeAll(async () => { const compiler = webpack(config); @@ -82,7 +82,7 @@ describe("'watchFiles' option", () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -104,8 +104,8 @@ describe("'watchFiles' option", () => { fs.truncateSync(file); }); - it('should reload on file content changed', (done) => { - server.staticWatchers[0].on('change', (changedPath) => { + it("should reload on file content changed", (done) => { + server.staticWatchers[0].on("change", (changedPath) => { expect(changedPath).toBe(file); done(); @@ -113,13 +113,13 @@ describe("'watchFiles' option", () => { // change file content setTimeout(() => { - fs.writeFileSync(file, 'Kurosaki Ichigo', 'utf8'); + fs.writeFileSync(file, "Kurosaki Ichigo", "utf8"); }, 1000); }); }); - describe('should work with string and glob', () => { - const file = path.join(watchDir, 'assets/example.txt'); + describe("should work with string and glob", () => { + const file = path.join(watchDir, "assets/example.txt"); beforeAll(async () => { const compiler = webpack(config); @@ -133,7 +133,7 @@ describe("'watchFiles' option", () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -155,8 +155,8 @@ describe("'watchFiles' option", () => { fs.truncateSync(file); }); - it('should reload on file content changed', (done) => { - server.staticWatchers[0].on('change', (changedPath) => { + it("should reload on file content changed", (done) => { + server.staticWatchers[0].on("change", (changedPath) => { expect(changedPath).toBe(file); done(); @@ -164,13 +164,13 @@ describe("'watchFiles' option", () => { // change file content setTimeout(() => { - fs.writeFileSync(file, 'Kurosaki Ichigo', 'utf8'); + fs.writeFileSync(file, "Kurosaki Ichigo", "utf8"); }, 1000); }); }); - describe('should work not crash on non exist file', () => { - const nonExistFile = path.join(watchDir, 'assets/non-exist.txt'); + describe("should work not crash on non exist file", () => { + const nonExistFile = path.join(watchDir, "assets/non-exist.txt"); beforeAll(async () => { try { @@ -190,7 +190,7 @@ describe("'watchFiles' option", () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -212,8 +212,8 @@ describe("'watchFiles' option", () => { fs.truncateSync(nonExistFile); }); - it('should reload on file content changed', (done) => { - server.staticWatchers[0].once('change', (changedPath) => { + it("should reload on file content changed", (done) => { + server.staticWatchers[0].once("change", (changedPath) => { expect(changedPath).toBe(nonExistFile); done(); @@ -221,18 +221,18 @@ describe("'watchFiles' option", () => { // create file content setTimeout(() => { - fs.writeFileSync(nonExistFile, 'Kurosaki Ichigo', 'utf8'); + fs.writeFileSync(nonExistFile, "Kurosaki Ichigo", "utf8"); // change file content setTimeout(() => { - fs.writeFileSync(nonExistFile, 'Kurosaki Ichigo', 'utf8'); + fs.writeFileSync(nonExistFile, "Kurosaki Ichigo", "utf8"); }, 1000); }, 1000); }); }); - describe('should work with object with single path', () => { - const file = path.join(watchDir, 'assets/example.txt'); + describe("should work with object with single path", () => { + const file = path.join(watchDir, "assets/example.txt"); beforeAll(async () => { const compiler = webpack(config); @@ -246,7 +246,7 @@ describe("'watchFiles' option", () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -268,8 +268,8 @@ describe("'watchFiles' option", () => { fs.truncateSync(file); }); - it('should reload on file content channge', (done) => { - server.staticWatchers[0].on('change', (changedPath) => { + it("should reload on file content channge", (done) => { + server.staticWatchers[0].on("change", (changedPath) => { expect(changedPath).toBe(file); done(); @@ -277,14 +277,14 @@ describe("'watchFiles' option", () => { // change file content setTimeout(() => { - fs.writeFileSync(file, 'Kurosaki Ichigo', 'utf8'); + fs.writeFileSync(file, "Kurosaki Ichigo", "utf8"); }, 1000); }); }); - describe('should work with object with multiple paths', () => { - const file = path.join(watchDir, 'assets/example.txt'); - const other = path.join(watchDir, 'assets/other.txt'); + describe("should work with object with multiple paths", () => { + const file = path.join(watchDir, "assets/example.txt"); + const other = path.join(watchDir, "assets/other.txt"); beforeAll(async () => { const compiler = webpack(config); @@ -298,7 +298,7 @@ describe("'watchFiles' option", () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -320,12 +320,12 @@ describe("'watchFiles' option", () => { fs.truncateSync(file); }); - it('should reload on file content channge', (done) => { + it("should reload on file content channge", (done) => { const expected = [file, other]; let changed = 0; - server.staticWatchers[0].on('change', (changedPath) => { + server.staticWatchers[0].on("change", (changedPath) => { expect(expected.includes(changedPath)).toBeTruthy(); changed += 1; @@ -337,15 +337,15 @@ describe("'watchFiles' option", () => { // change file content setTimeout(() => { - fs.writeFileSync(file, 'Kurosaki Ichigo', 'utf8'); - fs.writeFileSync(other, 'Kurosaki Ichigo', 'utf8'); + fs.writeFileSync(file, "Kurosaki Ichigo", "utf8"); + fs.writeFileSync(other, "Kurosaki Ichigo", "utf8"); }, 1000); }); }); - describe('should work with array config', () => { - const file = path.join(watchDir, 'assets/example.txt'); - const other = path.join(watchDir, 'assets/other.txt'); + describe("should work with array config", () => { + const file = path.join(watchDir, "assets/example.txt"); + const other = path.join(watchDir, "assets/other.txt"); beforeAll(async () => { const compiler = webpack(config); @@ -359,7 +359,7 @@ describe("'watchFiles' option", () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -382,10 +382,10 @@ describe("'watchFiles' option", () => { fs.truncateSync(other); }); - it('should reload on file content change', (done) => { + it("should reload on file content change", (done) => { let changed = 0; - server.staticWatchers[0].on('change', (changedPath) => { + server.staticWatchers[0].on("change", (changedPath) => { expect(changedPath).toBe(file); changed += 1; @@ -395,7 +395,7 @@ describe("'watchFiles' option", () => { } }); - server.staticWatchers[1].on('change', (changedPath) => { + server.staticWatchers[1].on("change", (changedPath) => { expect(changedPath).toBe(other); changed += 1; @@ -407,16 +407,16 @@ describe("'watchFiles' option", () => { // change file content setTimeout(() => { - fs.writeFileSync(file, 'Kurosaki Ichigo', 'utf8'); - fs.writeFileSync(other, 'Kurosaki Ichigo', 'utf8'); + fs.writeFileSync(file, "Kurosaki Ichigo", "utf8"); + fs.writeFileSync(other, "Kurosaki Ichigo", "utf8"); }, 1000); }); }); - describe('should work with options', () => { - const file = path.join(watchDir, 'assets/example.txt'); + describe("should work with options", () => { + const file = path.join(watchDir, "assets/example.txt"); - const chokidarMock = jest.spyOn(chokidar, 'watch'); + const chokidarMock = jest.spyOn(chokidar, "watch"); const optionCases = [ { @@ -461,7 +461,7 @@ describe("'watchFiles' option", () => { ); await new Promise((resolve, reject) => { - server.listen(port, '127.0.0.1', (error) => { + server.listen(port, "127.0.0.1", (error) => { if (error) { reject(error); @@ -483,12 +483,12 @@ describe("'watchFiles' option", () => { fs.truncateSync(file); }); - it('should pass correct options to chokidar config', () => { + it("should pass correct options to chokidar config", () => { expect(chokidarMock.mock.calls[0][1]).toMatchSnapshot(); }); - it('should reload on file content changed', (done) => { - server.staticWatchers[0].on('change', (changedPath) => { + it("should reload on file content changed", (done) => { + server.staticWatchers[0].on("change", (changedPath) => { expect(changedPath).toBe(file); done(); @@ -496,7 +496,7 @@ describe("'watchFiles' option", () => { // change file content setTimeout(() => { - fs.writeFileSync(file, 'Kurosaki Ichigo', 'utf8'); + fs.writeFileSync(file, "Kurosaki Ichigo", "utf8"); }, 1000); }); }); diff --git a/test/server/webSocketServer-option.test.js b/test/server/webSocketServer-option.test.js index ab67eb97d0..0514d46522 100644 --- a/test/server/webSocketServer-option.test.js +++ b/test/server/webSocketServer-option.test.js @@ -1,23 +1,23 @@ -'use strict'; +"use strict"; /* eslint-disable class-methods-use-this */ -const sockjs = require('sockjs'); -const SockJS = require('sockjs-client/dist/sockjs'); -const config = require('../fixtures/simple-config/webpack.config'); -const BaseServer = require('../../lib/servers/BaseServer'); -const port = require('../ports-map')['web-socket-server-option']; - -describe('webSocketServer', () => { - describe('server', () => { +const sockjs = require("sockjs"); +const SockJS = require("sockjs-client/dist/sockjs"); +const config = require("../fixtures/simple-config/webpack.config"); +const BaseServer = require("../../lib/servers/BaseServer"); +const port = require("../ports-map")["web-socket-server-option"]; + +describe("webSocketServer", () => { + describe("server", () => { let testServer; let server; - describe('passed to server', () => { + describe("passed to server", () => { beforeAll(() => { - jest.unmock('../../lib/utils/getSocketServerImplementation'); - testServer = require('../helpers/test-server'); + jest.unmock("../../lib/utils/getSocketServerImplementation"); + testServer = require("../helpers/test-server"); }); afterEach((done) => { @@ -25,7 +25,7 @@ describe('webSocketServer', () => { server = null; }); - describe.skip('without a header', () => { + describe.skip("without a header", () => { let mockWarn; beforeAll((done) => { @@ -33,18 +33,18 @@ describe('webSocketServer', () => { config, { port, - client: { webSocketTransport: 'sockjs' }, + client: { webSocketTransport: "sockjs" }, webSocketServer: class MySockJSServer extends BaseServer { constructor(serv) { super(serv); this.implementation = sockjs.createServer({ // Use provided up-to-date sockjs-client - sockjs_url: '/__webpack_dev_server__/sockjs.bundle.js', + sockjs_url: "/__webpack_dev_server__/sockjs.bundle.js", // Limit useless logs log: (severity, line) => { - if (severity === 'error') { + if (severity === "error") { this.server.logger.error(line); - } else if (severity === 'info') { + } else if (severity === "info") { this.server.logger.log(line); } else { this.server.logger.debug(line); @@ -53,7 +53,7 @@ describe('webSocketServer', () => { }); this.implementation.installHandlers(this.server.server, { - prefix: '/ws', + prefix: "/ws", }); } @@ -76,13 +76,13 @@ describe('webSocketServer', () => { } onConnection(f) { - this.implementation.on('connection', (connection) => { + this.implementation.on("connection", (connection) => { f(connection); }); } onConnectionClose(connection, f) { - connection.on('close', f); + connection.on("close", f); } }, }, @@ -90,16 +90,16 @@ describe('webSocketServer', () => { ); mockWarn = jest - .spyOn(server.logger, 'warn') + .spyOn(server.logger, "warn") .mockImplementation(() => {}); }); - it('results in an error', (done) => { + it("results in an error", (done) => { const data = []; const client = new SockJS(`http://localhost:${port}/ws`); client.onopen = () => { - data.push('open'); + data.push("open"); }; client.onmessage = (e) => { @@ -107,7 +107,7 @@ describe('webSocketServer', () => { }; client.onclose = () => { - data.push('close'); + data.push("close"); }; setTimeout(() => { @@ -137,24 +137,24 @@ describe('webSocketServer', () => { }); }); - describe.skip('with a bad host header', () => { + describe.skip("with a bad host header", () => { beforeAll((done) => { server = testServer.start( config, { port, - client: { webSocketTransport: 'sockjs' }, + client: { webSocketTransport: "sockjs" }, webSocketServer: class MySockJSServer extends BaseServer { constructor(serv) { super(serv); this.implementation = sockjs.createServer({ // Use provided up-to-date sockjs-client - sockjs_url: '/__webpack_dev_server__/sockjs.bundle.js', + sockjs_url: "/__webpack_dev_server__/sockjs.bundle.js", // Limit useless logs log: (severity, line) => { - if (severity === 'error') { + if (severity === "error") { this.server.logger.error(line); - } else if (severity === 'info') { + } else if (severity === "info") { this.server.logger.log(line); } else { this.server.logger.debug(line); @@ -163,7 +163,7 @@ describe('webSocketServer', () => { }); this.implementation.installHandlers(this.server.server, { - prefix: '/ws', + prefix: "/ws", }); } @@ -186,7 +186,7 @@ describe('webSocketServer', () => { } onConnection(f) { - this.implementation.on('connection', (connection) => { + this.implementation.on("connection", (connection) => { f(connection, { host: null, }); @@ -194,7 +194,7 @@ describe('webSocketServer', () => { } onConnectionClose(connection, f) { - connection.on('close', f); + connection.on("close", f); } }, }, @@ -202,12 +202,12 @@ describe('webSocketServer', () => { ); }); - it('results in an error', (done) => { + it("results in an error", (done) => { const data = []; const client = new SockJS(`http://localhost:${port}/ws`); client.onopen = () => { - data.push('open'); + data.push("open"); }; client.onmessage = (e) => { @@ -215,7 +215,7 @@ describe('webSocketServer', () => { }; client.onclose = () => { - data.push('close'); + data.push("close"); }; setTimeout(() => { diff --git a/test/validate-options.test.js b/test/validate-options.test.js index 27203b8e0f..d984d48b52 100644 --- a/test/validate-options.test.js +++ b/test/validate-options.test.js @@ -1,16 +1,16 @@ -'use strict'; +"use strict"; -const os = require('os'); -const path = require('path'); -const { readFileSync } = require('graceful-fs'); -const webpack = require('webpack'); -const { createFsFromVolume, Volume } = require('memfs'); -const Server = require('../lib/Server'); -const config = require('./fixtures/simple-config/webpack.config'); +const os = require("os"); +const path = require("path"); +const { readFileSync } = require("graceful-fs"); +const webpack = require("webpack"); +const { createFsFromVolume, Volume } = require("memfs"); +const Server = require("../lib/Server"); +const config = require("./fixtures/simple-config/webpack.config"); const httpsCertificateDirectory = path.join( __dirname, - './fixtures/https-certificate' + "./fixtures/https-certificate" ); const tests = { @@ -23,29 +23,29 @@ const tests = { failure: [false], }, bonjour: { - success: [false, true, { type: 'https' }], - failure: [''], + success: [false, true, { type: "https" }], + failure: [""], }, client: { success: [ {}, { - logging: 'none', + logging: "none", }, { - logging: 'error', + logging: "error", }, { - logging: 'warn', + logging: "warn", }, { - logging: 'info', + logging: "info", }, { - logging: 'log', + logging: "log", }, { - logging: 'verbose', + logging: "verbose", }, { progress: false, @@ -67,77 +67,77 @@ const tests = { }, }, { - webSocketTransport: 'sockjs', + webSocketTransport: "sockjs", }, { - webSocketTransport: require.resolve('../client/clients/SockJSClient'), + webSocketTransport: require.resolve("../client/clients/SockJSClient"), }, { - webSocketURL: 'ws://localhost:8080', + webSocketURL: "ws://localhost:8080", }, { - webSocketURL: { hostname: 'localhost' }, + webSocketURL: { hostname: "localhost" }, }, { webSocketURL: { port: 8080 }, }, { - webSocketURL: { port: '8080' }, + webSocketURL: { port: "8080" }, }, { - webSocketURL: { pathname: '' }, + webSocketURL: { pathname: "" }, }, { - webSocketURL: { pathname: '/my-path/' }, + webSocketURL: { pathname: "/my-path/" }, }, { webSocketURL: { - hostname: 'localhost', + hostname: "localhost", port: 8080, - pathname: '/my-path/', + pathname: "/my-path/", }, }, { - webSocketURL: { username: 'zoro', password: 'roronoa' }, + webSocketURL: { username: "zoro", password: "roronoa" }, }, ], failure: [ - 'whoops!', + "whoops!", { unknownOption: true, }, { - logging: 'whoops!', + logging: "whoops!", }, { - logging: 'silent', + logging: "silent", }, { - progress: '', + progress: "", }, { - overlay: '', + overlay: "", }, { overlay: { - errors: '', + errors: "", }, }, { overlay: { - warnings: '', + warnings: "", }, }, { overlay: { - arbitrary: '', + arbitrary: "", }, }, { webSocketTransport: true, }, { - webSocketURL: { hostname: true, pathname: '', port: 8080 }, + webSocketURL: { hostname: true, pathname: "", port: 8080 }, }, { webSocketURL: { pathname: true }, @@ -146,10 +146,10 @@ const tests = { webSocketURL: { port: true }, }, { - webSocketURL: { hostname: '' }, + webSocketURL: { hostname: "" }, }, { - webSocketURL: { port: '' }, + webSocketURL: { port: "" }, }, { webSocketURL: { username: 123, password: 976 }, @@ -158,60 +158,60 @@ const tests = { }, compress: { success: [false, true], - failure: [''], + failure: [""], }, devMiddleware: { success: [{}], - failure: [''], + failure: [""], }, allowedHosts: { - success: ['auto', 'all', ['foo'], 'bar'], - failure: [true, false, 123, [], ['']], + success: ["auto", "all", ["foo"], "bar"], + failure: [true, false, 123, [], [""]], }, headers: { - success: [{}, { foo: 'bar' }, () => {}], + success: [{}, { foo: "bar" }, () => {}], failure: [false, 1], }, historyApiFallback: { success: [{}, true], - failure: [''], + failure: [""], }, host: { - success: ['localhost', '::', '::1'], - failure: [false, '', null], + success: ["localhost", "::", "::1"], + failure: [false, "", null], }, hot: { - success: [true, 'only'], - failure: ['', 'foo'], + success: [true, "only"], + failure: ["", "foo"], }, http2: { success: [false, true], - failure: [''], + failure: [""], }, https: { success: [ false, true, { - cacert: path.join(httpsCertificateDirectory, 'ca.pem'), - key: path.join(httpsCertificateDirectory, 'server.key'), - pfx: path.join(httpsCertificateDirectory, 'server.pfx'), - cert: path.join(httpsCertificateDirectory, 'server.crt'), + cacert: path.join(httpsCertificateDirectory, "ca.pem"), + key: path.join(httpsCertificateDirectory, "server.key"), + pfx: path.join(httpsCertificateDirectory, "server.pfx"), + cert: path.join(httpsCertificateDirectory, "server.crt"), requestCert: true, - passphrase: 'webpack-dev-server', + passphrase: "webpack-dev-server", }, { - cacert: readFileSync(path.join(httpsCertificateDirectory, 'ca.pem')), - pfx: readFileSync(path.join(httpsCertificateDirectory, 'server.pfx')), - key: readFileSync(path.join(httpsCertificateDirectory, 'server.key')), - cert: readFileSync(path.join(httpsCertificateDirectory, 'server.crt')), - passphrase: 'webpack-dev-server', + cacert: readFileSync(path.join(httpsCertificateDirectory, "ca.pem")), + pfx: readFileSync(path.join(httpsCertificateDirectory, "server.pfx")), + key: readFileSync(path.join(httpsCertificateDirectory, "server.key")), + cert: readFileSync(path.join(httpsCertificateDirectory, "server.crt")), + passphrase: "webpack-dev-server", }, ], failure: [ - '', + "", { - foo: 'bar', + foo: "bar", }, { key: 10, @@ -229,83 +229,83 @@ const tests = { pfx: 10, }, { - requestCert: 'test', + requestCert: "test", }, ], }, ipc: { - success: [true, path.resolve(os.tmpdir(), 'webpack-dev-server.socket')], + success: [true, path.resolve(os.tmpdir(), "webpack-dev-server.socket")], failure: [false, {}], }, onListening: { success: [() => {}], - failure: [''], + failure: [""], }, open: { success: [ true, - 'foo', + "foo", [], - ['foo', 'bar'], - [{ app: 'google-chrome' }], - [{ app: 'google-chrome' }, { app: 'firefox' }], - [{ target: 'foo', app: 'google-chrome' }, { app: 'firefox' }], - [{ target: ['foo', 'bar'], app: 'google-chrome' }, { app: 'firefox' }], - { target: 'foo' }, - { target: ['foo', 'bar'] }, - { app: 'google-chrome' }, - { app: { name: 'google-chrome', arguments: ['--incognito'] } }, - { target: 'foo', app: 'google-chrome' }, - { - target: ['foo', 'bar'], - app: { name: 'google-chrome', arguments: ['--incognito'] }, + ["foo", "bar"], + [{ app: "google-chrome" }], + [{ app: "google-chrome" }, { app: "firefox" }], + [{ target: "foo", app: "google-chrome" }, { app: "firefox" }], + [{ target: ["foo", "bar"], app: "google-chrome" }, { app: "firefox" }], + { target: "foo" }, + { target: ["foo", "bar"] }, + { app: "google-chrome" }, + { app: { name: "google-chrome", arguments: ["--incognito"] } }, + { target: "foo", app: "google-chrome" }, + { + target: ["foo", "bar"], + app: { name: "google-chrome", arguments: ["--incognito"] }, }, {}, ], - failure: ['', { foo: 'bar' }, { target: 90 }, { app: true }], + failure: ["", { foo: "bar" }, { target: 90 }, { app: true }], }, port: { - success: ['20000', 20001, 'auto'], - failure: [false, null, ''], + success: ["20000", 20001, "auto"], + failure: [false, null, ""], }, proxy: { success: [ [ { - context: ['/auth', '/api'], - target: 'http://localhost:3000', + context: ["/auth", "/api"], + target: "http://localhost:3000", }, ], { - '/api': 'http://localhost:3000', + "/api": "http://localhost:3000", }, ], failure: [() => {}, false], }, static: { success: [ - 'path', + "path", false, { - directory: 'path', + directory: "path", staticOptions: {}, - publicPath: '/', + publicPath: "/", serveIndex: true, watch: true, }, { - directory: 'path', + directory: "path", staticOptions: {}, - publicPath: ['/public1/', '/public2/'], + publicPath: ["/public1/", "/public2/"], serveIndex: {}, watch: {}, }, [ - 'path1', + "path1", { - directory: 'path2', + directory: "path2", staticOptions: {}, - publicPath: '/', + publicPath: "/", serveIndex: true, watch: true, }, @@ -314,12 +314,12 @@ const tests = { failure: [ 0, null, - '', + "", { publicPath: false, }, { - serveIndex: 'true', + serveIndex: "true", }, { directory: false, @@ -332,23 +332,23 @@ const tests = { webSocketServer: { success: [ false, - 'ws', - 'sockjs', + "ws", + "sockjs", { - type: 'ws', + type: "ws", options: { - path: '/ws', + path: "/ws", }, }, { options: { - host: '127.0.0.1', + host: "127.0.0.1", port: 8090, - path: '/ws', + path: "/ws", }, }, { - type: 'ws', + type: "ws", }, ], failure: [ @@ -364,50 +364,50 @@ const tests = { }, watchFiles: { success: [ - 'dir', - ['one-dir', 'two-dir'], - { paths: ['dir'] }, - { paths: ['dir'], options: { usePolling: true } }, - [{ paths: ['one-dir'] }, 'two-dir'], + "dir", + ["one-dir", "two-dir"], + { paths: ["dir"] }, + { paths: ["dir"], options: { usePolling: true } }, + [{ paths: ["one-dir"] }, "two-dir"], ], failure: [false, 123], }, }; -describe('options', () => { +describe("options", () => { jest.setTimeout(20000); let consoleMock; beforeAll(() => { - consoleMock = jest.spyOn(console, 'warn').mockImplementation(); + consoleMock = jest.spyOn(console, "warn").mockImplementation(); }); afterAll(() => { consoleMock.mockRestore(); }); - describe('validate', () => { + describe("validate", () => { function stringifyValue(value) { if ( Array.isArray(value) || - (value && typeof value === 'object' && value.constructor === Object) + (value && typeof value === "object" && value.constructor === Object) ) { return JSON.stringify(value, (_key, replacedValue) => { if ( replacedValue && replacedValue.type && - replacedValue.type === 'Buffer' + replacedValue.type === "Buffer" ) { - return ''; + return ""; } - if (typeof replacedValue === 'string') { + if (typeof replacedValue === "string") { replacedValue = replacedValue - .replace(/\\/g, '/') + .replace(/\\/g, "/") .replace( - new RegExp(process.cwd().replace(/\\/g, '/'), 'g'), - '' + new RegExp(process.cwd().replace(/\\/g, "/"), "g"), + "" ); } @@ -420,7 +420,7 @@ describe('options', () => { function createTestCase(type, key, value) { it(`should ${ - type === 'success' ? 'successfully validate' : 'throw an error on' + type === "success" ? "successfully validate" : "throw an error on" } the "${key}" option with '${stringifyValue( value )}' value`, async () => { @@ -434,7 +434,7 @@ describe('options', () => { thrownError = error; } - if (type === 'success') { + if (type === "success") { expect(thrownError).toBeUndefined(); } else { expect(thrownError).not.toBeUndefined();