Skip to content

Commit 13dc07e

Browse files
test: added
1 parent 73f67fb commit 13dc07e

File tree

9 files changed

+91
-2
lines changed

9 files changed

+91
-2
lines changed

lib/ProgressPlugin.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ const createDefaultHandler = (profile, logger) => {
128128
return defaultHandler;
129129
};
130130

131+
const SKIPPED_QUEUE_CONTEXTS = ["import-module", "load-module"];
132+
131133
/**
132134
* @callback ReportProgress
133135
* @param {number} p percentage
@@ -313,7 +315,7 @@ class ProgressPlugin {
313315
* @param {T} _item item
314316
*/
315317
const factorizeAdd = (factorizeQueue, _item) => {
316-
if (factorizeQueue.getContext() === "import-module") {
318+
if (SKIPPED_QUEUE_CONTEXTS.includes(factorizeQueue.getContext())) {
317319
skippedDependenciesCount++;
318320
}
319321
dependenciesCount++;
@@ -333,7 +335,7 @@ class ProgressPlugin {
333335
* @param {T} _item item
334336
*/
335337
const moduleAdd = (addModuleQueue, _item) => {
336-
if (addModuleQueue.getContext() === "import-module") {
338+
if (SKIPPED_QUEUE_CONTEXTS.includes(addModuleQueue.getContext())) {
337339
skippedModulesCount++;
338340
}
339341
modulesCount++;

lib/dependencies/LoaderPlugin.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ class LoaderPlugin {
7676
)
7777
);
7878
}
79+
const oldFactorizeQueueContext =
80+
compilation.factorizeQueue.getContext();
81+
compilation.factorizeQueue.setContext("load-module");
82+
const oldAddModuleQueueContext =
83+
compilation.addModuleQueue.getContext();
84+
compilation.addModuleQueue.setContext("load-module");
7985
compilation.buildQueue.increaseParallelism();
8086
compilation.handleModuleCreation(
8187
{
@@ -88,6 +94,8 @@ class LoaderPlugin {
8894
recursive: false
8995
},
9096
err => {
97+
compilation.factorizeQueue.setContext(oldFactorizeQueueContext);
98+
compilation.addModuleQueue.setContext(oldAddModuleQueueContext);
9199
compilation.buildQueue.decreaseParallelism();
92100
if (err) {
93101
return callback(err);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const a = "a";
2+
export const b = "b";
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import a, { value, random } from "./mod.js";
2+
import { value as unrelated } from "./unrelated";
3+
4+
it("should have to correct values and validate on change", () => {
5+
const step = +WATCH_STEP;
6+
expect(a).toBe(24);
7+
expect(value).toBe(42);
8+
expect(random).toBeDefined();
9+
10+
if (step !== 0) {
11+
expect(STATE.random === a.random).toBe(step === 1);
12+
}
13+
STATE.random = a.random;
14+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/** @type {import("../../../../../").PitchLoaderDefinitionFunction} */
2+
exports.pitch = async function (remaining) {
3+
const callback = this.async();
4+
const result = this.loadModule(
5+
`${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`,
6+
(err, result) => {
7+
if (err) {
8+
callback(err);
9+
return;
10+
}
11+
12+
callback(null, result)
13+
}
14+
);
15+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const value = 42;
2+
export * from "./imported.js";
3+
export const random = Math.random();
4+
export default 24;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const value = 42;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const value = 24;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const webpack = require("../../../../");
2+
3+
/** @type {import("../../../../").Configuration} */
4+
module.exports = {
5+
cache: {
6+
type: "filesystem"
7+
},
8+
module: {
9+
rules: [
10+
{
11+
test: /mod\.js$/,
12+
use: "./loader"
13+
}
14+
]
15+
},
16+
plugins: [
17+
new webpack.ProgressPlugin(),
18+
{
19+
apply(compiler) {
20+
compiler.hooks.done.tapPromise("CacheTest", async () => {
21+
const cache = compiler
22+
.getCache("ProgressPlugin")
23+
.getItemCache("counts", null);
24+
25+
const data = await cache.getPromise();
26+
27+
if (data.modulesCount !== 4) {
28+
throw new Error(
29+
`Wrong cached value of \`ProgressPlugin.modulesCount\` - ${data.modulesCount}, expect 4`
30+
);
31+
}
32+
33+
if (data.dependenciesCount !== 4) {
34+
throw new Error(
35+
`Wrong cached value of \`ProgressPlugin.dependenciesCount\` - ${data.dependenciesCount}, expect 4`
36+
);
37+
}
38+
});
39+
}
40+
}
41+
]
42+
};

0 commit comments

Comments
 (0)