From 21227e38524d84c84da048a70210c3c35f30261c Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Thu, 20 Jan 2022 19:32:31 +0530 Subject: [PATCH] test: migrate `watchFiles` test on `HTMLGeneratorPlugin` (#4207) * test: migrate `watchFiles` test on `HTMLGeneratorPlugin` * test: migrate `watchFiles` test on `HTMLGeneratorPlugin` * chore: refactor --- .gitignore | 1 + test/e2e/watch-files.test.js | 23 +++++++++++-------- test/fixtures/watch-files-config/foo.js | 3 +++ .../watch-files-config/other/foo.html | 1 + .../public/assets/example.txt | 0 .../public/assets/other.txt | 0 .../watch-files-config/public/bar/index.html | 1 + .../watch-files-config/public/other.html | 1 + .../watch-files-config/static/index.html | 1 + .../watch-files-config/webpack.config.js | 17 ++++++++++++++ 10 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 test/fixtures/watch-files-config/foo.js create mode 100644 test/fixtures/watch-files-config/other/foo.html create mode 100644 test/fixtures/watch-files-config/public/assets/example.txt create mode 100644 test/fixtures/watch-files-config/public/assets/other.txt create mode 100644 test/fixtures/watch-files-config/public/bar/index.html create mode 100644 test/fixtures/watch-files-config/public/other.html create mode 100644 test/fixtures/watch-files-config/static/index.html create mode 100644 test/fixtures/watch-files-config/webpack.config.js diff --git a/.gitignore b/.gitignore index 41247690e6..2245f4db71 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ yarn-error.log .eslintcache test/fixtures/static-config/public/assets/non-exist.txt +test/fixtures/watch-files-config/public/assets/non-exist.txt test/fixtures/reload-config/main.css test/fixtures/reload-config-2/main.css !/test/fixtures/static-config/public/node_modules diff --git a/test/e2e/watch-files.test.js b/test/e2e/watch-files.test.js index 8031a3a963..ff58b1fbbb 100644 --- a/test/e2e/watch-files.test.js +++ b/test/e2e/watch-files.test.js @@ -5,11 +5,14 @@ const chokidar = require("chokidar"); const fs = require("graceful-fs"); const webpack = require("webpack"); const Server = require("../../lib/Server"); -const config = require("../fixtures/static-config/webpack.config"); +const config = require("../fixtures/watch-files-config/webpack.config"); const runBrowser = require("../helpers/run-browser"); const port = require("../ports-map")["watch-files-option"]; -const watchDir = path.resolve(__dirname, "../fixtures/static-config/public"); +const watchDir = path.resolve( + __dirname, + "../fixtures/watch-files-config/public" +); describe("watchFiles option", () => { describe("should work with string and path to file", () => { @@ -55,7 +58,7 @@ describe("watchFiles option", () => { pageErrors.push(error); }); - const response = await page.goto(`http://127.0.0.1:${port}/main`, { + const response = await page.goto(`http://127.0.0.1:${port}/`, { waitUntil: "networkidle0", }); @@ -126,7 +129,7 @@ describe("watchFiles option", () => { pageErrors.push(error); }); - const response = await page.goto(`http://127.0.0.1:${port}/main`, { + const response = await page.goto(`http://127.0.0.1:${port}/`, { waitUntil: "networkidle0", }); @@ -197,7 +200,7 @@ describe("watchFiles option", () => { pageErrors.push(error); }); - const response = await page.goto(`http://127.0.0.1:${port}/main`, { + const response = await page.goto(`http://127.0.0.1:${port}/`, { waitUntil: "networkidle0", }); @@ -273,7 +276,7 @@ describe("watchFiles option", () => { pageErrors.push(error); }); - const response = await page.goto(`http://127.0.0.1:${port}/main`, { + const response = await page.goto(`http://127.0.0.1:${port}/`, { waitUntil: "networkidle0", }); @@ -349,7 +352,7 @@ describe("watchFiles option", () => { pageErrors.push(error); }); - const response = await page.goto(`http://127.0.0.1:${port}/main`, { + const response = await page.goto(`http://127.0.0.1:${port}/`, { waitUntil: "networkidle0", }); @@ -422,7 +425,7 @@ describe("watchFiles option", () => { pageErrors.push(error); }); - const response = await page.goto(`http://127.0.0.1:${port}/main`, { + const response = await page.goto(`http://127.0.0.1:${port}/`, { waitUntil: "networkidle0", }); @@ -503,7 +506,7 @@ describe("watchFiles option", () => { pageErrors.push(error); }); - const response = await page.goto(`http://127.0.0.1:${port}/main`, { + const response = await page.goto(`http://127.0.0.1:${port}/`, { waitUntil: "networkidle0", }); @@ -644,7 +647,7 @@ describe("watchFiles option", () => { pageErrors.push(error); }); - const response = await page.goto(`http://127.0.0.1:${port}/main`, { + const response = await page.goto(`http://127.0.0.1:${port}/`, { waitUntil: "networkidle0", }); diff --git a/test/fixtures/watch-files-config/foo.js b/test/fixtures/watch-files-config/foo.js new file mode 100644 index 0000000000..3c915dbcb8 --- /dev/null +++ b/test/fixtures/watch-files-config/foo.js @@ -0,0 +1,3 @@ +"use strict"; + +console.log("Hey."); diff --git a/test/fixtures/watch-files-config/other/foo.html b/test/fixtures/watch-files-config/other/foo.html new file mode 100644 index 0000000000..c57ed97e22 --- /dev/null +++ b/test/fixtures/watch-files-config/other/foo.html @@ -0,0 +1 @@ +Foo! diff --git a/test/fixtures/watch-files-config/public/assets/example.txt b/test/fixtures/watch-files-config/public/assets/example.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/watch-files-config/public/assets/other.txt b/test/fixtures/watch-files-config/public/assets/other.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/watch-files-config/public/bar/index.html b/test/fixtures/watch-files-config/public/bar/index.html new file mode 100644 index 0000000000..17654db5a1 --- /dev/null +++ b/test/fixtures/watch-files-config/public/bar/index.html @@ -0,0 +1 @@ +Heyo diff --git a/test/fixtures/watch-files-config/public/other.html b/test/fixtures/watch-files-config/public/other.html new file mode 100644 index 0000000000..6b31da1a64 --- /dev/null +++ b/test/fixtures/watch-files-config/public/other.html @@ -0,0 +1 @@ +Other html diff --git a/test/fixtures/watch-files-config/static/index.html b/test/fixtures/watch-files-config/static/index.html new file mode 100644 index 0000000000..20f073ee9d --- /dev/null +++ b/test/fixtures/watch-files-config/static/index.html @@ -0,0 +1 @@ +Heyo. diff --git a/test/fixtures/watch-files-config/webpack.config.js b/test/fixtures/watch-files-config/webpack.config.js new file mode 100644 index 0000000000..c31d06071d --- /dev/null +++ b/test/fixtures/watch-files-config/webpack.config.js @@ -0,0 +1,17 @@ +"use strict"; + +const HTMLGeneratorPlugin = require("../../helpers/html-generator-plugin"); + +module.exports = { + mode: "development", + context: __dirname, + stats: "none", + entry: "./foo.js", + output: { + publicPath: "/", + }, + infrastructureLogging: { + level: "warn", + }, + plugins: [new HTMLGeneratorPlugin()], +};