-
Notifications
You must be signed in to change notification settings - Fork 43
feat(rstest): add rspack-adapter example #412
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
29af439
feat(rstest): add rspack-adapter example
9aoy e0388ba
Update rstest/rspack-adapter/src/main.tsx
9aoy 5b16128
Update rstest/rspack-adapter/package.json
9aoy d9602c1
Update rstest/rspack-adapter/rspack.config.ts
9aoy 864612a
Update rstest/rspack-adapter/src/App.tsx
9aoy 08ea96e
Update rstest/rspack-adapter/tests/index.test.tsx
9aoy 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,16 @@ | ||
| # Local | ||
| .DS_Store | ||
| *.local | ||
| *.log* | ||
|
|
||
| # Dist | ||
| node_modules | ||
| dist/ | ||
|
|
||
| # Profile | ||
| .rspack-profile-*/ | ||
|
|
||
| # IDE | ||
| .vscode/* | ||
| !.vscode/extensions.json | ||
| .idea |
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,36 @@ | ||
| # Rspack project | ||
|
|
||
| ## Setup | ||
|
|
||
| Install the dependencies: | ||
|
|
||
| ```bash | ||
| npm install | ||
| ``` | ||
|
|
||
| ## Get started | ||
|
|
||
| Start the dev server, and the app will be available at <http://localhost:8080>. | ||
|
|
||
| ```bash | ||
| npm run dev | ||
| ``` | ||
|
|
||
| Build the app for production: | ||
|
|
||
| ```bash | ||
| npm run build | ||
| ``` | ||
|
|
||
| Preview the production build locally: | ||
|
|
||
| ```bash | ||
| npm run preview | ||
| ``` | ||
|
|
||
| ## Learn more | ||
|
|
||
| To learn more about Rspack, check out the following resources: | ||
|
|
||
| - [Rspack documentation](https://rspack.rs) - explore Rspack features and APIs. | ||
| - [Rspack GitHub repository](https://github.com/web-infra-dev/rspack) - your feedback and contributions are welcome! |
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,12 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <link rel="icon" type="image/svg+xml" href="/react.svg" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Rspack + React + TS</title> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| </body> | ||
| </html> |
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,33 @@ | ||
| { | ||
| "name": "@rstest-example/rspack-adapter", | ||
| "private": true, | ||
| "version": "1.0.0", | ||
| "scripts": { | ||
| "build": "rspack build", | ||
| "dev": "rspack dev", | ||
| "preview": "rspack preview", | ||
| "test": "rstest", | ||
| "test:watch": "rstest --watch" | ||
| }, | ||
| "dependencies": { | ||
| "react": "^19.2.4", | ||
| "react-dom": "^19.2.4" | ||
| }, | ||
| "devDependencies": { | ||
| "@rsbuild/plugin-react": "^1.4.5", | ||
| "@rspack/cli": "2.0.0-beta.5", | ||
| "@rspack/core": "2.0.0-beta.5", | ||
| "@rspack/dev-server": "2.0.0-beta.5", | ||
| "@rspack/plugin-react-refresh": "^1.6.1", | ||
| "@rstest/adapter-rspack": "^0.2.0", | ||
| "@rstest/core": "^0.9.1", | ||
| "@testing-library/dom": "^10.4.1", | ||
| "@testing-library/jest-dom": "^6.9.1", | ||
| "@testing-library/react": "^16.3.2", | ||
| "@types/react": "^19.2.14", | ||
| "@types/react-dom": "^19.2.3", | ||
| "happy-dom": "^20.8.3", | ||
| "react-refresh": "^0.18.0", | ||
| "typescript": "^5.9.3" | ||
| } | ||
| } |
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,56 @@ | ||
| import { defineConfig } from '@rspack/cli'; | ||
| import { rspack, type SwcLoaderOptions } from '@rspack/core'; | ||
| import { ReactRefreshRspackPlugin } from '@rspack/plugin-react-refresh'; | ||
|
|
||
| const isDev = process.env.NODE_ENV === 'development'; | ||
|
|
||
| export default defineConfig({ | ||
| entry: { | ||
| main: './src/main.tsx', | ||
| }, | ||
| target: ['browserslist:last 2 versions, > 0.2%, not dead, Firefox ESR'], | ||
| resolve: { | ||
| extensions: ['...', '.ts', '.tsx', '.jsx'], | ||
| }, | ||
| module: { | ||
| rules: [ | ||
| { | ||
| test: /\.svg$/, | ||
| type: 'asset', | ||
| }, | ||
| { | ||
| test: /\.css$/, | ||
| type: 'css/auto', | ||
| }, | ||
| { | ||
| test: /\.(jsx?|tsx?)$/, | ||
| use: [ | ||
| { | ||
| loader: 'builtin:swc-loader', | ||
| options: { | ||
| jsc: { | ||
| parser: { | ||
| syntax: 'typescript', | ||
| tsx: true, | ||
| }, | ||
| transform: { | ||
| react: { | ||
| runtime: 'automatic', | ||
| development: isDev, | ||
| refresh: isDev, | ||
| }, | ||
| }, | ||
| }, | ||
| } satisfies SwcLoaderOptions, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| plugins: [ | ||
| new rspack.HtmlRspackPlugin({ | ||
| template: './index.html', | ||
| }), | ||
| ...(isDev ? [new ReactRefreshRspackPlugin()] : []), | ||
| ], | ||
| }); | ||
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,8 @@ | ||
| import { withRspackConfig } from '@rstest/adapter-rspack'; | ||
| import { defineConfig } from '@rstest/core'; | ||
|
|
||
| // Docs: https://rstest.rs/config/ | ||
| export default defineConfig({ | ||
| extends: withRspackConfig(), | ||
| setupFiles: ['./tests/rstest.setup.ts'], | ||
| }); |
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,41 @@ | ||
| #root { | ||
| max-width: 1280px; | ||
| margin: 0 auto; | ||
| padding: 2rem; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .logo { | ||
| height: 6em; | ||
| padding: 1.5em; | ||
| will-change: filter; | ||
| } | ||
| .logo:hover { | ||
| filter: drop-shadow(0 0 2em #646cffaa); | ||
| } | ||
| .logo.react:hover { | ||
| filter: drop-shadow(0 0 2em #61dafbaa); | ||
| } | ||
|
|
||
| @keyframes logo-spin { | ||
| from { | ||
| transform: rotate(0deg); | ||
| } | ||
| to { | ||
| transform: rotate(360deg); | ||
| } | ||
| } | ||
|
|
||
| @media (prefers-reduced-motion: no-preference) { | ||
| a > .logo { | ||
| animation: logo-spin infinite 20s linear; | ||
| } | ||
| } | ||
|
|
||
| .card { | ||
| padding: 2em; | ||
| } | ||
|
|
||
| .read-the-docs { | ||
| color: #888; | ||
| } |
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,29 @@ | ||
| import { useState } from 'react'; | ||
| import reactLogo from './assets/react.svg'; | ||
| import './App.css'; | ||
|
|
||
| function App() { | ||
| const [count, setCount] = useState(0); | ||
|
|
||
| return ( | ||
| <div className="App"> | ||
| <div> | ||
| <a href="https://react.dev" target="_blank" rel="noreferrer"> | ||
| <img src={reactLogo} className="logo react" alt="React logo" /> | ||
| </a> | ||
| </div> | ||
| <h1>Rspack + React + TypeScript</h1> | ||
| <div className="card"> | ||
| <button type="button" onClick={() => setCount((count) => count + 1)}> | ||
| count is {count} | ||
| </button> | ||
| <p> | ||
| Edit <code>src/App.tsx</code> and save to test HMR | ||
| </p> | ||
| </div> | ||
| <p className="read-the-docs">Click on the Rspack and React logos to learn more</p> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default App; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,70 @@ | ||
| :root { | ||
| font-family: Inter, Avenir, Helvetica, Arial, sans-serif; | ||
| font-size: 16px; | ||
| line-height: 24px; | ||
| font-weight: 400; | ||
|
|
||
| color-scheme: light dark; | ||
| color: rgba(255, 255, 255, 0.87); | ||
| background-color: #242424; | ||
|
|
||
| font-synthesis: none; | ||
| text-rendering: optimizeLegibility; | ||
| -webkit-font-smoothing: antialiased; | ||
| -moz-osx-font-smoothing: grayscale; | ||
| -webkit-text-size-adjust: 100%; | ||
| } | ||
|
|
||
| a { | ||
| font-weight: 500; | ||
| color: #646cff; | ||
| text-decoration: inherit; | ||
| } | ||
| a:hover { | ||
| color: #535bf2; | ||
| } | ||
|
|
||
| body { | ||
| margin: 0; | ||
| display: flex; | ||
| place-items: center; | ||
| min-width: 320px; | ||
| min-height: 100vh; | ||
| } | ||
|
|
||
| h1 { | ||
| font-size: 3.2em; | ||
| line-height: 1.1; | ||
| } | ||
|
|
||
| button { | ||
| border-radius: 8px; | ||
| border: 1px solid transparent; | ||
| padding: 0.6em 1.2em; | ||
| font-size: 1em; | ||
| font-weight: 500; | ||
| font-family: inherit; | ||
| background-color: #1a1a1a; | ||
| cursor: pointer; | ||
| transition: border-color 0.25s; | ||
| } | ||
| button:hover { | ||
| border-color: #646cff; | ||
| } | ||
| button:focus, | ||
| button:focus-visible { | ||
| outline: 4px auto -webkit-focus-ring-color; | ||
| } | ||
|
|
||
| @media (prefers-color-scheme: light) { | ||
| :root { | ||
| color: #213547; | ||
| background-color: #ffffff; | ||
| } | ||
| a:hover { | ||
| color: #747bff; | ||
| } | ||
| button { | ||
| background-color: #f9f9f9; | ||
| } | ||
| } |
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,14 @@ | ||
| import React from 'react'; | ||
| import ReactDOM from 'react-dom/client'; | ||
| import App from './App.tsx'; | ||
| import './index.css'; | ||
|
|
||
| const rootElement = document.getElementById('root'); | ||
| if (!rootElement) { | ||
| throw new Error('Failed to find the root element'); | ||
| } | ||
| ReactDOM.createRoot(rootElement).render( | ||
| <React.StrictMode> | ||
| <App /> | ||
| </React.StrictMode>, | ||
| ); |
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,9 @@ | ||
| import { expect, test } from '@rstest/core'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import App from '../src/App'; | ||
|
|
||
| test('renders the main page', () => { | ||
| const testMessage = 'Rspack + React + TypeScript'; | ||
| render(<App />); | ||
| expect(screen.getByRole('heading', { name: testMessage })).toBeInTheDocument(); | ||
| }); |
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,5 @@ | ||
| import { expect } from '@rstest/core'; | ||
| // biome-ignore lint/performance/noNamespaceImport: jest-dom matchers are consumed as a matcher namespace. | ||
| import * as jestDomMatchers from '@testing-library/jest-dom/matchers'; | ||
|
|
||
| expect.extend(jestDomMatchers); |
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,7 @@ | ||
| { | ||
| "extends": "../tsconfig.json", | ||
| "compilerOptions": { | ||
| "types": ["@testing-library/jest-dom"] | ||
| }, | ||
| "include": ["./"] | ||
| } |
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,22 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "lib": ["DOM", "ES2020"], | ||
| "jsx": "react-jsx", | ||
| "target": "ES2020", | ||
| "noEmit": true, | ||
| "skipLibCheck": true, | ||
| "useDefineForClassFields": true, | ||
|
|
||
| /* modules */ | ||
| "module": "ESNext", | ||
| "resolveJsonModule": true, | ||
| "moduleResolution": "bundler", | ||
| "allowImportingTsExtensions": true, | ||
|
|
||
| /* type checking */ | ||
| "strict": true, | ||
| "noUnusedLocals": true, | ||
| "noUnusedParameters": true | ||
| }, | ||
| "include": ["src"] | ||
| } |
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.