Skip to content

Commit 617fe7a

Browse files
authored
test: add persistent cache symlink test case (#11769)
1 parent 6f534ff commit 617fe7a

File tree

7 files changed

+70
-0
lines changed

7 files changed

+70
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default 1;
2+
---
3+
export default 2;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { version } from "tools";
2+
import value from "./file";
3+
4+
it("should invalidation work when using lib symlink", async () => {
5+
if (COMPILER_INDEX == 0) {
6+
expect(value).toBe(1);
7+
expect(version).toBe("1.0.0");
8+
await NEXT_START();
9+
}
10+
if (COMPILER_INDEX == 1) {
11+
expect(value).toBe(1);
12+
expect(version).toBe("2.0.0");
13+
}
14+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const version = "1.0.0";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"version": "1.0.0",
3+
"main": "./index.js"
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const version = "2.0.0";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"version": "2.0.0",
3+
"main": "./index.js"
4+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const path = require("path");
2+
const fs = require("fs");
3+
const fsPromise = require("fs/promises");
4+
5+
let index = 1;
6+
const nodeModulesPath = path.join(__dirname, "./node_modules");
7+
const toolsV1 = path.join(__dirname, "libs/tools_v1");
8+
const toolsV2 = path.join(__dirname, "libs/tools_v2");
9+
const libLinkedPath = path.join(nodeModulesPath, "tools");
10+
11+
/** @type {import("@rspack/core").Configuration} */
12+
module.exports = {
13+
context: __dirname,
14+
experiments: {
15+
cache: {
16+
type: "persistent",
17+
snapshot: {
18+
immutablePaths: [path.join(__dirname, "./file.js")],
19+
managedPaths: [path.join(__dirname, "./libs"), /node_modules/]
20+
}
21+
}
22+
},
23+
plugins: [
24+
{
25+
apply(compiler) {
26+
// make sure the node_modules dir exist
27+
fs.mkdirSync(nodeModulesPath, { recursive: true });
28+
compiler.hooks.beforeCompile.tapPromise(
29+
"Test Plugin",
30+
async function () {
31+
if (index === 1) {
32+
await fsPromise.symlink(toolsV1, libLinkedPath);
33+
} else {
34+
await fsPromise.unlink(libLinkedPath);
35+
await fsPromise.symlink(toolsV2, libLinkedPath);
36+
}
37+
index++;
38+
}
39+
);
40+
}
41+
}
42+
]
43+
};

0 commit comments

Comments
 (0)