-
-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test case for runtime condition (#7250)
- Loading branch information
1 parent
d6a7de2
commit 719c3de
Showing
11 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
packages/rspack-test-tools/tests/configCases/runtime/runtime-condition/a.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,25 @@ | ||
import { val, val2b } from "./shared"; | ||
|
||
it("should have correct runtime id", () => { | ||
expect(val).toBe(84); | ||
expect(val2b).toBe(42); | ||
expect(__webpack_require__.j).toBe("a-runtime"); | ||
}); | ||
|
||
it("should include runtime condition check code", () => { | ||
const fs = __non_webpack_require__("fs"); | ||
const path = __non_webpack_require__("path"); | ||
const url = __non_webpack_require__("url"); | ||
|
||
const __filename = url.fileURLToPath(import.meta.url); | ||
const source = fs.readFileSync( | ||
path.join( | ||
__filename, | ||
"../../../../js/config/runtime/runtime-condition/shared.js" | ||
), | ||
"utf-8" | ||
); | ||
expect(source).toContain(`"a-runtime" == __webpack_require__.j`) | ||
expect(source).toContain(`"b-runtime" == __webpack_require__.j`); | ||
expect(source).toContain(`/^[ab]x\\-name$/.test(__webpack_require__.j)`); | ||
}) |
6 changes: 6 additions & 0 deletions
6
packages/rspack-test-tools/tests/configCases/runtime/runtime-condition/ax.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,6 @@ | ||
import { val, val2b } from "./concatenated-shared"; | ||
|
||
it("should have the correct value", () => { | ||
expect(val).toBe(84); | ||
expect(val2b).toBe(42); | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/rspack-test-tools/tests/configCases/runtime/runtime-condition/b.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,9 @@ | ||
import { other, val2c, Test } from "./shared"; | ||
|
||
it("should have correct runtime id", () => { | ||
expect(other).toBe("other"); | ||
expect(val2c).toBe(42); | ||
expect(Test).toBeTypeOf("function"); | ||
expect(new Test()).toBeInstanceOf(Test); | ||
expect(__webpack_require__.j).toBe("b-runtime"); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/rspack-test-tools/tests/configCases/runtime/runtime-condition/bx.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,8 @@ | ||
import { other, val2c, Test } from "./concatenated-shared"; | ||
|
||
it("should have the correct value", () => { | ||
expect(other).toBe("other"); | ||
expect(val2c).toBe(42); | ||
expect(Test).toBeTypeOf("function"); | ||
expect(new Test()).toBeInstanceOf(Test); | ||
}); |
1 change: 1 addition & 0 deletions
1
...ages/rspack-test-tools/tests/configCases/runtime/runtime-condition/concatenated-shared.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 @@ | ||
export * from "./shared?1"; |
1 change: 1 addition & 0 deletions
1
packages/rspack-test-tools/tests/configCases/runtime/runtime-condition/dep.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 @@ | ||
export default 42; |
1 change: 1 addition & 0 deletions
1
packages/rspack-test-tools/tests/configCases/runtime/runtime-condition/dep2.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 @@ | ||
module.exports = 42; |
44 changes: 44 additions & 0 deletions
44
packages/rspack-test-tools/tests/configCases/runtime/runtime-condition/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,44 @@ | ||
/** @type {import("@rspack/core").Configuration} */ | ||
module.exports = { | ||
entry: { | ||
"a-name": { | ||
import: "./a", | ||
runtime: "a-runtime", | ||
}, | ||
"b-name": { | ||
import: "./b", | ||
runtime: "b-runtime", | ||
}, | ||
"ax-name": "./ax.js", | ||
"bx-name": "./bx.js" | ||
}, | ||
target: "web", | ||
output: { | ||
filename: "[id].js", | ||
}, | ||
optimization: { | ||
chunkIds: "named", | ||
moduleIds: "named", | ||
minimize: false, | ||
usedExports: true, | ||
concatenateModules: true, | ||
splitChunks: { | ||
cacheGroups: { | ||
forceMerge: { | ||
test: /shared/, | ||
enforce: true, | ||
name: "shared", | ||
chunks: "all" | ||
} | ||
} | ||
} | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /dep/, | ||
sideEffects: false | ||
} | ||
] | ||
}, | ||
}; |
16 changes: 16 additions & 0 deletions
16
packages/rspack-test-tools/tests/configCases/runtime/runtime-condition/shared.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,16 @@ | ||
import value from "./dep"; | ||
import value2 from "./dep2"; | ||
import * as dep2 from "./dep2"; | ||
import Super from "./super"; | ||
|
||
const derived = value; | ||
|
||
export const val = /*#__PURE__*/ (() => value + derived)(); | ||
|
||
export const val2a = value2; | ||
export const val2b = value2; | ||
export const val2c = value2; | ||
|
||
export const other = "other"; | ||
|
||
export class Test extends Super {} |
1 change: 1 addition & 0 deletions
1
packages/rspack-test-tools/tests/configCases/runtime/runtime-condition/super.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 @@ | ||
export default class Super {} |
9 changes: 9 additions & 0 deletions
9
packages/rspack-test-tools/tests/configCases/runtime/runtime-condition/test.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,9 @@ | ||
module.exports = { | ||
findBundle: function (i, options) { | ||
return [ | ||
"a-runtime.js", | ||
"shared.js", | ||
"a-name.js", | ||
]; | ||
} | ||
}; |
719c3de
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.
📝 Ran ecosystem CI: Open
719c3de
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