Skip to content

Commit 483e40b

Browse files
committed
test: add e2e
1 parent 89a1aea commit 483e40b

3 files changed

Lines changed: 72 additions & 1 deletion

File tree

packages/plugin-rsc/e2e/fixture.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export async function setupInlineFixture(options: {
217217
let filepath = path.join(options.dest, filename)
218218
fs.mkdirSync(path.dirname(filepath), { recursive: true })
219219
// strip indent
220-
contents = contents.replace(/^\n/, '')
220+
contents = contents.replace(/^\n*/, '').replace(/\s*$/, '\n')
221221
const indent = contents.match(/^\s*/)?.[0] ?? ''
222222
const strippedContents = contents
223223
.split('\n')

packages/plugin-rsc/e2e/helper.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,15 @@ export async function expectNoReload(page: Page) {
4242
},
4343
}
4444
}
45+
46+
export function expectNoPageError(page: Page) {
47+
const errors: Error[] = []
48+
page.on('pageerror', (error) => {
49+
errors.push(error)
50+
})
51+
return {
52+
[Symbol.dispose]: () => {
53+
expect(errors).toEqual([])
54+
},
55+
}
56+
}

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect, test } from '@playwright/test'
22
import { setupInlineFixture, type Fixture, useFixture } from './fixture'
33
import {
4+
expectNoPageError,
45
expectNoReload,
56
testNoJs,
67
waitForHydration as waitForHydration_,
@@ -203,6 +204,64 @@ test.describe(() => {
203204
})
204205
})
205206

207+
test.describe(() => {
208+
const root = 'examples/e2e/temp/ssr-thenable'
209+
210+
test.beforeAll(async () => {
211+
await setupInlineFixture({
212+
src: 'examples/starter',
213+
dest: root,
214+
files: {
215+
'src/root.tsx': /* tsx */ `
216+
import { TestClientUse } from './client.tsx'
217+
218+
export function Root() {
219+
return (
220+
<html lang="en">
221+
<head>
222+
<meta charSet="UTF-8" />
223+
</head>
224+
<body>
225+
<TestClientUse />
226+
</body>
227+
</html>
228+
)
229+
}
230+
`,
231+
'src/client.tsx': /* tsx */ `
232+
"use client";
233+
import React from 'react'
234+
235+
const promise = Promise.resolve('ok')
236+
237+
export function TestClientUse() {
238+
const value = React.use(promise)
239+
return <span data-testid="client-use">{value}</span>
240+
}
241+
`,
242+
},
243+
})
244+
})
245+
246+
function defineSsrThenableTest(f: Fixture) {
247+
test('ssr-thenable', async ({ page }) => {
248+
using _ = expectNoPageError(page)
249+
await page.goto(f.url())
250+
await waitForHydration_(page)
251+
})
252+
}
253+
254+
test.describe('dev', () => {
255+
const f = useFixture({ root, mode: 'dev' })
256+
defineSsrThenableTest(f)
257+
})
258+
259+
test.describe('build', () => {
260+
const f = useFixture({ root, mode: 'build' })
261+
defineSsrThenableTest(f)
262+
})
263+
})
264+
206265
function defineTest(f: Fixture, variant?: 'no-ssr') {
207266
const waitForHydration: typeof waitForHydration_ = (page) =>
208267
waitForHydration_(page, variant === 'no-ssr' ? '#root' : 'body')

0 commit comments

Comments
 (0)