Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,9 +973,12 @@ class Server {
// https://github.com/webpack/watchpack/blob/master/lib/DirectoryWatcher.js#L49
// this isn't an elegant solution, but we'll improve it in the future
// eslint-disable-next-line no-undefined
const usePolling = watchOptions.poll ? true : undefined;
const usePolling = watchOptions.usePolling || Boolean(watchOptions.poll);
const interval =
typeof watchOptions.poll === 'number'
// eslint-disable-next-line no-nested-ternary
typeof watchOptions.interval !== 'undefined'
? watchOptions.interval
: typeof watchOptions.poll === 'number'
? watchOptions.poll
: // eslint-disable-next-line no-undefined
undefined;
Expand Down
19 changes: 19 additions & 0 deletions test/server/watchFiles-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const path = require('path');
const fs = require('graceful-fs');
const chokidar = require('chokidar');
const testServer = require('../helpers/test-server');
const config = require('../fixtures/contentbase-config/webpack.config');
const port = require('../ports-map')['watchFiles-option'];
Expand Down Expand Up @@ -277,6 +278,8 @@ describe("'watchFiles' option", () => {
describe('should work with options', () => {
const file = path.join(watchDir, 'assets/example.txt');

const chokidarMock = jest.spyOn(chokidar, 'watch');

beforeAll((done) => {
server = testServer.start(
config,
Expand All @@ -285,6 +288,7 @@ describe("'watchFiles' option", () => {
paths: file,
options: {
usePolling: true,
interval: 400,
},
},
port,
Expand All @@ -298,6 +302,21 @@ describe("'watchFiles' option", () => {
fs.truncateSync(file);
});

it('should pass correct options to chokidar config', () => {
expect(chokidarMock).toHaveBeenCalledWith(file, {
ignoreInitial: true,
persistent: true,
followSymlinks: false,
atomic: false,
alwaysStat: true,
ignorePermissionErrors: true,
// eslint-disable-next-line no-undefined
ignored: undefined,
usePolling: true,
interval: 400,
});
});
Comment thread
anshumanv marked this conversation as resolved.
Outdated

it('should reload on file content changed', (done) => {
server.staticWatchers[0].on('change', (changedPath) => {
expect(changedPath).toBe(file);
Expand Down