Skip to content

Commit

Permalink
feat(server): add callback support for invalidate (#1900)
Browse files Browse the repository at this point in the history
  • Loading branch information
EslamHiko authored and evilebottnawi committed May 31, 2019
1 parent bca0341 commit cd218ef
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -980,9 +980,9 @@ class Server {
this.contentBaseWatchers.push(watcher);
}

invalidate() {
invalidate(callback) {
if (this.middleware) {
this.middleware.invalidate();
this.middleware.invalidate(callback);
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions test/InvalidateCallback.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

const webpack = require('webpack');
const { noop } = require('webpack-dev-middleware/lib/util');
const Server = require('../lib/Server');
const config = require('./fixtures/simple-config/webpack.config');

describe('Invalidate Callback', () => {
describe('Testing callback functions on calling invalidate without callback', () => {
it('should be `noop` (the default callback function)', (done) => {
const compiler = webpack(config);
const server = new Server(compiler);

server.invalidate();
expect(server.middleware.context.callbacks[0]).toBe(noop);

compiler.hooks.done.tap('webpack-dev-server', () => {
server.close(done);
});

compiler.run(() => {});
});
});

describe('Testing callback functions on calling invalidate with callback', () => {
it('should be `callback` function', (done) => {
const compiler = webpack(config);
const callback = jest.fn();
const server = new Server(compiler);
server.invalidate(callback);

expect(server.middleware.context.callbacks[0]).toBe(callback);

compiler.hooks.done.tap('webpack-dev-server', () => {
server.close(done);
});

compiler.run(() => {});
});
});
});

0 comments on commit cd218ef

Please # to comment.