Skip to content

test: use Rstest as Rslib's test framework #1090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@
// umd tests need to lock this version
'react-18',
'react-dom-18',
// bundled dts tests need to lock this version
'@vitest/expect',
// see https://github.com/web-infra-dev/rslib/pull/992
'@ast-grep/napi',
],
Expand Down
58 changes: 31 additions & 27 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,34 @@ jobs:
node-version: [20]

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 10
ref: ${{ inputs.ref || 'main' }}

- name: Install pnpm
run: |
npm install -g corepack@latest --force
corepack enable

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Install Dependencies
run: pnpm install && cd ./tests && pnpm playwright install chromium

# only run benchmark in Ubuntu
- name: Benchmarks (Vitest)
uses: CodSpeedHQ/action@0010eb0ca6e89b80c88e8edaaa07cfe5f3e6664d # v3
with:
run: pnpm run test:benchmark
# token retrieved from the CodSpeed app at the previous step
token: ${{ secrets.CODSPEED_TOKEN }}
# just a dummy step
- name: Dummy Step
run: echo "TODO:\ Support benchmark in Rstest, this job is only a placeholder for the time being."

# - name: Checkout
# uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
# with:
# fetch-depth: 10
# ref: ${{ inputs.ref || 'main' }}

# - name: Install pnpm
# run: |
# npm install -g corepack@latest --force
# corepack enable

# - name: Setup Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
# with:
# node-version: ${{ matrix.node-version }}
# cache: 'pnpm'

# - name: Install Dependencies
# run: pnpm install && cd ./tests && pnpm playwright install chromium

# # only run benchmark in Ubuntu
# - name: Benchmarks (Rstest)
# uses: CodSpeedHQ/action@0010eb0ca6e89b80c88e8edaaa07cfe5f3e6664d # v3
# with:
# run: pnpm run test:benchmark
# # token retrieved from the CodSpeed app at the previous step
# token: ${{ secrets.CODSPEED_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jobs:
if: steps.changes.outputs.changed == 'true'
run: pnpm install && cd ./tests && pnpm playwright install chromium

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

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ test-results
**/@mf-types
**/@mf-types/**
.env.local
.env.*.local
.env.*.local
.rslib/**/*
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ npx nx build @rslib/core --watch

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

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

### Run unit tests

Expand Down
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.0.5/schema.json",
"$schema": "https://biomejs.dev/schemas/2.0.6/schema.json",
"assist": {
"actions": {
"source": {
Expand Down Expand Up @@ -46,6 +46,7 @@
"includes": [
"**",
"!**/*.vue",
"!**/dist/**",
"!**/.rslib/**/*",
"!tests/integration/**/*/src/**/*",
"!tests/e2e/react-component/public/umd/**/*"
Expand Down
2 changes: 1 addition & 1 deletion examples/module-federation/mf-host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"react-dom": "^19.1.0"
},
"devDependencies": {
"@module-federation/rsbuild-plugin": "^0.15.0",
"@module-federation/rsbuild-plugin": "^0.16.0",
"@rsbuild/core": "~1.4.2",
"@rsbuild/plugin-react": "^1.3.2",
"@types/react": "^19.1.8",
Expand Down
31 changes: 17 additions & 14 deletions examples/module-federation/mf-host/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@ import { pluginReact } from '@rsbuild/plugin-react';
export default defineConfig({
plugins: [
pluginReact(),
pluginModuleFederation({
name: 'rsbuild_host',
remotes: {
rslib: 'rslib@http://localhost:3001/mf/mf-manifest.json',
},
shared: {
react: {
singleton: true,
pluginModuleFederation(
{
name: 'rsbuild_host',
remotes: {
rslib: 'rslib@http://localhost:3001/mf/mf-manifest.json',
},
'react-dom': {
singleton: true,
shared: {
react: {
singleton: true,
},
'react-dom': {
singleton: true,
},
},
// Enable this when the output of Rslib is build under 'production' mode, while the host app is 'development'.
// Reference: https://rslib.rs/guide/advanced/module-federation#faqs
shareStrategy: 'loaded-first',
},
// Enable this when the output of Rslib is build under 'production' mode, while the host app is 'development'.
// Reference: https://rslib.rs/guide/advanced/module-federation#faqs
shareStrategy: 'loaded-first',
}),
{},
),
],
});
4 changes: 2 additions & 2 deletions examples/module-federation/mf-react-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"storybook": "storybook dev -p 6006"
},
"devDependencies": {
"@module-federation/enhanced": "^0.15.0",
"@module-federation/rsbuild-plugin": "^0.15.0",
"@module-federation/enhanced": "^0.16.0",
"@module-federation/rsbuild-plugin": "^0.16.0",
"@module-federation/storybook-addon": "^4.0.20",
"@rsbuild/plugin-react": "^1.3.2",
"@rslib/core": "workspace:*",
Expand Down
25 changes: 14 additions & 11 deletions examples/module-federation/mf-react-component/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,23 @@ export default defineConfig({
assetPrefix: 'http://localhost:3001/mf',
},
plugins: [
pluginModuleFederation({
name: 'rslib_provider',
exposes: {
'.': './src/index.tsx',
},
shared: {
react: {
singleton: true,
pluginModuleFederation(
{
name: 'rslib_provider',
exposes: {
'.': './src/index.tsx',
},
'react-dom': {
singleton: true,
shared: {
react: {
singleton: true,
},
'react-dom': {
singleton: true,
},
},
},
}),
{},
),
],
},
],
Expand Down
2 changes: 1 addition & 1 deletion examples/module-federation/mf-remote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"react-dom": "^19.1.0"
},
"devDependencies": {
"@module-federation/rsbuild-plugin": "^0.15.0",
"@module-federation/rsbuild-plugin": "^0.16.0",
"@rsbuild/core": "~1.4.2",
"@rsbuild/plugin-react": "^1.3.2",
"@types/react": "^19.1.8",
Expand Down
25 changes: 14 additions & 11 deletions examples/module-federation/mf-remote/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ import { pluginReact } from '@rsbuild/plugin-react';
export default defineConfig({
plugins: [
pluginReact(),
pluginModuleFederation({
name: 'rsbuild_remote',
exposes: {
'.': './src/App.tsx',
},
shared: {
react: {
singleton: true,
pluginModuleFederation(
{
name: 'rsbuild_remote',
exposes: {
'.': './src/App.tsx',
},
'react-dom': {
singleton: true,
shared: {
react: {
singleton: true,
},
'react-dom': {
singleton: true,
},
},
},
}),
{},
),
],
server: {
port: 3002,
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
"test:benchmark": "cd ./tests && pnpm run test:benchmark",
"test:e2e": "pnpm run build:examples && cd tests && pnpm run test:e2e",
"test:ecosystem-ci": "pnpm run test:unit && cross-env ECO_CI=1 pnpm run test:integration && pnpm run test:e2e",
"test:integration": "cross-env NODE_OPTIONS='--experimental-vm-modules' vitest run --project integration",
"test:integration:watch": "cross-env NODE_OPTIONS='--experimental-vm-modules' vitest --project integration",
"test:unit": "vitest run --project unit*",
"test:unit:watch": "vitest --project unit*",
"test:integration": "pnpm -r --filter \"./tests\" run test",
"test:unit": "pnpm -r --filter \"./packages/**\" run test",
"testu": "pnpm run test:unit -u && pnpm run test:integration -u",
"type-check": "pnpm -r run type-check",
"update:rsbuild": "npx taze minor --include /rsbuild/ -w -r -l",
Expand All @@ -44,6 +42,7 @@
"devDependencies": {
"@biomejs/biome": "^2.0.6",
"@changesets/cli": "^2.29.5",
"@rstest/core": "0.0.6",
"@types/fs-extra": "^11.0.4",
"@types/node": "^22.15.34",
"check-dependency-version-consistency": "^5.0.1",
Expand All @@ -57,7 +56,6 @@
"prettier-plugin-packagejson": "^2.5.17",
"simple-git-hooks": "^2.13.0",
"typescript": "^5.8.3",
"vitest": "^3.2.4",
"zx": "^8.6.0"
},
"packageManager": "[email protected]",
Expand Down
5 changes: 0 additions & 5 deletions packages/core/__mocks__/fs/promises.cjs

This file was deleted.

2 changes: 2 additions & 0 deletions packages/core/__mocks__/fs/promises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { promises } from 'memfs';
export default promises;
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"build": "rslib build",
"dev": "rslib build --watch",
"prebundle": "prebundle",
"test": "rstest run",
"type-check": "tsc --noEmit && tsc --noEmit -p tests"
},
"dependencies": {
Expand All @@ -47,7 +48,7 @@
"tinyglobby": "^0.2.14"
},
"devDependencies": {
"@module-federation/rsbuild-plugin": "^0.15.0",
"@module-federation/rsbuild-plugin": "^0.16.0",
"@rslib/tsconfig": "workspace:*",
"@types/fs-extra": "^11.0.4",
"cac": "^6.7.14",
Expand Down
7 changes: 7 additions & 0 deletions packages/core/rstest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from '@rstest/core';
import { shared } from '../../rstest.workspace';

export default defineConfig({
...shared,
name: 'unit',
});
26 changes: 23 additions & 3 deletions packages/core/tests/__snapshots__/config.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
// Rstest Snapshot v1

exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config in each format 1`] = `
[
Expand All @@ -15,6 +15,16 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
},
"externals": [
[Function],
/\\^@rsbuild\\\\/core\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
/\\^rsbuild-plugin-dts\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
/\\^tinyglobby\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
/\\^@microsoft\\\\/api-extractor\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
/\\^typescript\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
"@rsbuild/core",
"rsbuild-plugin-dts",
"tinyglobby",
"@microsoft/api-extractor",
"typescript",
"assert",
"assert/strict",
"async_hooks",
Expand Down Expand Up @@ -73,7 +83,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
"pnpapi",
],
"filename": {
"js": "[name].mjs",
"js": "[name].js",
},
"filenameHash": false,
"minify": {
Expand Down Expand Up @@ -275,6 +285,16 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
"jsAsync": "./",
},
"externals": [
/\\^@rsbuild\\\\/core\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
/\\^rsbuild-plugin-dts\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
/\\^tinyglobby\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
/\\^@microsoft\\\\/api-extractor\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
/\\^typescript\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
"@rsbuild/core",
"rsbuild-plugin-dts",
"tinyglobby",
"@microsoft/api-extractor",
"typescript",
"assert",
"assert/strict",
"async_hooks",
Expand Down Expand Up @@ -333,7 +353,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
"pnpapi",
],
"filename": {
"js": "[name].js",
"js": "[name].cjs",
},
"filenameHash": false,
"minify": {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/tests/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { join } from 'node:path';
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
import { describe, expect, test, vi } from 'vitest';
import { describe, expect, rs, test } from '@rstest/core';
import {
composeCreateRsbuildConfig,
composeRsbuildEnvironments,
loadConfig,
} from '../src/config';
import type { RslibConfig } from '../src/types/config';

vi.mock('rslog');
rs.mock('rslog');

describe('Should load config file correctly', () => {
test('Load config.js in cjs project', async () => {
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('Should compose create Rsbuild config correctly', () => {
},
{
format: 'mf',
plugins: [pluginModuleFederation({})],
plugins: [pluginModuleFederation({}, {})],
},
],
source: {
Expand Down
Loading
Loading