-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(e2e): add case for SVG dynamic import (#1784)
- Loading branch information
1 parent
6683ffb
commit 16cb530
Showing
5 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
e2e/cases/svg/svgr-query-react-dynamic-import/index.test.ts
This file contains 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,25 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { build, gotoPage } from '@e2e/helper'; | ||
|
||
// https://github.com/web-infra-dev/rsbuild/issues/1766 | ||
test('should import default from SVG with react query and dynamic import correctly', async ({ | ||
page, | ||
}) => { | ||
const rsbuild = await build({ | ||
cwd: __dirname, | ||
runServer: true, | ||
}); | ||
|
||
await gotoPage(page, rsbuild); | ||
|
||
await expect( | ||
page.evaluate(`document.getElementById('component').tagName === 'svg'`), | ||
).resolves.toBeTruthy(); | ||
|
||
// test svg asset | ||
await expect( | ||
page.evaluate(`document.getElementById('url').src`), | ||
).resolves.toMatch(/http:/); | ||
|
||
await rsbuild.close(); | ||
}); |
7 changes: 7 additions & 0 deletions
7
e2e/cases/svg/svgr-query-react-dynamic-import/rsbuild.config.ts
This file contains 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 @@ | ||
import { defineConfig } from '@rsbuild/core'; | ||
import { pluginReact } from '@rsbuild/plugin-react'; | ||
import { pluginSvgr } from '@rsbuild/plugin-svgr'; | ||
|
||
export default defineConfig({ | ||
plugins: [pluginReact(), pluginSvgr()], | ||
}); |
This file contains 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 @@ | ||
export async function getApp() { | ||
const name = 'small'; | ||
const { default: Component } = await import(`./${name}.svg?react`); | ||
const { default: url } = await import(`./${name}.svg?url`); | ||
|
||
return () => ( | ||
<div> | ||
<Component id="component" /> | ||
<img id="url" src={url} alt="url" /> | ||
</div> | ||
); | ||
} |
14 changes: 14 additions & 0 deletions
14
e2e/cases/svg/svgr-query-react-dynamic-import/src/index.js
This file contains 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 { createRoot } from 'react-dom/client'; | ||
import { getApp } from './App'; | ||
|
||
async function main() { | ||
const container = document.getElementById('root'); | ||
if (container) { | ||
const App = await getApp(); | ||
const root = createRoot(container); | ||
root.render(React.createElement(App)); | ||
} | ||
} | ||
|
||
main(); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.