test(react-renderer): supports streaming tests (#422)
parent
74dfa07ded
commit
a5e59c4199
|
@ -35,13 +35,15 @@
|
|||
"hono": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cloudflare/vitest-pool-workers": "^0.1.2",
|
||||
"@types/react": "^18",
|
||||
"@types/react-dom": "^18.2.17",
|
||||
"esbuild": "^0.20.2",
|
||||
"hono": "^3.11.7",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"tsup": "^8.0.1",
|
||||
"vitest": "^1.0.4"
|
||||
"vitest": "1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { Hono } from 'hono'
|
||||
|
||||
import { reactRenderer, useRequestContext } from '../src/react-renderer'
|
||||
|
||||
const RequestUrl = () => {
|
||||
|
@ -107,5 +108,27 @@ describe('Basic', () => {
|
|||
})
|
||||
|
||||
describe('Streaming', () => {
|
||||
it.skip('Vitest does not support Streaming')
|
||||
it('Should return a stream response', async () => {
|
||||
const app = new Hono()
|
||||
app.use(
|
||||
'*',
|
||||
reactRenderer(
|
||||
({ children }) => {
|
||||
return (
|
||||
<html>
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
)
|
||||
},
|
||||
{ stream: true }
|
||||
)
|
||||
)
|
||||
app.get('/', (c) => c.render(<h1>Hello</h1>, { title: 'Title' }))
|
||||
const res = await app.request('/')
|
||||
expect(res).not.toBeNull()
|
||||
expect(res.status).toBe(200)
|
||||
expect(res.headers.get('Transfer-Encoding')).toBe('chunked')
|
||||
expect(res.headers.get('Content-Type')).toBe('text/html; charset=UTF-8')
|
||||
expect(await res.text()).toBe('<!DOCTYPE html><html><body><h1>Hello</h1></body></html>')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -3,13 +3,14 @@
|
|||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "node",
|
||||
"moduleResolution": "Bundler",
|
||||
"rootDir": "./",
|
||||
"outDir": "./dist",
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "react"
|
||||
},
|
||||
"include": [
|
||||
"vitest.config.ts",
|
||||
"src/**/*.ts",
|
||||
"test/**/*.tsx",
|
||||
],
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
/// <reference types="vitest" />
|
||||
import { defineConfig } from 'vitest/config'
|
||||
import { defineWorkersProject } from '@cloudflare/vitest-pool-workers/config'
|
||||
|
||||
export default defineConfig({
|
||||
export default defineWorkersProject({
|
||||
test: {
|
||||
globals: true,
|
||||
poolOptions: {
|
||||
workers: {
|
||||
miniflare: {
|
||||
compatibilityDate: '2024-01-01',
|
||||
compatibilityFlags: ['nodejs_compat'],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue