Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exclude /node_modules/ from _watch by default #1794

Merged
merged 4 commits into from Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/Server.js
Expand Up @@ -115,7 +115,15 @@ class Server {

this.sockets = [];

this.watchOptions = options.watchOptions || {};
if (!options.watchOptions) {
options.watchOptions = {};
}
// ignoring node_modules folder by default
options.watchOptions.ignored = options.watchOptions.ignored || [
/node_modules/,
];
this.watchOptions = options.watchOptions;

this.contentBaseWatchers = [];
// Replace leading and trailing slashes to normalize path
this.sockPath = `/${
Expand Down
75 changes: 75 additions & 0 deletions test/ContentBase.test.js
Expand Up @@ -64,6 +64,81 @@ describe('ContentBase', () => {
}, 1000);
});
});

describe('test ignoring node_modules folder by Default', () => {
jest.setTimeout(30000);

beforeAll((done) => {
server = helper.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) => {
helper.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', () => {
jest.setTimeout(30000);

beforeAll((done) => {
server = helper.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) => {
helper.close(() => {
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();
});
});

describe('test listing files in folders without index.html using the option serveIndex:false', () => {
beforeAll((done) => {
server = helper.start(
Expand Down
Empty file.