-
Notifications
You must be signed in to change notification settings - Fork 122
feat: support rstest in testing library #1305
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
af8a651
feat: support rstest in testing library
upupming 852025f
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming 854e2f1
fix: global.console in rstest cannot be modify
upupming 2442e36
fix: unused Console type
upupming a0f2275
fix: api
upupming 410e1c9
fix: use `enableTestingLibrary` instead of process.env.NODE_ENV to av…
upupming f4a9651
feat: add template to create-rspeedy
upupming 7eb5c36
fix: enableTestingLibrary passing to ReactWebpackPlugin
upupming fe0fd93
feat: pre-bundled @lynx-js/testing-environment should shared between …
upupming dc74726
fix: setup file order in vitest
upupming d8a0221
Merge branch 'feat/rltl-rstest' of github.com:upupming/lynx-stack int…
upupming d3dce4a
fix: rstest setup
upupming c51a15a
chore: add testTimeout for rstest
upupming 9a44a9a
feat: add rstest template
upupming a0a21b6
fix coderabbitai cr
upupming 5b45cfb
feat: update snapshot
upupming dae4616
chore: update changeset
upupming 04cbe34
Merge branch 'main' into feat/rltl-rstest
upupming fea9d67
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming df4d0a3
chore: use catalog for rstest version
upupming 000961d
fix: use cjs for polyfill
upupming b391cb8
feat: keep the `createVitestConfig` API
upupming 1163c32
feat: using callerName and reuse lynx.config for rstest
upupming a769bc5
chore: pnpm dedupe
upupming fe86acd
fix: cr
upupming 6d0d454
Merge branch 'main' into feat/rltl-rstest
upupming 2300227
docs: update changeset
upupming b9c1ca2
fix: cr
upupming fc20380
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming 4591409
Update .changeset/red-lamps-arrive.md
upupming bfdebd0
feat: remove layer from testing rules
upupming 0d4e0c9
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming cf78e1a
chore: changeset
upupming 8863f55
fix: cr
upupming 37cd1c8
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming 37ccc68
feat: add applyStubRspeedyAPI
upupming 34bd921
feat: add test cases for callerName: rstest
upupming b5567fa
Merge branch 'main' into feat/rltl-rstest
upupming e884c07
fix: remove test.only
upupming b898c19
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming 9d8bd7c
feat: use getRspeedyAPI and remove applyStubRspeedyAPI
upupming 095bc28
feat: remove enableDefine and use lynx.config to define __ALOG__
upupming 76872a4
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming 1f51a70
fix: snapshot
upupming 0c38300
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming 1a18210
chore: remove process.env['DEBUG']
upupming 41f71f1
fix: update testing cases
upupming 24cd0a2
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming 2825c3c
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming 44fbd57
fix: rstest css module classname is diff from vitest
upupming b2d5322
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming ff2cb92
Merge remote-tracking branch 'gh/main' into feat/rltl-rstest
upupming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --- | ||
| "@lynx-js/react": patch | ||
| --- | ||
|
|
||
| Support rstest for testing library, you can use rstest with RLTL now: | ||
|
|
||
| ```ts | ||
| import { defineConfig } from '@rstest/core'; | ||
| import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'; | ||
| import { rstestTestingLibraryPlugin } from '@lynx-js/react/testing-library/plugins'; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [ | ||
| rstestTestingLibraryPlugin(), | ||
| pluginReactLynx(), | ||
| ], | ||
| testEnvironment: 'jsdom', | ||
| setupFiles: [ | ||
| require.resolve('@lynx-js/react/testing-library/setupFiles/rstest'), | ||
| ], | ||
| globals: true, | ||
| }); | ||
| ``` | ||
|
upupming marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { defineConfig } from '@rstest/core'; | ||
| import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'; | ||
| import { rstestTestingLibraryPlugin } from './src/plugins'; | ||
| import type { RsbuildPlugin } from '@rsbuild/core'; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [ | ||
| rstestTestingLibraryPlugin(), | ||
| pluginReactLynx(), | ||
| { | ||
| name: 'lynx:testing-library:plugin', | ||
| setup(api) { | ||
| api.modifyBundlerChain((chain, { CHAIN_ID }) => { | ||
| const rule = chain.module.rules.get(CHAIN_ID.RULE.JS); | ||
| const swcUse = rule.uses.entries().swc; | ||
| const originalOptions = swcUse.get('options') || {}; | ||
| const newOptions = { | ||
| ...originalOptions, | ||
| jsc: { | ||
| ...originalOptions.jsc, | ||
| transform: { | ||
| ...((originalOptions.jsc?.transform) | ||
| || {}), | ||
| // Keep our snapshot consistent with vitest | ||
| // class field will be undefined if not initialized | ||
| useDefineForClassFields: true, | ||
|
colinaaa marked this conversation as resolved.
Outdated
|
||
| }, | ||
| }, | ||
| }; | ||
| swcUse.options(newOptions); | ||
| }); | ||
| }, | ||
| }, | ||
| ] as RsbuildPlugin[], | ||
| source: { | ||
| define: { | ||
| __RSTEST__: '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.js'), | ||
| }, | ||
| }, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/react/testing-library/src/__tests__/auto-cleanup-skip.test.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| import { beforeAll, test, expect } from 'vitest'; | ||
|
|
||
| let render; | ||
|
|
||
| beforeAll(async () => { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.