Skip to content

Commit

Permalink
test: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrykingxyz committed Jan 2, 2025
1 parent 22b6027 commit 52d566d
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default 1;
---
export default 2;
---
export default 3;
---
export default 4;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import value from "./file";

it("should invalidation using config.mode work", async () => {
if (COMPILER_INDEX == 0) {
expect(value).toBe(1);
await NEXT_HMR();
expect(value).toBe(2);
await NEXT_START();
}
if (COMPILER_INDEX == 1) {
expect(value).toBe(3);
await NEXT_HMR();
expect(value).toBe(4);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const path = require("path");

let index = 1;

/** @type {import("@rspack/core").Configuration} */
module.exports = {
context: __dirname,
experiments: {
cache: {
type: "persistent",
snapshot: {
immutablePaths: [path.join(__dirname, "./file.js")]
}
}
},
plugins: [
{
apply(compiler) {
compiler.hooks.beforeCompile.tap("Test Plugin", function () {
if (index === 1) {
compiler.options.mode = "development";
} else {
compiler.options.mode = "production";
}
index++;
});
}
}
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default 1;
---
export default 2;
---
export default 3;
---
export default 4;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import value from "./file";

it("should invalidation using config.name work", async () => {
if (COMPILER_INDEX == 0) {
expect(value).toBe(1);
await NEXT_HMR();
expect(value).toBe(2);
await NEXT_START();
}
if (COMPILER_INDEX == 1) {
expect(value).toBe(3);
await NEXT_HMR();
expect(value).toBe(4);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const path = require("path");

let index = 1;

/** @type {import("@rspack/core").Configuration} */
module.exports = {
context: __dirname,
experiments: {
cache: {
type: "persistent",
snapshot: {
immutablePaths: [path.join(__dirname, "./file.js")]
}
}
},
plugins: [
{
apply(compiler) {
compiler.hooks.beforeCompile.tap("Test Plugin", function () {
compiler.options.name = String(index);
index++;
});
}
}
]
};

0 comments on commit 52d566d

Please sign in to comment.