forked from webpack/webpack-dev-server
/
InvalidateCallback.test.js
41 lines (32 loc) · 1.22 KB
/
InvalidateCallback.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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(() => {});
});
});
});