Skip to content
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
582ffe8
Squashed commit of the following:
upupming Mar 10, 2026
49afabb
fix: test cases
upupming Mar 11, 2026
2f22d7d
fix: use-sync-external-store test cases
upupming Mar 11, 2026
88ec796
fix: expect for rstest
upupming Mar 11, 2026
f5a3757
feat: support rstest-adapter in testing library (#2347)
9aoy Mar 18, 2026
222a3b6
Merge branch 'main' into feat/rstest-rltl
upupming Mar 18, 2026
c493518
fix: rstest lock version (#2349)
9aoy Mar 18, 2026
62a1481
Update .github/workflows/test.yml
upupming Mar 19, 2026
ee27d39
Update packages/react/testing-library/.npmignore
upupming Mar 19, 2026
0773651
Update packages/react/testing-library/src/__tests__/css/index.test.jsx
upupming Mar 19, 2026
f581194
Update packages/react/testing-library/src/setupFiles/common/runtime-s…
upupming Mar 19, 2026
1c8cf5f
feat: add rstest support to testing-environment
upupming Mar 19, 2026
340592e
fix: align rstest environment and test loader options
upupming Mar 19, 2026
b1636a3
test: stabilize rstest list snapshot
upupming Mar 19, 2026
b5ebec8
Merge remote-tracking branch 'origin/main' into feat/rstest-rltl
upupming Mar 26, 2026
f79bc80
Merge remote-tracking branch 'origin/main' into feat/rstest-rltl
upupming Mar 26, 2026
dcd3dd3
Update .github/workflows/test.yml
upupming Mar 31, 2026
e6dee15
Merge origin/main into feat/rstest-rltl
upupming Mar 31, 2026
8b0aad1
fix(testing-library): externalize rstest dependencies
upupming Mar 31, 2026
df3ae29
Merge remote-tracking branch 'origin/main' into feat/rstest-rltl
upupming Apr 1, 2026
014ff38
Revert "fix(testing-library): externalize rstest dependencies"
upupming Apr 2, 2026
f50b0a5
fix: test snapshots
upupming Apr 2, 2026
e239639
fix: remove extra code
upupming Apr 2, 2026
2a6f4c5
Merge branch 'main' into feat/rstest-rltl
upupming Apr 2, 2026
085aed9
refactor(testing-library): deprecate createVitestConfig and adopt plu…
upupming Apr 2, 2026
c2f397d
refactor(testing-library): replace rstest-adapter with rstest-config
upupming Apr 2, 2026
41c16b2
chore: dedupe pnpm lockfile
upupming Apr 2, 2026
8fae035
fix: address rstest review comments
upupming Apr 2, 2026
b5e9180
revert: remove rspeedy peer dependency from react package
upupming Apr 2, 2026
333198d
chore: remove rstest peer dependency from react package
upupming Apr 2, 2026
b30dd88
chore: sync lockfile after removing rstest core
upupming Apr 2, 2026
a4c440a
Merge remote-tracking branch 'origin/main' into feat/rstest-rltl
upupming Apr 9, 2026
b77f622
fix: regenerate lockfile after merge
upupming Apr 9, 2026
6521e71
fix: add explicit type for profileFlowId
upupming Apr 9, 2026
5722509
fix: use runtime worklet-runtime paths in testing setup
upupming Apr 9, 2026
99592d3
test: fix vitest snapshot and defineDCE output assertion
upupming Apr 9, 2026
527ed7c
Merge remote-tracking branch 'origin/main' into feat/rstest-rltl
upupming Apr 13, 2026
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
6 changes: 6 additions & 0 deletions .changeset/easy-waves-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@lynx-js/react-webpack-plugin": patch
"@lynx-js/react-rsbuild-plugin": patch
---

Support rstest for testing library using a dedicated testing loader.
11 changes: 11 additions & 0 deletions .changeset/fair-plums-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@lynx-js/testing-environment": minor
---

**BREAKING CHANGE**:

Align the public test-environment API around `LynxEnv`.

`LynxTestingEnv` now expects a `{ window }`-shaped environment instead of relying on a concrete `JSDOM` instance or `global.jsdom`. Callers that construct `LynxTestingEnv` manually or initialize the environment through globals should migrate to `new LynxTestingEnv({ window })` or set `global.lynxEnv`.

This release also adds the `@lynx-js/testing-environment/env/rstest` entry for running the shared testing-environment suite under rstest.
5 changes: 5 additions & 0 deletions .changeset/ninety-pants-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-rspeedy": patch
---

Add Rstest ReactLynx Testing Library template.
26 changes: 26 additions & 0 deletions .changeset/red-lamps-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
"@lynx-js/react": patch
---

Support rstest for testing library, you can use rstest with RLTL now:

Create a config file `rstest.config.ts` with the following content:

```ts
import { defineConfig } from '@rstest/core';
import { withLynxConfig } from '@lynx-js/react/testing-library/rstest-config';

export default defineConfig({
extends: withLynxConfig(),
});
```

`@lynx-js/react/testing-library/rstest-config` will automatically load your `lynx.config.ts` and apply the same configuration to rstest, so you can keep your test environment consistent with your development environment.

And then use rstest as usual:

```bash
$ rstest
```

For more usage detail, see https://rstest.rs/
9 changes: 9 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ jobs:
pnpm run build --mode development
pnpm run lint
pnpm run test
cd `mktemp -d`
npx --registry http://localhost:4873 create-rspeedy-canary@latest --template react --dir create-rspeedy-regression-rstest-rltl --tools eslint,rstest-rltl
cd create-rspeedy-regression-rstest-rltl
npx --registry http://localhost:4873 upgrade-rspeedy-canary@latest
pnpm install --registry=http://localhost:4873
pnpm run build
pnpm run build --mode development
pnpm run lint
pnpm run test
test-react:
needs: build
uses: ./.github/workflows/workflow-test.yml
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@rsbuild/core": "catalog:rsbuild",
"@rslib/core": "^0.19.6",
"@rspack/core": "catalog:rspack",
"@rstest/core": "catalog:rstest",
"@svitejs/changesets-changelog-github-compact": "^1.2.0",
"@tsconfig/node22": "^22.0.5",
"@tsconfig/strictest": "^2.0.8",
Expand Down
12 changes: 6 additions & 6 deletions packages/lynx/gesture-runtime/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { defineConfig, mergeConfig } from 'vitest/config';
import { createVitestConfig } from '@lynx-js/react/testing-library/vitest-config';
import { defineConfig } from 'vitest/config';
import { vitestTestingLibraryPlugin } from '@lynx-js/react/testing-library/plugins';

const defaultConfig = await createVitestConfig();
const config = defineConfig({
export default defineConfig({
plugins: [
vitestTestingLibraryPlugin(),
],
test: {
name: 'lynx/gesture-runtime',
setupFiles: ['__test__/utils/setup.ts'],
Expand All @@ -13,5 +15,3 @@ const config = defineConfig({
exclude: ['__test__/utils/**'],
},
});

export default mergeConfig(defaultConfig, config);
12 changes: 6 additions & 6 deletions packages/motion/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { defineConfig, mergeConfig } from 'vitest/config';
import { createVitestConfig } from '@lynx-js/react/testing-library/vitest-config';
import { defineConfig } from 'vitest/config';
import { vitestTestingLibraryPlugin } from '@lynx-js/react/testing-library/plugins';

const defaultConfig = await createVitestConfig();
const config = defineConfig({
export default defineConfig({
plugins: [
vitestTestingLibraryPlugin(),
],
test: {
include: ['__tests__/**/*.test.{js,ts,jsx,tsx}'],
exclude: ['__tests__/utils/**'],
Expand All @@ -11,5 +13,3 @@ const config = defineConfig({
},
},
});

export default mergeConfig(defaultConfig, config);
10 changes: 9 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,17 @@
"default": "./testing-library/dist/pure.js"
},
"./testing-library/vitest-config": {
"types": "./testing-library/types/vitest-config.d.ts",
"types": "./testing-library/dist/vitest.config.d.ts",
Comment thread
upupming marked this conversation as resolved.
"default": "./testing-library/dist/vitest.config.js"
Comment thread
upupming marked this conversation as resolved.
},
"./testing-library/plugins": {
"types": "./testing-library/dist/plugins/index.d.ts",
"default": "./testing-library/dist/plugins/index.js"
},
"./testing-library/rstest-config": {
"types": "./testing-library/dist/rstest-config.d.ts",
"default": "./testing-library/dist/rstest-config.js"
},
"./package.json": "./package.json"
},
"types": "./types/react.d.ts",
Expand Down
6 changes: 4 additions & 2 deletions packages/react/testing-library/.npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*
!dist/*
!dist/env/*
*
!dist
!dist/**/*
!types
!types/*
Comment thread
upupming marked this conversation as resolved.
57 changes: 48 additions & 9 deletions packages/react/testing-library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,69 @@ Similar to [react-testing-library](https://github.com/testing-library/react-test

## Setup

### Rstest

Setup rstest with `@lynx-js/react/testing-library/rstest-config`.

Recommended for library projects:

```ts
import { defineConfig } from '@rstest/core';
import { withDefaultConfig } from '@lynx-js/react/testing-library/rstest-config';

export default defineConfig({
extends: withDefaultConfig(),
});
```

Use `withLynxConfig` when you want to reuse your app's `lynx.config.ts`:

```ts
// rstest.config.ts
import { defineConfig } from '@rstest/core';
import { withLynxConfig } from '@lynx-js/react/testing-library/rstest-config';

export default defineConfig({
extends: withLynxConfig(),
});
```

Difference between `withLynxConfig` and `withDefaultConfig`:

- `withLynxConfig`: app-oriented. Loads your `lynx.config.ts` and converts it to rstest config, so rspeedy/lynx settings are reused in tests.
- `withDefaultConfig`: library-oriented. Only applies testing-library defaults (`jsdom`, setup files, globals) and lets you provide the rest via `modifyRstestConfig`.

Then you can start writing tests and run them with rstest!

For more usage detail, see https://rstest.rs/

### Vitest

Setup vitest:

```js
// vitest.config.js
import { defineConfig, mergeConfig } from 'vitest/config';
import { createVitestConfig } from '@lynx-js/react/testing-library/vitest-config';
import { defineConfig } from 'vitest/config';
import { vitestTestingLibraryPlugin } from '@lynx-js/react/testing-library/plugins';

const defaultConfig = createVitestConfig();
const config = defineConfig({
export default defineConfig({
plugins: [
vitestTestingLibraryPlugin(),
],
test: {
// ...
},
});

export default mergeConfig(defaultConfig, config);
```

Then you can start writing tests and run them with vitest!

`createVitestConfig` is still supported for backward compatibility, but is deprecated.

## Usage

```js
```jsx
import '@testing-library/jest-dom';
import { test, expect } from 'vitest';
import { test, expect } from 'vitest'; // or '@rstest/core'
import { render } from '@lynx-js/react/testing-library';

test('renders options.wrapper around node', async () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/react/testing-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
"scripts": {
"build": "rslib build",
"dev": "rslib build --watch",
"rstest": "rstest",
"test": "npm run test:base && npm run test:3.1",
"test:3.1": "vitest --config vitest.3.1.config.ts",
"test:base": "vitest",
"test:ui": "vitest --ui"
},
"devDependencies": {
"@lynx-js/react": "workspace:*",
"@lynx-js/react-rsbuild-plugin": "workspace:*",
"@lynx-js/rspeedy": "workspace:*",
"@lynx-js/testing-environment": "workspace:*",
"@rsbuild/core": "catalog:rsbuild",
"@rstest/adapter-rsbuild": "^0.2.3",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.9.1"
}
Expand Down
19 changes: 14 additions & 5 deletions packages/react/testing-library/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ export default defineConfig({
{
format: 'esm',
syntax: 'es2022',
dts: false,
dts: true,
bundle: true,
source: {
entry: {
'pure': './src/pure.jsx',
'env/vitest': './src/env/vitest.ts',
'env/index': './src/env/index.ts',
'plugins/index': './src/plugins/index.ts',
'rstest-config': './src/rstest-config.ts',
},
},
output: {
Expand All @@ -23,6 +25,9 @@ export default defineConfig({
/^\.\.\/\.\.\/runtime\/lib/,
/^preact/,
/^vitest/,
'@rstest/core',
'@rsbuild/core',
'@lynx-js/rspeedy',
],
},
},
Expand All @@ -33,9 +38,13 @@ export default defineConfig({
bundle: false,
source: {
entry: {
'index': './src/index.jsx',
'vitest.config': './src/vitest.config.js',
'vitest-global-setup': './src/vitest-global-setup.js',
'index': [
'./src/index.jsx',
'./src/vitest.config.ts',
'./src/env/vitest.ts',
'./src/env/rstest.ts',
'./src/setupFiles/**/*.js',
],
},
},
output: {
Expand Down
44 changes: 44 additions & 0 deletions packages/react/testing-library/rstest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { defineConfig } from '@rstest/core';
import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin';
import { withDefaultConfig } from './src/rstest-config.ts';

export default defineConfig({
extends: withDefaultConfig({
modifyRstestConfig(config) {
return {
...config,
tools: {
swc: {
jsc: {
transform: {
useDefineForClassFields: true,
},
},
},
},
plugins: [
...(config.plugins || []),
pluginReactLynx(),
],
source: {
...config.source,
define: {
...config.source?.define,
__ALOG__: 'true',
},
},
resolve: {
...config.resolve,
// in order to make our test case work for
// both vitest and rstest, we need to alias
// `vitest` to `@rstest/core`
alias: {
...config.resolve?.alias,
vitest: require.resolve('./vitest-polyfill.cjs'),
},
},
include: ['src/**/*.test.{js,jsx,ts,tsx}', '!src/__tests__/3.1/**/*.{js,jsx,ts,tsx}'],
};
},
}),
});
8 changes: 4 additions & 4 deletions packages/react/testing-library/src/__tests__/act.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ test('fireEvent triggers useEffect calls', async () => {
[
"rLynxChange",
{
"data": "{"patchList":[{"snapshotPatch":[0,"__snapshot_e8d0a_test_4",2,4,2,[1],0,null,3,4,3,[0],1,2,3,null,1,-1,2,null],"id":2}]}",
"data": "{"patchList":[{"snapshotPatch":[0,"__snapshot_268b9_test_4",2,4,2,[1],0,null,3,4,3,[0],1,2,3,null,1,-1,2,null],"id":2}]}",
"patchOptions": {
"isHydration": true,
"pipelineOptions": {
Expand Down Expand Up @@ -236,7 +236,7 @@ test('fireEvent triggers useEffect calls', async () => {
],
"extraProps": undefined,
"id": 2,
"type": "__snapshot_e8d0a_test_4",
"type": "__snapshot_268b9_test_4",
"values": [
"2:0:",
],
Expand All @@ -261,7 +261,7 @@ test('fireEvent triggers useEffect calls', async () => {
],
"extraProps": undefined,
"id": 2,
"type": "__snapshot_e8d0a_test_4",
"type": "__snapshot_268b9_test_4",
"values": [
"2:0:",
],
Expand All @@ -285,7 +285,7 @@ test('fireEvent triggers useEffect calls', async () => {
[
"rLynxChange",
{
"data": "{"patchList":[{"snapshotPatch":[0,"__snapshot_e8d0a_test_4",2,4,2,[1],0,null,3,4,3,[0],1,2,3,null,1,-1,2,null],"id":2}]}",
"data": "{"patchList":[{"snapshotPatch":[0,"__snapshot_268b9_test_4",2,4,2,[1],0,null,3,4,3,[0],1,2,3,null,1,-1,2,null],"id":2}]}",
"patchOptions": {
"isHydration": true,
"pipelineOptions": {
Expand Down
Loading
Loading