Skip to content

Commit fd96308

Browse files
authored
test(rsc): test assets (#733)
1 parent fe15467 commit fd96308

File tree

11 files changed

+83
-0
lines changed

11 files changed

+83
-0
lines changed

packages/plugin-rsc/e2e/basic.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,4 +1179,28 @@ function defineTest(f: Fixture) {
11791179
await expect(page.locator(selector)).toHaveCSS('color', color)
11801180
}
11811181
})
1182+
1183+
test('assets', async ({ page }) => {
1184+
await page.goto(f.url())
1185+
await waitForHydration(page)
1186+
await expect(
1187+
page.getByTestId('test-assets-server-import'),
1188+
).not.toHaveJSProperty('naturalWidth', 0)
1189+
await expect(
1190+
page.getByTestId('test-assets-client-import'),
1191+
).not.toHaveJSProperty('naturalWidth', 0)
1192+
1193+
async function testBackgroundImage(selector: string) {
1194+
const url = await page
1195+
.locator(selector)
1196+
.evaluate((el) => getComputedStyle(el).backgroundImage)
1197+
expect(url).toMatch(/^url\(.*\)$/)
1198+
const response = await page.request.get(url.slice(5, -2))
1199+
expect(response.ok()).toBeTruthy()
1200+
expect(response.headers()['content-type']).toBe('image/svg+xml')
1201+
}
1202+
1203+
await testBackgroundImage('.test-assets-server-css')
1204+
await testBackgroundImage('.test-assets-client-css')
1205+
})
11821206
}
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.test-assets-client-css {
2+
background: url(./client-css.svg) no-repeat;
3+
background-size: contain;
4+
width: 20px;
5+
height: 20px;
6+
}
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use client'
2+
3+
import './client.css'
4+
import svg from './client.svg?no-inline'
5+
6+
export function TestAssetsClient() {
7+
return (
8+
<div style={{ display: 'flex', gap: '0.5rem', alignItems: 'center' }}>
9+
<span>test-assets-client</span>
10+
<img
11+
src={svg}
12+
data-testid="test-assets-client-import"
13+
width="20"
14+
height="20"
15+
/>
16+
<span className="test-assets-client-css" />
17+
</div>
18+
)
19+
}
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.test-assets-server-css {
2+
background: url(./server-css.svg) no-repeat;
3+
background-size: contain;
4+
width: 20px;
5+
height: 20px;
6+
}
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { TestAssetsClient } from './client'
2+
import './server.css'
3+
import svg from './server.svg?no-inline'
4+
5+
export function TestAssetsServer() {
6+
return (
7+
<>
8+
<div style={{ display: 'flex', gap: '0.5rem', alignItems: 'center' }}>
9+
<span>test-assets-server</span>
10+
<img
11+
src={svg}
12+
data-testid="test-assets-server-import"
13+
width="20"
14+
height="20"
15+
/>
16+
<span className="test-assets-server-css" />
17+
</div>
18+
<TestAssetsClient />
19+
</>
20+
)
21+
}

packages/plugin-rsc/examples/basic/src/routes/root.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { TestHmrSharedClient } from './hmr-shared/client'
3737
import { TestHmrSharedAtomic } from './hmr-shared/atomic/server'
3838
import { TestCssQueries } from './css-queries/server'
3939
import { TestImportMetaGlob } from './import-meta-glob/server'
40+
import { TestAssetsServer } from './assets/server'
4041

4142
export function Root(props: { url: URL }) {
4243
return (
@@ -87,6 +88,7 @@ export function Root(props: { url: URL }) {
8788
<TestReactCache url={props.url} />
8889
<TestCssQueries />
8990
<TestImportMetaGlob />
91+
<TestAssetsServer />
9092
</body>
9193
</html>
9294
)

0 commit comments

Comments
 (0)