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

fix(server): don't ignore node_modules by default #1970

Merged
merged 1 commit into from Jun 5, 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
7 changes: 2 additions & 5 deletions lib/Server.js
Expand Up @@ -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 = `/${
Expand Down
80 changes: 13 additions & 67 deletions test/ContentBase.test.js
Expand Up @@ -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);
});
});

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.