Skip to content

Commit

Permalink
test: add test case for runtime condition (#7250)
Browse files Browse the repository at this point in the history
  • Loading branch information
LingyuCoder authored Jul 22, 2024
1 parent d6a7de2 commit 719c3de
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 0 deletions.
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)`);
})
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);
});
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");
});
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);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./shared?1";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 42;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 42;
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
}
]
},
};
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 {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default class Super {}
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",
];
}
};

2 comments on commit 719c3de

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
_selftest ✅ success
nx ❌ failure
rspress ✅ success
rsbuild ❌ failure
examples ❌ failure

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-07-22 1b5fbdf) Current Change
10000_development-mode + exec 2.26 s ± 18 ms 2.26 s ± 19 ms +0.12 %
10000_development-mode_hmr + exec 703 ms ± 11 ms 696 ms ± 5 ms -0.99 %
10000_production-mode + exec 2.88 s ± 74 ms 2.89 s ± 26 ms +0.39 %
arco-pro_development-mode + exec 1.89 s ± 76 ms 1.9 s ± 69 ms +0.55 %
arco-pro_development-mode_hmr + exec 436 ms ± 3.4 ms 434 ms ± 1.4 ms -0.24 %
arco-pro_production-mode + exec 3.46 s ± 85 ms 3.48 s ± 63 ms +0.61 %
threejs_development-mode_10x + exec 1.76 s ± 13 ms 1.75 s ± 22 ms -0.67 %
threejs_development-mode_10x_hmr + exec 861 ms ± 3.3 ms 855 ms ± 8.2 ms -0.68 %
threejs_production-mode_10x + exec 5.74 s ± 38 ms 5.75 s ± 43 ms +0.11 %

Please sign in to comment.