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

feat(server): add callback support for invalidate #1900

Merged
merged 4 commits into from May 31, 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
4 changes: 2 additions & 2 deletions lib/Server.js
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
@@ -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(() => {});
});
});
});