test: added

This commit is contained in:
alexander.akait 2024-09-26 20:46:29 +03:00
parent c5eccb21ca
commit 73f67fb132
8 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,4 @@
export const value = 42;
export * from "./imported.js";
export { default as nested } from "./b.generate-json.js";
export const random = Math.random();

View File

@ -0,0 +1,2 @@
export const value = 42;
export * from "./imported.js";

View File

@ -0,0 +1,2 @@
export const a = "a";
export const b = "b";

View File

@ -0,0 +1,16 @@
import a from "./a.generate-json.js";
import { value as unrelated } from "./unrelated";
it("should have to correct values and validate on change", () => {
const step = +WATCH_STEP;
expect(a.value).toBe(42);
expect(a.a).toBe("a");
expect(a.nested.value).toBe(42);
expect(a.nested.a).toBe("a");
expect(a.b).toBe("b");
expect(a.nested.b).toBe("b");
if (step !== 0) {
expect(STATE.random === a.random).toBe(step === 1);
}
STATE.random = a.random;
});

View File

@ -0,0 +1,7 @@
/** @type {import("../../../../../").PitchLoaderDefinitionFunction} */
exports.pitch = async function (remaining) {
const result = await this.importModule(
`${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`
);
return JSON.stringify(result, null, 2);
};

View File

@ -0,0 +1 @@
export const value = 42;

View File

@ -0,0 +1 @@
export const value = 24;

View File

@ -0,0 +1,43 @@
const webpack = require("../../../../");
/** @type {import("../../../../").Configuration} */
module.exports = {
cache: {
type: "filesystem"
},
module: {
rules: [
{
test: /\.generate-json\.js$/,
use: "./loader",
type: "json"
}
]
},
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 !== 3) {
throw new Error(
`Wrong cached value of \`ProgressPlugin.modulesCount\` - ${data.modulesCount}, expect 3`
);
}
if (data.dependenciesCount !== 3) {
throw new Error(
`Wrong cached value of \`ProgressPlugin.dependenciesCount\` - ${data.dependenciesCount}, expect 3`
);
}
});
}
}
]
};