Skip to content

Commit 202fa68

Browse files
test: use Rstest as Rslib's test framework (#1090)
Co-authored-by: Timeless0911 <[email protected]>
1 parent 2824c1b commit 202fa68

File tree

123 files changed

+916
-745
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+916
-745
lines changed

.github/renovate.json5

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@
6666
// umd tests need to lock this version
6767
'react-18',
6868
'react-dom-18',
69-
// bundled dts tests need to lock this version
70-
'@vitest/expect',
7169
// see https://github.com/web-infra-dev/rslib/pull/992
7270
'@ast-grep/napi',
7371
],

.github/workflows/benchmark.yml

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,34 @@ jobs:
2020
node-version: [20]
2121

2222
steps:
23-
- name: Checkout
24-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
25-
with:
26-
fetch-depth: 10
27-
ref: ${{ inputs.ref || 'main' }}
28-
29-
- name: Install pnpm
30-
run: |
31-
npm install -g corepack@latest --force
32-
corepack enable
33-
34-
- name: Setup Node.js ${{ matrix.node-version }}
35-
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
36-
with:
37-
node-version: ${{ matrix.node-version }}
38-
cache: 'pnpm'
39-
40-
- name: Install Dependencies
41-
run: pnpm install && cd ./tests && pnpm playwright install chromium
42-
43-
# only run benchmark in Ubuntu
44-
- name: Benchmarks (Vitest)
45-
uses: CodSpeedHQ/action@0010eb0ca6e89b80c88e8edaaa07cfe5f3e6664d # v3
46-
with:
47-
run: pnpm run test:benchmark
48-
# token retrieved from the CodSpeed app at the previous step
49-
token: ${{ secrets.CODSPEED_TOKEN }}
23+
# just a dummy step
24+
- name: Dummy Step
25+
run: echo "TODO:\ Support benchmark in Rstest, this job is only a placeholder for the time being."
26+
27+
# - name: Checkout
28+
# uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
29+
# with:
30+
# fetch-depth: 10
31+
# ref: ${{ inputs.ref || 'main' }}
32+
33+
# - name: Install pnpm
34+
# run: |
35+
# npm install -g corepack@latest --force
36+
# corepack enable
37+
38+
# - name: Setup Node.js ${{ matrix.node-version }}
39+
# uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
40+
# with:
41+
# node-version: ${{ matrix.node-version }}
42+
# cache: 'pnpm'
43+
44+
# - name: Install Dependencies
45+
# run: pnpm install && cd ./tests && pnpm playwright install chromium
46+
47+
# # only run benchmark in Ubuntu
48+
# - name: Benchmarks (Rstest)
49+
# uses: CodSpeedHQ/action@0010eb0ca6e89b80c88e8edaaa07cfe5f3e6664d # v3
50+
# with:
51+
# run: pnpm run test:benchmark
52+
# # token retrieved from the CodSpeed app at the previous step
53+
# token: ${{ secrets.CODSPEED_TOKEN }}

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ jobs:
121121
if: steps.changes.outputs.changed == 'true'
122122
run: pnpm install && cd ./tests && pnpm playwright install chromium
123123

124-
- name: Integration Test (Vitest)
124+
- name: Integration Test (Rstest)
125125
if: steps.changes.outputs.changed == 'true'
126126
run: pnpm run test:integration
127127

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ test-results
2525
**/@mf-types
2626
**/@mf-types/**
2727
.env.local
28-
.env.*.local
28+
.env.*.local
29+
.rslib/**/*

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ npx nx build @rslib/core --watch
7272

7373
If you've fixed a bug or added code that should be tested, then add some tests.
7474

75-
You can add unit test cases in the `<PACKAGE_DIR>/tests` folder. The test runner is based on [Vitest](https://vitest.dev/).
75+
You can add unit test cases in the `<PACKAGE_DIR>/tests` folder. The test runner is based on [Rstest](https://rstest.rs/).
7676

7777
### Run unit tests
7878

biome.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.0.5/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/2.0.6/schema.json",
33
"assist": {
44
"actions": {
55
"source": {
@@ -46,6 +46,7 @@
4646
"includes": [
4747
"**",
4848
"!**/*.vue",
49+
"!**/dist/**",
4950
"!**/.rslib/**/*",
5051
"!tests/integration/**/*/src/**/*",
5152
"!tests/e2e/react-component/public/umd/**/*"

examples/module-federation/mf-host/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"react-dom": "^19.1.0"
1313
},
1414
"devDependencies": {
15-
"@module-federation/rsbuild-plugin": "^0.15.0",
15+
"@module-federation/rsbuild-plugin": "^0.16.0",
1616
"@rsbuild/core": "~1.4.2",
1717
"@rsbuild/plugin-react": "^1.3.2",
1818
"@types/react": "^19.1.8",

examples/module-federation/mf-host/rsbuild.config.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@ import { pluginReact } from '@rsbuild/plugin-react';
55
export default defineConfig({
66
plugins: [
77
pluginReact(),
8-
pluginModuleFederation({
9-
name: 'rsbuild_host',
10-
remotes: {
11-
rslib: 'rslib@http://localhost:3001/mf/mf-manifest.json',
12-
},
13-
shared: {
14-
react: {
15-
singleton: true,
8+
pluginModuleFederation(
9+
{
10+
name: 'rsbuild_host',
11+
remotes: {
12+
rslib: 'rslib@http://localhost:3001/mf/mf-manifest.json',
1613
},
17-
'react-dom': {
18-
singleton: true,
14+
shared: {
15+
react: {
16+
singleton: true,
17+
},
18+
'react-dom': {
19+
singleton: true,
20+
},
1921
},
22+
// Enable this when the output of Rslib is build under 'production' mode, while the host app is 'development'.
23+
// Reference: https://rslib.rs/guide/advanced/module-federation#faqs
24+
shareStrategy: 'loaded-first',
2025
},
21-
// Enable this when the output of Rslib is build under 'production' mode, while the host app is 'development'.
22-
// Reference: https://rslib.rs/guide/advanced/module-federation#faqs
23-
shareStrategy: 'loaded-first',
24-
}),
26+
{},
27+
),
2528
],
2629
});

examples/module-federation/mf-react-component/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"storybook": "storybook dev -p 6006"
1919
},
2020
"devDependencies": {
21-
"@module-federation/enhanced": "^0.15.0",
22-
"@module-federation/rsbuild-plugin": "^0.15.0",
21+
"@module-federation/enhanced": "^0.16.0",
22+
"@module-federation/rsbuild-plugin": "^0.16.0",
2323
"@module-federation/storybook-addon": "^4.0.20",
2424
"@rsbuild/plugin-react": "^1.3.2",
2525
"@rslib/core": "workspace:*",

examples/module-federation/mf-react-component/rslib.config.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,23 @@ export default defineConfig({
3434
assetPrefix: 'http://localhost:3001/mf',
3535
},
3636
plugins: [
37-
pluginModuleFederation({
38-
name: 'rslib_provider',
39-
exposes: {
40-
'.': './src/index.tsx',
41-
},
42-
shared: {
43-
react: {
44-
singleton: true,
37+
pluginModuleFederation(
38+
{
39+
name: 'rslib_provider',
40+
exposes: {
41+
'.': './src/index.tsx',
4542
},
46-
'react-dom': {
47-
singleton: true,
43+
shared: {
44+
react: {
45+
singleton: true,
46+
},
47+
'react-dom': {
48+
singleton: true,
49+
},
4850
},
4951
},
50-
}),
52+
{},
53+
),
5154
],
5255
},
5356
],

examples/module-federation/mf-remote/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"react-dom": "^19.1.0"
1313
},
1414
"devDependencies": {
15-
"@module-federation/rsbuild-plugin": "^0.15.0",
15+
"@module-federation/rsbuild-plugin": "^0.16.0",
1616
"@rsbuild/core": "~1.4.2",
1717
"@rsbuild/plugin-react": "^1.3.2",
1818
"@types/react": "^19.1.8",

examples/module-federation/mf-remote/rsbuild.config.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@ import { pluginReact } from '@rsbuild/plugin-react';
55
export default defineConfig({
66
plugins: [
77
pluginReact(),
8-
pluginModuleFederation({
9-
name: 'rsbuild_remote',
10-
exposes: {
11-
'.': './src/App.tsx',
12-
},
13-
shared: {
14-
react: {
15-
singleton: true,
8+
pluginModuleFederation(
9+
{
10+
name: 'rsbuild_remote',
11+
exposes: {
12+
'.': './src/App.tsx',
1613
},
17-
'react-dom': {
18-
singleton: true,
14+
shared: {
15+
react: {
16+
singleton: true,
17+
},
18+
'react-dom': {
19+
singleton: true,
20+
},
1921
},
2022
},
21-
}),
23+
{},
24+
),
2225
],
2326
server: {
2427
port: 3002,

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
"test:benchmark": "cd ./tests && pnpm run test:benchmark",
1919
"test:e2e": "pnpm run build:examples && cd tests && pnpm run test:e2e",
2020
"test:ecosystem-ci": "pnpm run test:unit && cross-env ECO_CI=1 pnpm run test:integration && pnpm run test:e2e",
21-
"test:integration": "cross-env NODE_OPTIONS='--experimental-vm-modules' vitest run --project integration",
22-
"test:integration:watch": "cross-env NODE_OPTIONS='--experimental-vm-modules' vitest --project integration",
23-
"test:unit": "vitest run --project unit*",
24-
"test:unit:watch": "vitest --project unit*",
21+
"test:integration": "pnpm -r --filter \"./tests\" run test",
22+
"test:unit": "pnpm -r --filter \"./packages/**\" run test",
2523
"testu": "pnpm run test:unit -u && pnpm run test:integration -u",
2624
"type-check": "pnpm -r run type-check",
2725
"update:rsbuild": "npx taze minor --include /rsbuild/ -w -r -l",
@@ -44,6 +42,7 @@
4442
"devDependencies": {
4543
"@biomejs/biome": "^2.0.6",
4644
"@changesets/cli": "^2.29.5",
45+
"@rstest/core": "0.0.6",
4746
"@types/fs-extra": "^11.0.4",
4847
"@types/node": "^22.15.34",
4948
"check-dependency-version-consistency": "^5.0.1",
@@ -57,7 +56,6 @@
5756
"prettier-plugin-packagejson": "^2.5.17",
5857
"simple-git-hooks": "^2.13.0",
5958
"typescript": "^5.8.3",
60-
"vitest": "^3.2.4",
6159
"zx": "^8.6.0"
6260
},
6361
"packageManager": "[email protected]",

packages/core/__mocks__/fs/promises.cjs

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { promises } from 'memfs';
2+
export default promises;

packages/core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"build": "rslib build",
4040
"dev": "rslib build --watch",
4141
"prebundle": "prebundle",
42+
"test": "rstest run",
4243
"type-check": "tsc --noEmit && tsc --noEmit -p tests"
4344
},
4445
"dependencies": {
@@ -47,7 +48,7 @@
4748
"tinyglobby": "^0.2.14"
4849
},
4950
"devDependencies": {
50-
"@module-federation/rsbuild-plugin": "^0.15.0",
51+
"@module-federation/rsbuild-plugin": "^0.16.0",
5152
"@rslib/tsconfig": "workspace:*",
5253
"@types/fs-extra": "^11.0.4",
5354
"cac": "^6.7.14",

packages/core/rstest.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from '@rstest/core';
2+
import { shared } from '../../rstest.workspace';
3+
4+
export default defineConfig({
5+
...shared,
6+
name: 'unit',
7+
});

packages/core/tests/__snapshots__/config.test.ts.snap

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
1+
// Rstest Snapshot v1
22

33
exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config in each format 1`] = `
44
[
@@ -15,6 +15,16 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
1515
},
1616
"externals": [
1717
[Function],
18+
/\\^@rsbuild\\\\/core\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
19+
/\\^rsbuild-plugin-dts\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
20+
/\\^tinyglobby\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
21+
/\\^@microsoft\\\\/api-extractor\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
22+
/\\^typescript\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
23+
"@rsbuild/core",
24+
"rsbuild-plugin-dts",
25+
"tinyglobby",
26+
"@microsoft/api-extractor",
27+
"typescript",
1828
"assert",
1929
"assert/strict",
2030
"async_hooks",
@@ -73,7 +83,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
7383
"pnpapi",
7484
],
7585
"filename": {
76-
"js": "[name].mjs",
86+
"js": "[name].js",
7787
},
7888
"filenameHash": false,
7989
"minify": {
@@ -275,6 +285,16 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
275285
"jsAsync": "./",
276286
},
277287
"externals": [
288+
/\\^@rsbuild\\\\/core\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
289+
/\\^rsbuild-plugin-dts\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
290+
/\\^tinyglobby\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
291+
/\\^@microsoft\\\\/api-extractor\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
292+
/\\^typescript\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
293+
"@rsbuild/core",
294+
"rsbuild-plugin-dts",
295+
"tinyglobby",
296+
"@microsoft/api-extractor",
297+
"typescript",
278298
"assert",
279299
"assert/strict",
280300
"async_hooks",
@@ -333,7 +353,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
333353
"pnpapi",
334354
],
335355
"filename": {
336-
"js": "[name].js",
356+
"js": "[name].cjs",
337357
},
338358
"filenameHash": false,
339359
"minify": {

packages/core/tests/config.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { join } from 'node:path';
22
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
3-
import { describe, expect, test, vi } from 'vitest';
3+
import { describe, expect, rs, test } from '@rstest/core';
44
import {
55
composeCreateRsbuildConfig,
66
composeRsbuildEnvironments,
77
loadConfig,
88
} from '../src/config';
99
import type { RslibConfig } from '../src/types/config';
1010

11-
vi.mock('rslog');
11+
rs.mock('rslog');
1212

1313
describe('Should load config file correctly', () => {
1414
test('Load config.js in cjs project', async () => {
@@ -182,7 +182,7 @@ describe('Should compose create Rsbuild config correctly', () => {
182182
},
183183
{
184184
format: 'mf',
185-
plugins: [pluginModuleFederation({})],
185+
plugins: [pluginModuleFederation({}, {})],
186186
},
187187
],
188188
source: {

0 commit comments

Comments
 (0)