From 699f8b424eefe0137b8e8493f76735a4fa3135b9 Mon Sep 17 00:00:00 2001 From: Yuta Hiroto Date: Wed, 5 Jun 2019 15:27:53 +0200 Subject: [PATCH] fix(server): don't ignore node_modules by default (#1970) revert #1794 --- lib/Server.js | 7 +- test/ContentBase.test.js | 80 +++---------------- .../public/node_modules/index.html | 1 + 3 files changed, 16 insertions(+), 72 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index 5425f7be31..e086fa7956 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -105,11 +105,8 @@ class Server { if (!this.options.watchOptions) { this.options.watchOptions = {}; } - // Ignoring node_modules folder by default - this.options.watchOptions.ignored = this.options.watchOptions.ignored || [ - /node_modules/, - ]; - this.watchOptions = this.options.watchOptions; + + this.watchOptions = options.watchOptions || {}; // Replace leading and trailing slashes to normalize path this.sockPath = `/${ diff --git a/test/ContentBase.test.js b/test/ContentBase.test.js index b908657a87..647add5190 100644 --- a/test/ContentBase.test.js +++ b/test/ContentBase.test.js @@ -61,75 +61,21 @@ describe('ContentBase', () => { fs.writeFileSync(nestedFile, 'Heyo', 'utf8'); }, 1000); }); - }); - - describe('test ignoring node_modules folder by Default', () => { - beforeAll((done) => { - server = testServer.start(config, { - contentBase: contentBasePublic, - watchContentBase: true, - }); - // making sure that chokidar has read all the files - server.contentBaseWatchers[0].on('ready', () => { - done(); - }); - req = request(server.app); - }); - afterAll((done) => { - testServer.close(() => { - done(); - }); - }); - - it('Should ignore node_modules & watch bar', (done) => { - const watchedPaths = server.contentBaseWatchers[0].getWatched(); - // check if node_modules folder is not in watched list - const folderWatched = !!watchedPaths[ - path.join(contentBasePublic, 'node_modules') - ]; - expect(folderWatched).toEqual(false); - // check if bar folder is in watched list - expect(watchedPaths[path.join(contentBasePublic, 'bar')]).toEqual([ - 'index.html', - ]); - - done(); - }); - }); - - describe('test not ignoring node_modules folder', () => { - beforeAll((done) => { - server = testServer.start(config, { - contentBase: contentBasePublic, - watchContentBase: true, - watchOptions: { - ignored: /bar/, - }, - }); - // making sure that chokidar has read all the files - server.contentBaseWatchers[0].on('ready', () => { - done(); - }); - req = request(server.app); - }); - - afterAll((done) => { - testServer.close(() => { - done(); - }); - }); + it('watch node_modules', (done) => { + const filePath = path.join( + contentBasePublic, + 'node_modules', + 'index.html' + ); + // chokidar emitted a change, + // meaning it watched the file correctly + server.contentBaseWatchers[0].on('change', () => done()); - it('Should watch node_modules & ignore bar', (done) => { - const watchedPaths = server.contentBaseWatchers[0].getWatched(); - // check if node_modules folder is in watched list - expect( - watchedPaths[path.join(contentBasePublic, 'node_modules')] - ).toEqual(['index.html']); - // check if bar folder is not in watched list - const folderWatched = !!watchedPaths[path.join(contentBasePublic, 'bar')]; - expect(folderWatched).toEqual(false); - done(); + // change a file manually + setTimeout(() => { + fs.writeFileSync(filePath, `${Math.random()}`, 'utf8'); + }, 1000); }); }); diff --git a/test/fixtures/contentbase-config/public/node_modules/index.html b/test/fixtures/contentbase-config/public/node_modules/index.html index e69de29bb2..d4a679602e 100644 --- a/test/fixtures/contentbase-config/public/node_modules/index.html +++ b/test/fixtures/contentbase-config/public/node_modules/index.html @@ -0,0 +1 @@ +0.240478319203405 \ No newline at end of file