-
-
Notifications
You must be signed in to change notification settings - Fork 618
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add persistent cache test (#8890)
* test: add persistent cache test * test: update snapshot
- Loading branch information
1 parent
515e650
commit 28f2169
Showing
26 changed files
with
296 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../tests/cacheCases/snapshot/basic/index.js → ...ls/tests/cacheCases/common/basic/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
packages/rspack-test-tools/tests/cacheCases/common/build-dependencies/file.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
15 changes: 15 additions & 0 deletions
15
packages/rspack-test-tools/tests/cacheCases/common/build-dependencies/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import value from "./file"; | ||
|
||
it("should build dependencies 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); | ||
} | ||
}); |
33 changes: 33 additions & 0 deletions
33
packages/rspack-test-tools/tests/cacheCases/common/build-dependencies/rspack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const path = require("path"); | ||
const fs = require("fs/promises"); | ||
|
||
let content = 1; | ||
|
||
const buildDependency = path.join(__dirname, "test.log"); | ||
|
||
/** @type {import("@rspack/core").Configuration} */ | ||
module.exports = { | ||
context: __dirname, | ||
experiments: { | ||
cache: { | ||
type: "persistent", | ||
buildDependencies: [buildDependency], | ||
snapshot: { | ||
immutablePaths: [path.join(__dirname, "./file.js")] | ||
} | ||
} | ||
}, | ||
plugins: [ | ||
{ | ||
apply(compiler) { | ||
compiler.hooks.beforeCompile.tapPromise( | ||
"Test Plugin", | ||
async function () { | ||
await fs.writeFile(buildDependency, String(content)); | ||
content++; | ||
} | ||
); | ||
} | ||
} | ||
] | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/rspack-test-tools/tests/cacheCases/common/version/file.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
15 changes: 15 additions & 0 deletions
15
packages/rspack-test-tools/tests/cacheCases/common/version/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import value from "./file"; | ||
|
||
it("should version 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); | ||
} | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/rspack-test-tools/tests/cacheCases/common/version/rspack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const path = require("path"); | ||
|
||
let version = 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.experiments.cache.version = String(version); | ||
version++; | ||
}); | ||
} | ||
} | ||
] | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/rspack-test-tools/tests/cacheCases/snapshot/immutable-paths/file.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
15 changes: 15 additions & 0 deletions
15
packages/rspack-test-tools/tests/cacheCases/snapshot/immutable-paths/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import value from "./file"; | ||
|
||
it("should snapshot immutable-paths 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(2); | ||
await NEXT_HMR(); | ||
expect(value).toBe(4); | ||
} | ||
}); |
14 changes: 14 additions & 0 deletions
14
packages/rspack-test-tools/tests/cacheCases/snapshot/immutable-paths/rspack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const path = require("path"); | ||
|
||
/** @type {import("@rspack/core").Configuration} */ | ||
module.exports = { | ||
context: __dirname, | ||
experiments: { | ||
cache: { | ||
type: "persistent", | ||
snapshot: { | ||
immutablePaths: [path.join(__dirname, "./file.js")] | ||
} | ||
} | ||
} | ||
}; |
15 changes: 15 additions & 0 deletions
15
packages/rspack-test-tools/tests/cacheCases/snapshot/managed-paths/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import value from "./test_lib"; | ||
|
||
it("should snapshot managed-paths 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(2); | ||
await NEXT_HMR(); | ||
expect(value).toBe(4); | ||
} | ||
}); |
14 changes: 14 additions & 0 deletions
14
packages/rspack-test-tools/tests/cacheCases/snapshot/managed-paths/rspack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const path = require("path"); | ||
|
||
/** @type {import("@rspack/core").Configuration} */ | ||
module.exports = { | ||
context: __dirname, | ||
experiments: { | ||
cache: { | ||
type: "persistent", | ||
snapshot: { | ||
managedPaths: [path.join(__dirname, "./test_lib")] | ||
} | ||
} | ||
} | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/rspack-test-tools/tests/cacheCases/snapshot/managed-paths/test_lib/file.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
5 changes: 5 additions & 0 deletions
5
packages/rspack-test-tools/tests/cacheCases/snapshot/managed-paths/test_lib/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "test_lib", | ||
"version": "0.0.1", | ||
"main": "./file.js" | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/rspack-test-tools/tests/cacheCases/snapshot/unmanaged-paths/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import value, { changed } from "./test_lib"; | ||
|
||
it("should snapshot unmanaged-paths work", async () => { | ||
if (COMPILER_INDEX == 0) { | ||
expect(value).toBe(1); | ||
expect(changed).toBe(1); | ||
await NEXT_HMR(); | ||
expect(value).toBe(2); | ||
expect(changed).toBe(2); | ||
await NEXT_START(); | ||
} | ||
if (COMPILER_INDEX == 1) { | ||
expect(value).toBe(2); | ||
expect(changed).toBe(3); | ||
await NEXT_HMR(); | ||
expect(value).toBe(4); | ||
expect(changed).toBe(4); | ||
} | ||
}); |
15 changes: 15 additions & 0 deletions
15
packages/rspack-test-tools/tests/cacheCases/snapshot/unmanaged-paths/rspack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const path = require("path"); | ||
|
||
/** @type {import("@rspack/core").Configuration} */ | ||
module.exports = { | ||
context: __dirname, | ||
experiments: { | ||
cache: { | ||
type: "persistent", | ||
snapshot: { | ||
managedPaths: [path.join(__dirname, "./test_lib")], | ||
unmanagedPaths: [path.join(__dirname, "./test_lib/changed.js")] | ||
} | ||
} | ||
} | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/rspack-test-tools/tests/cacheCases/snapshot/unmanaged-paths/test_lib/changed.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
15 changes: 15 additions & 0 deletions
15
packages/rspack-test-tools/tests/cacheCases/snapshot/unmanaged-paths/test_lib/file.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import changed from "./changed"; | ||
export { changed }; | ||
export default 1; | ||
--- | ||
import changed from "./changed"; | ||
export { changed }; | ||
export default 2; | ||
--- | ||
import changed from "./changed"; | ||
export { changed }; | ||
export default 3; | ||
--- | ||
import changed from "./changed"; | ||
export { changed }; | ||
export default 4; |
5 changes: 5 additions & 0 deletions
5
packages/rspack-test-tools/tests/cacheCases/snapshot/unmanaged-paths/test_lib/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "test_lib", | ||
"version": "0.0.1", | ||
"main": "./file.js" | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/rspack-test-tools/tests/cacheCases/storage/directory/file.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
15 changes: 15 additions & 0 deletions
15
packages/rspack-test-tools/tests/cacheCases/storage/directory/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import value from "./file"; | ||
|
||
it("should storage directory 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); | ||
} | ||
}); |
28 changes: 28 additions & 0 deletions
28
packages/rspack-test-tools/tests/cacheCases/storage/directory/rspack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const path = require("path"); | ||
const fs = require("fs/promises"); | ||
|
||
const cacheDir = path.join(__dirname, "node_modules/.cache/test/"); | ||
|
||
/** @type {import("@rspack/core").Configuration} */ | ||
module.exports = { | ||
context: __dirname, | ||
experiments: { | ||
cache: { | ||
type: "persistent", | ||
storage: { | ||
type: "filesystem", | ||
directory: cacheDir | ||
} | ||
} | ||
}, | ||
plugins: [ | ||
{ | ||
apply(compiler) { | ||
compiler.hooks.done.tapPromise("Test Plugin", async function () { | ||
const stat = await fs.stat(cacheDir); | ||
expect(stat.isDirectory()).toBeTruthy(); | ||
}); | ||
} | ||
} | ||
] | ||
}; |
28f2169
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Benchmark detail: Open