Skip to content

Commit 73f67fb

Browse files
test: added
1 parent c5eccb2 commit 73f67fb

File tree

8 files changed

+76
-0
lines changed

8 files changed

+76
-0
lines changed
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 { default as nested } from "./b.generate-json.js";
4+
export const random = Math.random();
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const value = 42;
2+
export * from "./imported.js";
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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import a from "./a.generate-json.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.value).toBe(42);
7+
expect(a.a).toBe("a");
8+
expect(a.nested.value).toBe(42);
9+
expect(a.nested.a).toBe("a");
10+
expect(a.b).toBe("b");
11+
expect(a.nested.b).toBe("b");
12+
if (step !== 0) {
13+
expect(STATE.random === a.random).toBe(step === 1);
14+
}
15+
STATE.random = a.random;
16+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** @type {import("../../../../../").PitchLoaderDefinitionFunction} */
2+
exports.pitch = async function (remaining) {
3+
const result = await this.importModule(
4+
`${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`
5+
);
6+
return JSON.stringify(result, null, 2);
7+
};
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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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: /\.generate-json\.js$/,
12+
use: "./loader",
13+
type: "json"
14+
}
15+
]
16+
},
17+
plugins: [
18+
new webpack.ProgressPlugin(),
19+
{
20+
apply(compiler) {
21+
compiler.hooks.done.tapPromise("CacheTest", async () => {
22+
const cache = compiler
23+
.getCache("ProgressPlugin")
24+
.getItemCache("counts", null);
25+
26+
const data = await cache.getPromise();
27+
28+
if (data.modulesCount !== 3) {
29+
throw new Error(
30+
`Wrong cached value of \`ProgressPlugin.modulesCount\` - ${data.modulesCount}, expect 3`
31+
);
32+
}
33+
34+
if (data.dependenciesCount !== 3) {
35+
throw new Error(
36+
`Wrong cached value of \`ProgressPlugin.dependenciesCount\` - ${data.dependenciesCount}, expect 3`
37+
);
38+
}
39+
});
40+
}
41+
}
42+
]
43+
};

0 commit comments

Comments
 (0)