forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WatchClose.test.js
61 lines (50 loc) · 1.19 KB
/
WatchClose.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"use strict";
require("./helpers/warmup-webpack");
const path = require("path");
describe("WatchClose", () => {
jest.setTimeout(5000);
describe("multiple calls watcher", () => {
const fixturePath = path.join(__dirname, "fixtures");
const outputPath = path.join(__dirname, "js/WatchClose");
const filePath = path.join(fixturePath, "a.js");
let compiler;
let watcher;
beforeEach(() => {
const webpack = require("../");
compiler = webpack({
mode: "development",
entry: filePath,
output: {
path: outputPath,
filename: "bundle.js"
}
});
watcher = compiler.watch({ poll: 300 }, () => {});
});
afterEach(() => {
watcher.close();
compiler = null;
});
function close(watcher, callback) {
return new Promise(res => {
const onClose = () => {
callback();
res();
};
watcher.close(onClose);
});
}
it("each callback should be called", async () => {
let num = 0;
await Promise.all([
close(watcher, () => (num += 1)),
close(watcher, () => (num += 10))
]);
await Promise.all([
close(watcher, () => (num += 100)),
close(watcher, () => (num += 1000))
]);
expect(num).toBe(1111);
});
});
});