|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +/*globals describe it before after */ |
| 4 | +const path = require("path"); |
| 5 | +const should = require("should"); |
| 6 | +const MemoryFs = require("memory-fs"); |
| 7 | +const webpack = require("../"); |
| 8 | + |
| 9 | +const createCompiler = config => { |
| 10 | + const compiler = webpack(config); |
| 11 | + compiler.outputFileSystem = new MemoryFs(); |
| 12 | + return compiler; |
| 13 | +}; |
| 14 | + |
| 15 | +const createSingleCompiler = () => { |
| 16 | + return createCompiler({ |
| 17 | + context: path.join(__dirname, "fixtures"), |
| 18 | + entry: "./a.js" |
| 19 | + }); |
| 20 | +}; |
| 21 | + |
| 22 | +const createMultiCompiler = () => { |
| 23 | + return createCompiler([{ |
| 24 | + context: path.join(__dirname, "fixtures"), |
| 25 | + entry: "./a.js" |
| 26 | + }]); |
| 27 | +}; |
| 28 | + |
| 29 | +describe("WatchEvents", () => { |
| 30 | + |
| 31 | + it("should emit 'watch-close' when using single-compiler mode and the compiler is not running", function(done) { |
| 32 | + let called = false; |
| 33 | + |
| 34 | + const compiler = createSingleCompiler(); |
| 35 | + const watcher = compiler.watch({}, (err, stats) => { |
| 36 | + called.should.be.exactly(true); |
| 37 | + done(err); |
| 38 | + }); |
| 39 | + |
| 40 | + compiler.plugin('watch-close', () => { |
| 41 | + called = true |
| 42 | + }); |
| 43 | + |
| 44 | + compiler.plugin('done', () => { |
| 45 | + watcher.close(); |
| 46 | + }); |
| 47 | + |
| 48 | + }); |
| 49 | + |
| 50 | + it("should emit 'watch-close' when using multi-compiler mode and the compiler is not running", function(done) { |
| 51 | + let called = false; |
| 52 | + |
| 53 | + const compiler = createMultiCompiler(); |
| 54 | + const watcher = compiler.watch({}, (err, stats) => { |
| 55 | + called.should.be.exactly(true); |
| 56 | + done(err); |
| 57 | + }); |
| 58 | + |
| 59 | + compiler.plugin('watch-close', () => { |
| 60 | + called = true |
| 61 | + }); |
| 62 | + |
| 63 | + compiler.plugin('done', () => { |
| 64 | + watcher.close(); |
| 65 | + }); |
| 66 | + |
| 67 | + }); |
| 68 | + |
| 69 | +}); |
0 commit comments