add test case by this change
This commit is contained in:
parent
c5fff759ee
commit
d66cce2601
|
@ -253,14 +253,9 @@ module.exports = class HotModuleReplacementPlugin {
|
|||
c: {}
|
||||
};
|
||||
for (const key of Object.keys(records.chunkHashs)) {
|
||||
let chunkId;
|
||||
if (compiler.options.optimization.namedChunks) {
|
||||
chunkId = key;
|
||||
} else {
|
||||
chunkId = isNaN(+key) ? key : +key;
|
||||
}
|
||||
const chunkId = isNaN(+key) ? key : +key;
|
||||
const currentChunk = compilation.chunks.find(
|
||||
chunk => chunk.id === chunkId
|
||||
chunk => `${chunk.id}` === key
|
||||
);
|
||||
if (currentChunk) {
|
||||
const newModules = currentChunk
|
||||
|
|
|
@ -107,6 +107,7 @@
|
|||
"test": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest",
|
||||
"test:update-snapshots": "yarn jest -u",
|
||||
"test:integration": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.test.js\"",
|
||||
"test:HMR": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/{HotModuleReplacementPlugin}.test.js\"",
|
||||
"test:basic": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/{TestCasesNormal,StatsTestCases,ConfigTestCases}.test.js\"",
|
||||
"test:unit": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.unittest.js\"",
|
||||
"travis:integration": "yarn cover:init && yarn cover:integration --ci $JEST",
|
||||
|
|
|
@ -97,4 +97,78 @@ describe("HotModuleReplacementPlugin", () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should correct working when entry is Object and key is a number", done => {
|
||||
const entryFile = path.join(
|
||||
__dirname,
|
||||
"js",
|
||||
"HotModuleReplacementPlugin",
|
||||
"entry.js"
|
||||
);
|
||||
const statsFile3 = path.join(
|
||||
__dirname,
|
||||
"js",
|
||||
"HotModuleReplacementPlugin",
|
||||
"HotModuleReplacementPlugin.test.stats3.txt"
|
||||
);
|
||||
const statsFile4 = path.join(
|
||||
__dirname,
|
||||
"js",
|
||||
"HotModuleReplacementPlugin",
|
||||
"HotModuleReplacementPlugin.test.stats4.txt"
|
||||
);
|
||||
const recordsFile = path.join(
|
||||
__dirname,
|
||||
"js",
|
||||
"HotModuleReplacementPlugin",
|
||||
"records.json"
|
||||
);
|
||||
try {
|
||||
mkdirp.sync(path.join(__dirname, "js", "HotModuleReplacementPlugin"));
|
||||
} catch (e) {
|
||||
// empty
|
||||
}
|
||||
try {
|
||||
fs.unlinkSync(recordsFile);
|
||||
} catch (e) {
|
||||
// empty
|
||||
}
|
||||
const compiler = webpack({
|
||||
mode: "development",
|
||||
cache: false,
|
||||
entry: {
|
||||
"0": entryFile
|
||||
},
|
||||
recordsPath: recordsFile,
|
||||
output: {
|
||||
path: path.join(__dirname, "js", "HotModuleReplacementPlugin")
|
||||
},
|
||||
plugins: [new webpack.HotModuleReplacementPlugin()],
|
||||
optimization: {
|
||||
namedChunks: true
|
||||
}
|
||||
});
|
||||
fs.writeFileSync(entryFile, "1", "utf-8");
|
||||
compiler.run((err, stats) => {
|
||||
if (err) throw err;
|
||||
const jsonStats = stats.toJson();
|
||||
const hash = jsonStats.hash;
|
||||
const trunkName = Object.keys(jsonStats.assetsByChunkName)[0];
|
||||
fs.writeFileSync(statsFile3, stats.toString());
|
||||
compiler.run((err, stats) => {
|
||||
if (err) throw err;
|
||||
fs.writeFileSync(statsFile4, stats.toString());
|
||||
fs.writeFileSync(entryFile, "2", "utf-8");
|
||||
compiler.run((err, stats) => {
|
||||
if (err) throw err;
|
||||
fs.writeFileSync(statsFile3, stats.toString());
|
||||
const result = JSON.parse(
|
||||
stats.compilation.assets[`${hash}.hot-update.json`].source()
|
||||
)["c"][`${trunkName}`];
|
||||
expect(result).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue