Skip to content

Commit

Permalink
feat(server): add callback support for invalidate
Browse files Browse the repository at this point in the history
  • Loading branch information
EslamHiko committed May 24, 2019
1 parent c0f8fde commit 86871e1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Server.js
Expand Up @@ -1003,9 +1003,9 @@ class Server {
this.contentBaseWatchers.push(watcher);
}

invalidate() {
invalidate(callback) {
if (this.middleware) {
this.middleware.invalidate();
this.middleware.invalidate(callback);
}
}
}
Expand Down
46 changes: 46 additions & 0 deletions test/Server.test.js
Expand Up @@ -2,6 +2,7 @@

const { relative, sep } = require('path');
const webpack = require('webpack');
const { noop } = require('webpack-dev-middleware/lib/util');
const request = require('supertest');
// Mock opn before loading Server
jest.mock('opn');
Expand Down Expand Up @@ -74,6 +75,51 @@ describe('Server', () => {
});
});

describe('Testing callback functions on calling invalidate without callback', () => {
it('should be `noop` (the default callback function)', () => {
return new Promise((res) => {
// eslint-disable-next-line
const Server = require('../lib/Server');
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(() => {
res();
});
});

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

describe('Testing callback functions on calling invalidate with callback', () => {
it('should be `callback` function', () => {
return new Promise((res) => {
// eslint-disable-next-line
const Server = require('../lib/Server');
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(() => {
res();
});
});

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

// issue: https://github.com/webpack/webpack-dev-server/issues/1724
describe('express.static.mine.types', () => {
beforeEach(() => {
Expand Down

0 comments on commit 86871e1

Please sign in to comment.