From 57c8c928335cb34af4550ad5b14b4014bd087e11 Mon Sep 17 00:00:00 2001 From: Yuta Hiroto Date: Wed, 5 Jun 2019 18:35:59 +0200 Subject: [PATCH] fix(server): Change clientLogLevel order to be called first (#1973) * fix(server): change clientLogLevel order to be called first * test: fix contentbase tests --- .gitignore | 1 + lib/Server.js | 9 +++++---- test/ContentBase.test.js | 9 +++++++-- test/e2e/ClientOptions.test.js | 6 ++++++ test/e2e/__snapshots__/ClientOptions.test.js.snap | 6 ++++++ .../contentbase-config/public/node_modules/.gitkeep | 0 .../contentbase-config/public/node_modules/index.html | 1 - 7 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 test/fixtures/contentbase-config/public/node_modules/.gitkeep delete mode 100644 test/fixtures/contentbase-config/public/node_modules/index.html diff --git a/.gitignore b/.gitignore index 8d7d3b7e81..bb37acce5b 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ node_modules .eslintcache test/fixtures/reload-config/main.css +!/test/fixtures/contentbase-config/public/node_modules diff --git a/lib/Server.js b/lib/Server.js index e086fa7956..1c58eaea43 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -694,10 +694,15 @@ class Server { } }); + if (this.clientLogLevel) { + this.sockWrite([connection], 'log-level', this.clientLogLevel); + } + if (this.hot) { this.sockWrite([connection], 'hot'); } + // TODO: change condition at major version if (this.options.liveReload !== false) { this.sockWrite([connection], 'liveReload', this.options.liveReload); } @@ -710,10 +715,6 @@ class Server { this.sockWrite([connection], 'overlay', this.clientOverlay); } - if (this.clientLogLevel) { - this.sockWrite([connection], 'log-level', this.clientLogLevel); - } - if (!this._stats) { return; } diff --git a/test/ContentBase.test.js b/test/ContentBase.test.js index 647add5190..24311dc396 100644 --- a/test/ContentBase.test.js +++ b/test/ContentBase.test.js @@ -68,13 +68,18 @@ describe('ContentBase', () => { 'node_modules', 'index.html' ); + fs.writeFileSync(filePath, 'foo', 'utf8'); + // chokidar emitted a change, // meaning it watched the file correctly - server.contentBaseWatchers[0].on('change', () => done()); + server.contentBaseWatchers[0].on('change', () => { + fs.unlinkSync(filePath); + done(); + }); // change a file manually setTimeout(() => { - fs.writeFileSync(filePath, `${Math.random()}`, 'utf8'); + fs.writeFileSync(filePath, 'bar', 'utf8'); }, 1000); }); }); diff --git a/test/e2e/ClientOptions.test.js b/test/e2e/ClientOptions.test.js index 11fb7f1ff8..2e643c516f 100644 --- a/test/e2e/ClientOptions.test.js +++ b/test/e2e/ClientOptions.test.js @@ -250,6 +250,12 @@ describe('Client console.log', () => { liveReload: true, }, }, + { + title: 'clientLogLevel is silent', + options: { + clientLogLevel: 'silent', + }, + }, ]; for (const { title, options } of cases) { diff --git a/test/e2e/__snapshots__/ClientOptions.test.js.snap b/test/e2e/__snapshots__/ClientOptions.test.js.snap index 92ec069c30..e8778380ae 100644 --- a/test/e2e/__snapshots__/ClientOptions.test.js.snap +++ b/test/e2e/__snapshots__/ClientOptions.test.js.snap @@ -1,5 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Client console.log clientLogLevel is silent 1`] = ` +Array [ + "Hey.", +] +`; + exports[`Client console.log hot disabled 1`] = ` Array [ "Hey.", diff --git a/test/fixtures/contentbase-config/public/node_modules/.gitkeep b/test/fixtures/contentbase-config/public/node_modules/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/contentbase-config/public/node_modules/index.html b/test/fixtures/contentbase-config/public/node_modules/index.html deleted file mode 100644 index d4a679602e..0000000000 --- a/test/fixtures/contentbase-config/public/node_modules/index.html +++ /dev/null @@ -1 +0,0 @@ -0.240478319203405 \ No newline at end of file