mirror of https://github.com/webpack/webpack.git
test: added
This commit is contained in:
parent
73f67fb132
commit
13dc07e996
|
@ -128,6 +128,8 @@ const createDefaultHandler = (profile, logger) => {
|
|||
return defaultHandler;
|
||||
};
|
||||
|
||||
const SKIPPED_QUEUE_CONTEXTS = ["import-module", "load-module"];
|
||||
|
||||
/**
|
||||
* @callback ReportProgress
|
||||
* @param {number} p percentage
|
||||
|
@ -313,7 +315,7 @@ class ProgressPlugin {
|
|||
* @param {T} _item item
|
||||
*/
|
||||
const factorizeAdd = (factorizeQueue, _item) => {
|
||||
if (factorizeQueue.getContext() === "import-module") {
|
||||
if (SKIPPED_QUEUE_CONTEXTS.includes(factorizeQueue.getContext())) {
|
||||
skippedDependenciesCount++;
|
||||
}
|
||||
dependenciesCount++;
|
||||
|
@ -333,7 +335,7 @@ class ProgressPlugin {
|
|||
* @param {T} _item item
|
||||
*/
|
||||
const moduleAdd = (addModuleQueue, _item) => {
|
||||
if (addModuleQueue.getContext() === "import-module") {
|
||||
if (SKIPPED_QUEUE_CONTEXTS.includes(addModuleQueue.getContext())) {
|
||||
skippedModulesCount++;
|
||||
}
|
||||
modulesCount++;
|
||||
|
|
|
@ -76,6 +76,12 @@ class LoaderPlugin {
|
|||
)
|
||||
);
|
||||
}
|
||||
const oldFactorizeQueueContext =
|
||||
compilation.factorizeQueue.getContext();
|
||||
compilation.factorizeQueue.setContext("load-module");
|
||||
const oldAddModuleQueueContext =
|
||||
compilation.addModuleQueue.getContext();
|
||||
compilation.addModuleQueue.setContext("load-module");
|
||||
compilation.buildQueue.increaseParallelism();
|
||||
compilation.handleModuleCreation(
|
||||
{
|
||||
|
@ -88,6 +94,8 @@ class LoaderPlugin {
|
|||
recursive: false
|
||||
},
|
||||
err => {
|
||||
compilation.factorizeQueue.setContext(oldFactorizeQueueContext);
|
||||
compilation.addModuleQueue.setContext(oldAddModuleQueueContext);
|
||||
compilation.buildQueue.decreaseParallelism();
|
||||
if (err) {
|
||||
return callback(err);
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
export const a = "a";
|
||||
export const b = "b";
|
|
@ -0,0 +1,14 @@
|
|||
import a, { value, random } from "./mod.js";
|
||||
import { value as unrelated } from "./unrelated";
|
||||
|
||||
it("should have to correct values and validate on change", () => {
|
||||
const step = +WATCH_STEP;
|
||||
expect(a).toBe(24);
|
||||
expect(value).toBe(42);
|
||||
expect(random).toBeDefined();
|
||||
|
||||
if (step !== 0) {
|
||||
expect(STATE.random === a.random).toBe(step === 1);
|
||||
}
|
||||
STATE.random = a.random;
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
/** @type {import("../../../../../").PitchLoaderDefinitionFunction} */
|
||||
exports.pitch = async function (remaining) {
|
||||
const callback = this.async();
|
||||
const result = this.loadModule(
|
||||
`${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`,
|
||||
(err, result) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, result)
|
||||
}
|
||||
);
|
||||
};
|
|
@ -0,0 +1,4 @@
|
|||
export const value = 42;
|
||||
export * from "./imported.js";
|
||||
export const random = Math.random();
|
||||
export default 24;
|
|
@ -0,0 +1 @@
|
|||
export const value = 42;
|
|
@ -0,0 +1 @@
|
|||
export const value = 24;
|
|
@ -0,0 +1,42 @@
|
|||
const webpack = require("../../../../");
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
cache: {
|
||||
type: "filesystem"
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /mod\.js$/,
|
||||
use: "./loader"
|
||||
}
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new webpack.ProgressPlugin(),
|
||||
{
|
||||
apply(compiler) {
|
||||
compiler.hooks.done.tapPromise("CacheTest", async () => {
|
||||
const cache = compiler
|
||||
.getCache("ProgressPlugin")
|
||||
.getItemCache("counts", null);
|
||||
|
||||
const data = await cache.getPromise();
|
||||
|
||||
if (data.modulesCount !== 4) {
|
||||
throw new Error(
|
||||
`Wrong cached value of \`ProgressPlugin.modulesCount\` - ${data.modulesCount}, expect 4`
|
||||
);
|
||||
}
|
||||
|
||||
if (data.dependenciesCount !== 4) {
|
||||
throw new Error(
|
||||
`Wrong cached value of \`ProgressPlugin.dependenciesCount\` - ${data.dependenciesCount}, expect 4`
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
Loading…
Reference in New Issue