Skip to content

Commit

Permalink
add watch test case
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Apr 12, 2021
1 parent 1d35cf1 commit 0d6b5db
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const value = 42;
export * from "./imported.js";
2 changes: 2 additions & 0 deletions test/watchCases/cache/loader-import-module/0/imported.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const a = "a";
export const b = "b";
18 changes: 18 additions & 0 deletions test/watchCases/cache/loader-import-module/0/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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(step < 3 ? 42 : 24);
expect(a.nested.a).toBe(step < 3 ? "a" : undefined);
expect(a.b).toBe(step < 1 ? "b" : undefined);
expect(a.nested.b).toBe(step < 1 ? "b" : undefined);
expect(a.c).toBe(step < 1 ? undefined : "c");
expect(a.nested.c).toBe(step < 1 || step >= 3 ? undefined : "c");
if (step !== 0) {
expect(STATE.random === a.random).toBe(step === 2);
}
STATE.random = a.random;
});
6 changes: 6 additions & 0 deletions test/watchCases/cache/loader-import-module/0/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
exports.pitch = async function (remaining) {
const result = await this.importModule(
`${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`
);
return JSON.stringify(result, null, 2);
};
1 change: 1 addition & 0 deletions test/watchCases/cache/loader-import-module/0/unrelated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const value = 42;
2 changes: 2 additions & 0 deletions test/watchCases/cache/loader-import-module/1/imported.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const a = "a";
export const c = "c";
1 change: 1 addition & 0 deletions test/watchCases/cache/loader-import-module/2/unrelated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const value = 24;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const value = 24;
12 changes: 12 additions & 0 deletions test/watchCases/cache/loader-import-module/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
module: {
rules: [
{
test: /\.generate-json\.js$/,
use: "./loader",
type: "json"
}
]
}
};

0 comments on commit 0d6b5db

Please sign in to comment.