diff --git a/.gitignore b/.gitignore index 05104ca..a524d1e 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ wps-hmr.* coverage.lcov dist + +*.pem +*.key diff --git a/README.md b/README.md index 92ab05a..e4351a3 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ If `true`, will enable [`Hot Module Replacement`](https://webpack.js.org/concept _Note: If the build process generates errors, the client (browser) will not be notified of new changes and no HMR will be performed. Errors must be resolved before HMR can proceed. To force a refresh, pass `refresh-on-failure' to this option._ -_Note: If using in combination with `http2`, the `http2` option `allowHTTP1` must be enabled for the HMR WS connection to work._ +_Note: If using in combination with `http2`, the `http2` option `allowHTTP1` will be enabled by default for the HMR WS connection to work._ ### `host` Type: `String | Promise`
@@ -151,9 +151,9 @@ _Note: The default URI is `http://[::]:{port}`. For more info, please read [the ### `http2` Type: `boolean` | [`http2` options](https://nodejs.org/api/http2.html#http2_http2_createserver_options_onrequesthandler) | [secure `http2` options](https://nodejs.org/api/http2.html#http2_http2_createsecureserver_options_onrequesthandler) -If set, this option will instruct the server to enable HTTP2. Properties for this option should correspond to [HTTP2 options][http2] or [HTTP2 SSL options][http2tls]. +If set, this option will instruct the server to enable HTTP2. Properties for this option should correspond to [HTTP2 options][http2] or [HTTP2 SSL options][http2tls]. Browsers currently do not support unencrypted HTTP2 connections, so you will need to enable SSL for this to work properly. -_Note: If using in combination with `hmr`, the option `allowHTTP1` must be enabled for the HMR WS connection to work._ +_Note: If using in combination with `hmr`, the option `allowHTTP1` will be enabled by default for the HMR WS connection to work._ ### `https` Type: `Object`
diff --git a/lib/server.js b/lib/server.js index 1905713..97220c7 100644 --- a/lib/server.js +++ b/lib/server.js @@ -24,18 +24,19 @@ const select = (options, callback) => { http2: require('http2').createServer, http2Secure: require('http2').createSecureServer }; - const { http2, https } = options; + const { http2, https, hmr } = options; let server; let secure = false; if (http2) { + const defaultOptions = hmr === true ? { allowHTTP1: true } : {}; if (http2 === true) { - server = types.http2({}, callback); + server = types.http2(defaultOptions, callback); } else if (http2.cert) { secure = true; - server = types.http2Secure(http2, callback); + server = types.http2Secure({ ...defaultOptions, ...http2 }, callback); } else { - server = types.http2(http2, callback); + server = types.http2({ ...defaultOptions, ...http2 }, callback); } } else if (https) { secure = true; diff --git a/package-lock.json b/package-lock.json index b64e9c8..d2c3866 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1723,6 +1723,15 @@ "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", "dev": true }, + "asn1": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", + "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==", + "dev": true, + "requires": { + "safer-buffer": "~2.1.0" + } + }, "asn1.js": { "version": "5.4.1", "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-5.4.1.tgz", @@ -1770,6 +1779,12 @@ } } }, + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", + "dev": true + }, "assign-symbols": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/assign-symbols/-/assign-symbols-1.0.0.tgz", @@ -2483,6 +2498,15 @@ "integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw==", "dev": true }, + "bcrypt-pbkdf": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", + "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", + "dev": true, + "requires": { + "tweetnacl": "^0.14.3" + } + }, "big.js": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", @@ -3055,6 +3079,29 @@ "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==", "dev": true }, + "child-process-promise": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/child-process-promise/-/child-process-promise-2.2.1.tgz", + "integrity": "sha1-RzChHvYQ+tRQuPIjx50x172tgHQ=", + "dev": true, + "requires": { + "cross-spawn": "^4.0.2", + "node-version": "^1.0.0", + "promise-polyfill": "^6.0.1" + }, + "dependencies": { + "cross-spawn": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-4.0.2.tgz", + "integrity": "sha1-e5JHYhwjrf3ThWAEqCPL45dCTUE=", + "dev": true, + "requires": { + "lru-cache": "^4.0.1", + "which": "^1.2.9" + } + } + } + }, "chokidar": { "version": "3.4.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.4.3.tgz", @@ -3412,6 +3459,12 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, + "command-exists": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz", + "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==", + "dev": true + }, "commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", @@ -4076,6 +4129,15 @@ "integrity": "sha512-2iy1EkLdlBzQGvbweYRFxmFath8+K7+AKB0TlhHWkNuH+TmovaMH/Wp7V7R4u7f4SnX3OgLsU9t1NI9ioDnUpg==", "dev": true }, + "dashdash": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", + "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", + "dev": true, + "requires": { + "assert-plus": "^1.0.0" + } + }, "date-time": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/date-time/-/date-time-2.1.0.tgz", @@ -4680,6 +4742,16 @@ "stream-shift": "^1.0.0" } }, + "ecc-jsbn": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", + "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", + "dev": true, + "requires": { + "jsbn": "~0.1.0", + "safer-buffer": "^2.1.0" + } + }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -6010,6 +6082,15 @@ "integrity": "sha1-3BXKHGcjh8p2vTesCjlbogQqLCg=", "dev": true }, + "getpass": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", + "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", + "dev": true, + "requires": { + "assert-plus": "^1.0.0" + } + }, "git-raw-commits": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/git-raw-commits/-/git-raw-commits-2.0.7.tgz", @@ -7657,6 +7738,12 @@ "esprima": "^4.0.0" } }, + "jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", + "dev": true + }, "jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", @@ -9142,6 +9229,29 @@ } } }, + "node-powershell": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/node-powershell/-/node-powershell-3.3.1.tgz", + "integrity": "sha1-u/drKfCR7YPq4WrZ56GAoT820RM=", + "dev": true, + "requires": { + "bluebird": "^3.5.1", + "chalk": "^2.1.0" + }, + "dependencies": { + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + } + } + }, "node-preload": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/node-preload/-/node-preload-0.2.1.tgz", @@ -9151,6 +9261,12 @@ "process-on-spawn": "^1.0.0" } }, + "node-version": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/node-version/-/node-version-1.2.0.tgz", + "integrity": "sha512-ma6oU4Sk0qOoKEAymVoTvk8EdXEobdS7m/mAGhDJ8Rouugho48crHBORAmy5BoOcv8wraPM6xumapQp5hl4iIQ==", + "dev": true + }, "normalize-package-data": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", @@ -9511,6 +9627,12 @@ } } }, + "openssl.exe": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/openssl.exe/-/openssl.exe-0.0.2.tgz", + "integrity": "sha512-8d6bpC7XaplFujm4K2H1ATbGeiHgdVjFEk14ZIgZE0vz1z7jLOHzzorcfuNTFJRDqRe4tbj0lJAsGiJQ1I3fEA==", + "dev": true + }, "optionator": { "version": "0.8.3", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz", @@ -9573,6 +9695,12 @@ "integrity": "sha1-hUNzx/XCMVkU/Jv8a9gjj92h7Cc=", "dev": true }, + "os-homedir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", + "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", + "dev": true + }, "os-shim": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/os-shim/-/os-shim-0.1.3.tgz", @@ -10136,6 +10264,12 @@ "integrity": "sha1-mEcocL8igTL8vdhoEputEsPAKeM=", "dev": true }, + "promise-polyfill": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-6.1.0.tgz", + "integrity": "sha1-36lpQ+qcEh/KTem1hoyznTRy4Fc=", + "dev": true + }, "proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", @@ -10939,6 +11073,12 @@ "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", "dev": true }, + "shell-escape": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/shell-escape/-/shell-escape-0.2.0.tgz", + "integrity": "sha1-aP0CXrBJC09WegJ/C/IkgLX4QTM=", + "dev": true + }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", @@ -11222,6 +11362,23 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, + "sshpk": { + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", + "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==", + "dev": true, + "requires": { + "asn1": "~0.2.3", + "assert-plus": "^1.0.0", + "bcrypt-pbkdf": "^1.0.0", + "dashdash": "^1.12.0", + "ecc-jsbn": "~0.1.1", + "getpass": "^0.1.1", + "jsbn": "~0.1.0", + "safer-buffer": "^2.0.2", + "tweetnacl": "~0.14.0" + } + }, "ssri": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz", @@ -11534,6 +11691,43 @@ } } }, + "temp-dir": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-1.0.0.tgz", + "integrity": "sha1-CnwOom06Oa+n4OvqnB/AvE2qAR0=", + "dev": true + }, + "temp-write": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/temp-write/-/temp-write-3.4.0.tgz", + "integrity": "sha1-jP9jD7fp2gXwR8dM5M5NaFRX1JI=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "is-stream": "^1.1.0", + "make-dir": "^1.0.0", + "pify": "^3.0.0", + "temp-dir": "^1.0.0", + "uuid": "^3.0.1" + }, + "dependencies": { + "make-dir": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz", + "integrity": "sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ==", + "dev": true, + "requires": { + "pify": "^3.0.0" + } + }, + "pify": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", + "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=", + "dev": true + } + } + }, "term-size": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/term-size/-/term-size-1.2.0.tgz", @@ -11674,6 +11868,39 @@ "setimmediate": "^1.0.4" } }, + "tls-keygen": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/tls-keygen/-/tls-keygen-3.7.0.tgz", + "integrity": "sha512-yMHaz/oMw9rkTGojlCJvhBVYiKTcvjvyLTpKSJGFoUryrf5GXwRrwk+tPJsWR6pl7NXE7TM+nVqWc6sBt2WLGA==", + "dev": true, + "requires": { + "chalk": "^2.4.1", + "child-process-promise": "^2.2.1", + "command-exists": "^1.2.7", + "minimist": "^1.2.0", + "mkdirp": "^0.5.1", + "node-powershell": "^3.3.1", + "openssl.exe": "^0.0.2", + "shell-escape": "^0.2.0", + "sshpk": "^1.14.2", + "temp-write": "^3.4.0", + "tmp-promise": "^1.0.4", + "user-home": "^2.0.0" + }, + "dependencies": { + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + } + } + }, "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", @@ -11683,6 +11910,36 @@ "os-tmpdir": "~1.0.2" } }, + "tmp-promise": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/tmp-promise/-/tmp-promise-1.1.0.tgz", + "integrity": "sha512-8+Ah9aB1IRXCnIOxXZ0uFozV1nMU5xiu7hhFVUSxZ3bYu+psD4TzagCzVbexUCgNNGJnsmNDQlS4nG3mTyoNkw==", + "dev": true, + "requires": { + "bluebird": "^3.5.0", + "tmp": "0.1.0" + }, + "dependencies": { + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, + "tmp": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.1.0.tgz", + "integrity": "sha512-J7Z2K08jbGcdA1kkQpJSqLF6T0tdQqpR2pnSUXsIchbPdTI9v3e85cLW0d6WDhwuAleOV71j2xWs8qMPfK7nKw==", + "dev": true, + "requires": { + "rimraf": "^2.6.3" + } + } + } + }, "to-arraybuffer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz", @@ -11778,6 +12035,12 @@ "integrity": "sha1-oVe6QC2iTpv5V/mqadUk7tQpAaY=", "dev": true }, + "tweetnacl": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", + "dev": true + }, "type-check": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", @@ -12063,6 +12326,15 @@ "integrity": "sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==", "dev": true }, + "user-home": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/user-home/-/user-home-2.0.0.tgz", + "integrity": "sha1-nHC/2Babwdy/SGBODwS4tJzenp8=", + "dev": true, + "requires": { + "os-homedir": "^1.0.0" + } + }, "util": { "version": "0.11.1", "resolved": "https://registry.npmjs.org/util/-/util-0.11.1.tgz", diff --git a/package.json b/package.json index b15a5b0..944e8b3 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,9 @@ "commitlint": "commitlint", "commitmsg": "commitlint -e $GIT_PARAMS", "dev": "npm run dev:clean && node node_modules/webpack-nano/bin/wp --config test/fixtures/simple/webpack.config.js", - "dev:clean": "del test/fixtures/multi/output/* test/fixtures/simple/output/*", + "dev:clean": "del test/fixtures/multi/output/* test/fixtures/simple/output/* test/fixtures/http2/output/*", "dev:multi": "npm run dev:clean && node node_modules/webpack-nano/bin/wp --config test/fixtures/multi/webpack.config.js", + "dev:http2": "npm run dev:clean && node node_modules/webpack-nano/bin/wp --config test/fixtures/http2/webpack.config.js", "faq:toc": "echo 'temporarily disabled' # markdown-toc -i .github/FAQ.md", "lint": "eslint --fix --cache lib test", "lint-staged": "lint-staged", @@ -77,6 +78,7 @@ "nyc": "^15.0.1", "pre-commit": "^1.2.2", "puppeteer": "^3.0.2", + "tls-keygen": "^3.7.0", "react-refresh": "^0.8.3", "webpack": "^4.44.2", "webpack-nano": "^1.0.0" diff --git a/test/fixtures/http2/app.js b/test/fixtures/http2/app.js new file mode 100644 index 0000000..4bf1ff7 --- /dev/null +++ b/test/fixtures/http2/app.js @@ -0,0 +1,19 @@ +require('./component'); + +if (module.hot) { + module.hot.accept((err) => { + if (err) { + console.error('HMR', err); + } + }); +} + +// uncomment to produce a build error +// if (!window) { +// require('tests'); +// } + +// uncomment to produce a build warning +// console.log(require); + +// console.log(require); diff --git a/test/fixtures/http2/component.js b/test/fixtures/http2/component.js new file mode 100644 index 0000000..9262226 --- /dev/null +++ b/test/fixtures/http2/component.js @@ -0,0 +1,2 @@ +const main = document.querySelector('main'); +main.innerHTML = 'main'; diff --git a/test/fixtures/http2/index.html b/test/fixtures/http2/index.html new file mode 100644 index 0000000..d77d6d3 --- /dev/null +++ b/test/fixtures/http2/index.html @@ -0,0 +1,10 @@ + + + + fixture: http2 - hmr + + +
+ + + diff --git a/test/fixtures/http2/webpack.config.js b/test/fixtures/http2/webpack.config.js new file mode 100644 index 0000000..34e4259 --- /dev/null +++ b/test/fixtures/http2/webpack.config.js @@ -0,0 +1,34 @@ +const { resolve } = require('path'); + +const { ephemeral } = require('tls-keygen'); + +const getPort = require('get-port'); + +const { WebpackPluginServe: Serve } = require('../../../lib/'); + +module.exports = async () => { + const { cert, key } = await ephemeral({ entrust: false }); + return { + context: __dirname, + entry: ['./app.js', 'webpack-plugin-serve/client'], + mode: 'development', + output: { + filename: './output.js', + path: resolve(__dirname, './output'), + publicPath: 'output/' + }, + plugins: [ + new Serve({ + host: 'localhost', + port: getPort({ port: 55555 }), + http2: { cert, key } + }) + ], + resolve: { + alias: { + 'webpack-plugin-serve/client': resolve(__dirname, '../../../client') + } + }, + watch: true + }; +}; diff --git a/test/helpers/puppeteer.js b/test/helpers/puppeteer.js index 0780195..a0d266f 100644 --- a/test/helpers/puppeteer.js +++ b/test/helpers/puppeteer.js @@ -54,7 +54,11 @@ const waitForBuild = (stderr) => { }; const browser = async (t, run) => { - const instance = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] }); + const instance = await puppeteer.launch({ + args: ['--no-sandbox', '--disable-setuid-sandbox', '--ignore-certificate-errors'], + acceptInsecureCerts: true, + ignoreHTTPSErrors: true + }); const page = await instance.newPage(); const util = { getPort, diff --git a/test/integration/http2-hmr.test.js b/test/integration/http2-hmr.test.js new file mode 100644 index 0000000..00e4607 --- /dev/null +++ b/test/integration/http2-hmr.test.js @@ -0,0 +1,34 @@ +const { join } = require('path'); + +const test = require('ava'); +const del = require('del'); +const execa = require('execa'); + +const { browser } = require('../helpers/puppeteer'); + +test('http2 with hmr - single compiler', browser, async (t, page, util) => { + const { getPort, replace, setup, waitForBuild } = util; + const fixturePath = await setup('http2', 'http2-hmr'); + const proc = execa('wp', [], { cwd: fixturePath }); + const { stdout, stderr } = proc; + const port = await getPort(stdout); + const url = `https://localhost:${port}`; + + await waitForBuild(stderr); + await page.goto(url, { + waitUntil: 'networkidle0' + }); + + const componentPath = join(fixturePath, 'component.js'); + const content = `const main = document.querySelector('main'); main.innerHTML = 'test';`; + + await replace(componentPath, content); + + const value = await page.evaluate(() => document.querySelector('main').innerHTML); + + proc.kill('SIGTERM'); + + t.is(value, 'test'); + + await del(fixturePath); +}); diff --git a/test/snapshots/plugin.test.js.md b/test/snapshots/plugin.test.js.md index 2855290..03bcc30 100644 --- a/test/snapshots/plugin.test.js.md +++ b/test/snapshots/plugin.test.js.md @@ -113,6 +113,7 @@ Generated by [AVA](https://ava.li). > Snapshot 1 [ + 'test/fixtures/http2', 'test/fixtures/multi', 'test/fixtures/proxy', 'test/fixtures/ramdisk', diff --git a/test/snapshots/plugin.test.js.snap b/test/snapshots/plugin.test.js.snap index 30f6643..961d6d1 100644 Binary files a/test/snapshots/plugin.test.js.snap and b/test/snapshots/plugin.test.js.snap differ