forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotModuleReplacementPlugin.test.js
More file actions
74 lines (71 loc) · 2.53 KB
/
HotModuleReplacementPlugin.test.js
File metadata and controls
74 lines (71 loc) · 2.53 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
"use strict";
const path = require("path");
const fs = require("fs");
const webpack = require("../");
describe("HotModuleReplacementPlugin", () => {
jest.setTimeout(10000);
it("should not have circular hashes but equal if unmodified", (done) => {
const entryFile = path.join(__dirname, "js", "entry.js");
const statsFile1 = path.join(__dirname, "js", "HotModuleReplacementPlugin.test.stats1.txt");
const statsFile2 = path.join(__dirname, "js", "HotModuleReplacementPlugin.test.stats2.txt");
const recordsFile = path.join(__dirname, "js", "records.json");
try {
fs.mkdirSync(path.join(__dirname, "js"));
} catch(e) {}
try {
fs.unlinkSync(recordsFile);
} catch(e) {}
const compiler = webpack({
cache: false,
entry: entryFile,
recordsPath: recordsFile,
output: {
path: path.join(__dirname, "js")
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.OccurrenceOrderPlugin()
]
});
fs.writeFileSync(entryFile, "1", "utf-8");
compiler.run((err, stats) => {
if(err) throw err;
const oldHash1 = stats.toJson().hash;
fs.writeFileSync(statsFile1, stats.toString());
compiler.run((err, stats) => {
if(err) throw err;
const lastHash1 = stats.toJson().hash;
fs.writeFileSync(statsFile2, stats.toString());
expect(lastHash1).toBe(oldHash1); // hash shouldn't change when bundle stay equal
fs.writeFileSync(entryFile, "2", "utf-8");
compiler.run((err, stats) => {
if(err) throw err;
const lastHash2 = stats.toJson().hash;
fs.writeFileSync(statsFile1, stats.toString());
expect(lastHash2).not.toBe(lastHash1); // hash should change when bundle changes
fs.writeFileSync(entryFile, "1", "utf-8");
compiler.run((err, stats) => {
if(err) throw err;
const currentHash1 = stats.toJson().hash;
fs.writeFileSync(statsFile2, stats.toString());
expect(currentHash1).not.toBe(lastHash1); // hash shouldn't change to the first hash if bundle changed back to first bundle
fs.writeFileSync(entryFile, "2", "utf-8");
compiler.run((err, stats) => {
if(err) throw err;
const currentHash2 = stats.toJson().hash;
fs.writeFileSync(statsFile1, stats.toString());
compiler.run((err, stats) => {
if(err) throw err;
expect(stats.toJson().hash).toBe(currentHash2);
expect(currentHash2).not.toBe(lastHash2);
expect(currentHash1).not.toBe(currentHash2);
expect(lastHash1).not.toBe(lastHash2);
done();
});
});
});
});
});
});
});
});