-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): add callback support for invalidate (#1900)
- Loading branch information
1 parent
bca0341
commit cd218ef
Showing
2 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(() => {}); | ||
}); | ||
}); | ||
}); |