Skip to content
Closed
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
af8a651
feat: support rstest in testing library
upupming Jul 17, 2025
852025f
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming Jul 17, 2025
854e2f1
fix: global.console in rstest cannot be modify
upupming Jul 17, 2025
2442e36
fix: unused Console type
upupming Jul 17, 2025
a0f2275
fix: api
upupming Jul 17, 2025
410e1c9
fix: use `enableTestingLibrary` instead of process.env.NODE_ENV to av…
upupming Jul 18, 2025
f4a9651
feat: add template to create-rspeedy
upupming Jul 18, 2025
7eb5c36
fix: enableTestingLibrary passing to ReactWebpackPlugin
upupming Jul 18, 2025
fe0fd93
feat: pre-bundled @lynx-js/testing-environment should shared between …
upupming Jul 18, 2025
dc74726
fix: setup file order in vitest
upupming Jul 18, 2025
d8a0221
Merge branch 'feat/rltl-rstest' of github.com:upupming/lynx-stack int…
upupming Jul 18, 2025
d3dce4a
fix: rstest setup
upupming Jul 18, 2025
c51a15a
chore: add testTimeout for rstest
upupming Jul 18, 2025
9a44a9a
feat: add rstest template
upupming Jul 18, 2025
a0a21b6
fix coderabbitai cr
upupming Jul 18, 2025
5b45cfb
feat: update snapshot
upupming Jul 18, 2025
dae4616
chore: update changeset
upupming Jul 18, 2025
04cbe34
Merge branch 'main' into feat/rltl-rstest
upupming Jul 18, 2025
fea9d67
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming Jul 24, 2025
df4d0a3
chore: use catalog for rstest version
upupming Jul 24, 2025
000961d
fix: use cjs for polyfill
upupming Jul 24, 2025
b391cb8
feat: keep the `createVitestConfig` API
upupming Jul 24, 2025
1163c32
feat: using callerName and reuse lynx.config for rstest
upupming Jul 24, 2025
a769bc5
chore: pnpm dedupe
upupming Jul 24, 2025
fe86acd
fix: cr
upupming Jul 24, 2025
6d0d454
Merge branch 'main' into feat/rltl-rstest
upupming Jul 24, 2025
2300227
docs: update changeset
upupming Jul 24, 2025
b9c1ca2
fix: cr
upupming Jul 25, 2025
fc20380
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming Jul 25, 2025
4591409
Update .changeset/red-lamps-arrive.md
upupming Jul 30, 2025
bfdebd0
feat: remove layer from testing rules
upupming Jul 30, 2025
0d4e0c9
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming Jul 30, 2025
cf78e1a
chore: changeset
upupming Jul 30, 2025
8863f55
fix: cr
upupming Aug 1, 2025
37cd1c8
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming Aug 1, 2025
37ccc68
feat: add applyStubRspeedyAPI
upupming Aug 1, 2025
34bd921
feat: add test cases for callerName: rstest
upupming Aug 1, 2025
b5567fa
Merge branch 'main' into feat/rltl-rstest
upupming Aug 4, 2025
e884c07
fix: remove test.only
upupming Aug 4, 2025
b898c19
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming Aug 6, 2025
9d8bd7c
feat: use getRspeedyAPI and remove applyStubRspeedyAPI
upupming Aug 6, 2025
095bc28
feat: remove enableDefine and use lynx.config to define __ALOG__
upupming Aug 6, 2025
76872a4
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming Aug 6, 2025
1f51a70
fix: snapshot
upupming Aug 6, 2025
0c38300
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming Aug 11, 2025
1a18210
chore: remove process.env['DEBUG']
upupming Aug 11, 2025
41f71f1
fix: update testing cases
upupming Aug 11, 2025
24cd0a2
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming Aug 13, 2025
2825c3c
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming Aug 14, 2025
44fbd57
fix: rstest css module classname is diff from vitest
upupming Aug 14, 2025
b2d5322
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming Aug 20, 2025
ff2cb92
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming Aug 20, 2025
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.
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.
29 changes: 29 additions & 0 deletions .changeset/red-lamps-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
"@lynx-js/react": patch
---

Support rstest for testing library, you can use rstest with RLTL now:
Comment thread
upupming marked this conversation as resolved.

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

```ts
import { defineConfig, RstestConfig } from '@rstest/core';
import lynxConfig from './lynx.config.js';

export default defineConfig({
...lynxConfig as RstestConfig,
testEnvironment: 'jsdom',
setupFiles: [
require.resolve('@lynx-js/react/testing-library/setupFiles/rstest'),
],
globals: true,
});
```
Comment thread
upupming marked this conversation as resolved.

And then use rstest as usual:

```bash
$ rstest
```

For more usage detail, see https://rstest.rs/
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ jobs:
pnpm run build --mode development
pnpm run lint
pnpm run test
npx --registry http://localhost:4873 create-rspeedy-canary@latest --template react-rstest-rltl --dir create-rspeedy-regression-rstest-rltl
cd create-rspeedy-regression-rstest-rltl
pnpm install --registry=http://localhost:4873
pnpm run build
pnpm run build --mode development
pnpm run test
test-react:
needs: build
uses: ./.github/workflows/workflow-test.yml
Expand All @@ -182,6 +188,23 @@ jobs:
--no-cache
--logHeapUsage
--silent
test-rstest:
needs: build
uses: ./.github/workflows/workflow-test.yml
strategy:
matrix:
runs-on:
- name: Ubuntu
label: lynx-ubuntu-24.04-medium
- name: Windows
label: lynx-windows-2022-large
name: Rstest (${{ matrix.runs-on.name }})
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
runs-on: ${{ matrix.runs-on.label }}
run: |
pnpm -r run rstest --testTimeout=50000
test-rust:
needs: build
uses: ./.github/workflows/rust.yml
Expand Down Expand Up @@ -242,6 +265,7 @@ jobs:
- test-api
- test-publish
- test-react
- test-rstest
- test-rust
- test-type
- test-typos
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@microsoft/api-extractor": "catalog:",
"@rslib/core": "^0.11.2",
"@rspack/core": "catalog:rspack",
"@rstest/core": "catalog:rstest",
"@svitejs/changesets-changelog-github-compact": "^1.2.0",
"@tsconfig/node20": "^20.1.6",
"@tsconfig/strictest": "^2.0.5",
Expand Down
3 changes: 2 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@
"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",
"default": "./testing-library/dist/vitest.config.js"
},
Comment thread
upupming marked this conversation as resolved.
"./testing-library/setupFiles/rstest": "./testing-library/dist/setupFiles/rstest.js",
Comment thread
upupming marked this conversation as resolved.
"./package.json": "./package.json"
},
"types": "./types/react.d.ts",
Expand Down
3 changes: 1 addition & 2 deletions packages/react/testing-library/.npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
*
!dist/*
!dist/env/*
!dist/**/*
!types/*
3 changes: 3 additions & 0 deletions packages/react/testing-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
"scripts": {
"build": "rslib build",
"dev": "rslib build --watch",
"rstest": "rstest",
"test": "vitest",
"test:ui": "vitest --ui"
},
"devDependencies": {
"@lynx-js/react": "workspace:*",
"@lynx-js/react-rsbuild-plugin": "workspace:*",
"@lynx-js/testing-environment": "workspace:*",
"@rsbuild/core": "catalog:rsbuild",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.6.4"
}
Expand Down
17 changes: 11 additions & 6 deletions packages/react/testing-library/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { defineConfig, type rsbuild } from '@rslib/core';
import { defineConfig } from '@rslib/core';

export default defineConfig({
lib: [
{
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',
},
},
output: {
Expand All @@ -29,9 +30,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
36 changes: 36 additions & 0 deletions packages/react/testing-library/rstest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { defineConfig } from '@rstest/core';
import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin';

export default defineConfig({
tools: {
swc: {
jsc: {
transform: {
useDefineForClassFields: true,
},
},
},
},
plugins: [
pluginReactLynx(),
],
source: {
define: {
__RSTEST__: 'true',
__ALOG__: 'true',
},
},
testEnvironment: 'jsdom',
setupFiles: [
require.resolve('@lynx-js/react/testing-library/setupFiles/rstest'),
],
globals: true,
resolve: {
// in order to make our test case work for
// both vitest and rstest, we need to alias
// `vitest` to `@rstest/core`
alias: {
vitest: require.resolve('./vitest-polyfill.cjs'),
},
},
});
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 @@ -213,7 +213,7 @@ test('fireEvent triggers useEffect calls', async () => {
[
"rLynxChange",
{
"data": "{"patchList":[{"snapshotPatch":[0,"__Card__:__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,"__Card__:__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 @@ -248,7 +248,7 @@ test('fireEvent triggers useEffect calls', async () => {
],
"extraProps": undefined,
"id": 2,
"type": "__Card__:__snapshot_e8d0a_test_4",
"type": "__Card__:__snapshot_268b9_test_4",
"values": [
"2:0:",
],
Expand All @@ -273,7 +273,7 @@ test('fireEvent triggers useEffect calls', async () => {
],
"extraProps": undefined,
"id": 2,
"type": "__Card__:__snapshot_e8d0a_test_4",
"type": "__Card__:__snapshot_268b9_test_4",
"values": [
"2:0:",
],
Expand All @@ -297,7 +297,7 @@ test('fireEvent triggers useEffect calls', async () => {
[
"rLynxChange",
{
"data": "{"patchList":[{"snapshotPatch":[0,"__Card__:__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,"__Card__:__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
56 changes: 32 additions & 24 deletions packages/react/testing-library/src/__tests__/alog.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ import { act } from 'preact/test-utils';

describe('alog', () => {
test('should log', async () => {
vi.spyOn(lynxTestingEnv.mainThread.console, 'alog');
vi.spyOn(lynxTestingEnv.backgroundThread.console, 'alog');
const originalAlog = console.alog;
let mainThreadALogCalls = [];
let backgroundThreadALogCalls = [];
console.alog = (...args) => {
if (__MAIN_THREAD__) {
mainThreadALogCalls.push(args);
} else {
backgroundThreadALogCalls.push(args);
}
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.

let _setCount;
function App() {
Expand Down Expand Up @@ -35,69 +43,69 @@ describe('alog', () => {
enableBackgroundThread: true,
});

expect(lynxTestingEnv.mainThread.console.alog.mock.calls).toMatchInlineSnapshot(`
expect(mainThreadALogCalls).toMatchInlineSnapshot(`
[
[
"[MainThread Component Render] name: ClassComponent, uniqID: __Card__:__snapshot_426db_test_2, __id: -6",
"[MainThread Component Render] name: ClassComponent, uniqID: __Card__:__snapshot_d6fb6_test_2, __id: -6",
],
[
"[MainThread Component Render] name: FunctionComponent, uniqID: __Card__:__snapshot_426db_test_3, __id: -7",
"[MainThread Component Render] name: FunctionComponent, uniqID: __Card__:__snapshot_d6fb6_test_3, __id: -7",
],
[
"[MainThread Component Render] name: App, uniqID: __Card__:__snapshot_426db_test_1, __id: -2",
"[MainThread Component Render] name: App, uniqID: __Card__:__snapshot_d6fb6_test_1, __id: -2",
],
[
"[MainThread Component Render] name: Fragment, uniqID: __Card__:__snapshot_426db_test_1, __id: -2",
"[MainThread Component Render] name: Fragment, uniqID: __Card__:__snapshot_d6fb6_test_1, __id: -2",
],
]
`);
expect(lynxTestingEnv.backgroundThread.console.alog.mock.calls).toMatchInlineSnapshot(`
expect(backgroundThreadALogCalls).toMatchInlineSnapshot(`
[
[
"[BackgroundThread Component Render] name: ClassComponent, uniqID: __Card__:__snapshot_426db_test_2, __id: 6",
"[BackgroundThread Component Render] name: ClassComponent, uniqID: __Card__:__snapshot_d6fb6_test_2, __id: 6",
],
[
"[BackgroundThread Component Render] name: FunctionComponent, uniqID: __Card__:__snapshot_426db_test_3, __id: 7",
"[BackgroundThread Component Render] name: FunctionComponent, uniqID: __Card__:__snapshot_d6fb6_test_3, __id: 7",
],
[
"[BackgroundThread Component Render] name: App, uniqID: __Card__:__snapshot_426db_test_1, __id: 2",
"[BackgroundThread Component Render] name: App, uniqID: __Card__:__snapshot_d6fb6_test_1, __id: 2",
],
[
"[BackgroundThread Component Render] name: Fragment, uniqID: __Card__:__snapshot_426db_test_1, __id: 2",
"[BackgroundThread Component Render] name: Fragment, uniqID: __Card__:__snapshot_d6fb6_test_1, __id: 2",
],
]
`);

lynxTestingEnv.mainThread.console.alog.mockClear();
lynxTestingEnv.backgroundThread.console.alog.mockClear();
mainThreadALogCalls = [];
backgroundThreadALogCalls = [];

act(() => {
_setCount(0);
});

expect(lynxTestingEnv.mainThread.console.alog.mock.calls).toMatchInlineSnapshot(`[]`);
expect(lynxTestingEnv.backgroundThread.console.alog.mock.calls).toMatchInlineSnapshot(`[]`);

lynxTestingEnv.mainThread.console.alog.mockClear();
lynxTestingEnv.backgroundThread.console.alog.mockClear();
mainThreadALogCalls = [];
backgroundThreadALogCalls = [];

act(() => {
_setCount(1);
});

expect(lynxTestingEnv.mainThread.console.alog.mock.calls).toMatchInlineSnapshot(`[]`);
expect(lynxTestingEnv.backgroundThread.console.alog.mock.calls).toMatchInlineSnapshot(`
expect(mainThreadALogCalls).toMatchInlineSnapshot(`[]`);
expect(backgroundThreadALogCalls).toMatchInlineSnapshot(`
[
[
"[BackgroundThread Component Render] name: ClassComponent, uniqID: __Card__:__snapshot_426db_test_2, __id: -6",
"[BackgroundThread Component Render] name: ClassComponent, uniqID: __Card__:__snapshot_d6fb6_test_2, __id: -6",
],
[
"[BackgroundThread Component Render] name: FunctionComponent, uniqID: __Card__:__snapshot_426db_test_3, __id: -7",
"[BackgroundThread Component Render] name: FunctionComponent, uniqID: __Card__:__snapshot_d6fb6_test_3, __id: -7",
],
[
"[BackgroundThread Component Render] name: App, uniqID: __Card__:__snapshot_426db_test_1, __id: -2",
"[BackgroundThread Component Render] name: App, uniqID: __Card__:__snapshot_d6fb6_test_1, __id: -2",
],
]
`);

// Cleanup
console.alog = originalAlog;
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { beforeAll, test, expect } from 'vitest';

let render;

beforeAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'vitest';
import { expect, vi } from 'vitest';
import { render, cleanup } from '..';
import { Component } from '@lynx-js/react';

Expand Down
Loading
Loading