Skip to content

Commit 699f8b4

Browse files
authored
fix(server): don't ignore node_modules by default (#1970)
revert #1794
1 parent 53f4253 commit 699f8b4

File tree

3 files changed

+16
-72
lines changed

3 files changed

+16
-72
lines changed

lib/Server.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,8 @@ class Server {
105105
if (!this.options.watchOptions) {
106106
this.options.watchOptions = {};
107107
}
108-
// Ignoring node_modules folder by default
109-
this.options.watchOptions.ignored = this.options.watchOptions.ignored || [
110-
/node_modules/,
111-
];
112-
this.watchOptions = this.options.watchOptions;
108+
109+
this.watchOptions = options.watchOptions || {};
113110

114111
// Replace leading and trailing slashes to normalize path
115112
this.sockPath = `/${

test/ContentBase.test.js

+13-67
Original file line numberDiff line numberDiff line change
@@ -61,75 +61,21 @@ describe('ContentBase', () => {
6161
fs.writeFileSync(nestedFile, 'Heyo', 'utf8');
6262
}, 1000);
6363
});
64-
});
65-
66-
describe('test ignoring node_modules folder by Default', () => {
67-
beforeAll((done) => {
68-
server = testServer.start(config, {
69-
contentBase: contentBasePublic,
70-
watchContentBase: true,
71-
});
72-
// making sure that chokidar has read all the files
73-
server.contentBaseWatchers[0].on('ready', () => {
74-
done();
75-
});
76-
req = request(server.app);
77-
});
7864

79-
afterAll((done) => {
80-
testServer.close(() => {
81-
done();
82-
});
83-
});
84-
85-
it('Should ignore node_modules & watch bar', (done) => {
86-
const watchedPaths = server.contentBaseWatchers[0].getWatched();
87-
// check if node_modules folder is not in watched list
88-
const folderWatched = !!watchedPaths[
89-
path.join(contentBasePublic, 'node_modules')
90-
];
91-
expect(folderWatched).toEqual(false);
92-
// check if bar folder is in watched list
93-
expect(watchedPaths[path.join(contentBasePublic, 'bar')]).toEqual([
94-
'index.html',
95-
]);
96-
97-
done();
98-
});
99-
});
100-
101-
describe('test not ignoring node_modules folder', () => {
102-
beforeAll((done) => {
103-
server = testServer.start(config, {
104-
contentBase: contentBasePublic,
105-
watchContentBase: true,
106-
watchOptions: {
107-
ignored: /bar/,
108-
},
109-
});
110-
// making sure that chokidar has read all the files
111-
server.contentBaseWatchers[0].on('ready', () => {
112-
done();
113-
});
114-
req = request(server.app);
115-
});
116-
117-
afterAll((done) => {
118-
testServer.close(() => {
119-
done();
120-
});
121-
});
65+
it('watch node_modules', (done) => {
66+
const filePath = path.join(
67+
contentBasePublic,
68+
'node_modules',
69+
'index.html'
70+
);
71+
// chokidar emitted a change,
72+
// meaning it watched the file correctly
73+
server.contentBaseWatchers[0].on('change', () => done());
12274

123-
it('Should watch node_modules & ignore bar', (done) => {
124-
const watchedPaths = server.contentBaseWatchers[0].getWatched();
125-
// check if node_modules folder is in watched list
126-
expect(
127-
watchedPaths[path.join(contentBasePublic, 'node_modules')]
128-
).toEqual(['index.html']);
129-
// check if bar folder is not in watched list
130-
const folderWatched = !!watchedPaths[path.join(contentBasePublic, 'bar')];
131-
expect(folderWatched).toEqual(false);
132-
done();
75+
// change a file manually
76+
setTimeout(() => {
77+
fs.writeFileSync(filePath, `${Math.random()}`, 'utf8');
78+
}, 1000);
13379
});
13480
});
13581

test/fixtures/contentbase-config/public/node_modules/index.html

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)