Skip to content

Commit

Permalink
test(e2e): add case for SVG dynamic import (#1784)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Mar 11, 2024
1 parent 6683ffb commit 16cb530
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
25 changes: 25 additions & 0 deletions e2e/cases/svg/svgr-query-react-dynamic-import/index.test.ts
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();
});
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()],
});
12 changes: 12 additions & 0 deletions e2e/cases/svg/svgr-query-react-dynamic-import/src/App.jsx
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 e2e/cases/svg/svgr-query-react-dynamic-import/src/index.js
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();
3 changes: 3 additions & 0 deletions e2e/cases/svg/svgr-query-react-dynamic-import/src/small.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 16cb530

Please sign in to comment.