test(react-renderer): supports streaming tests (#422)
parent
74dfa07ded
commit
a5e59c4199
|
@ -35,13 +35,15 @@
|
||||||
"hono": "*"
|
"hono": "*"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@cloudflare/vitest-pool-workers": "^0.1.2",
|
||||||
"@types/react": "^18",
|
"@types/react": "^18",
|
||||||
"@types/react-dom": "^18.2.17",
|
"@types/react-dom": "^18.2.17",
|
||||||
|
"esbuild": "^0.20.2",
|
||||||
"hono": "^3.11.7",
|
"hono": "^3.11.7",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"tsup": "^8.0.1",
|
"tsup": "^8.0.1",
|
||||||
"vitest": "^1.0.4"
|
"vitest": "1.3.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { Hono } from 'hono'
|
import { Hono } from 'hono'
|
||||||
|
|
||||||
import { reactRenderer, useRequestContext } from '../src/react-renderer'
|
import { reactRenderer, useRequestContext } from '../src/react-renderer'
|
||||||
|
|
||||||
const RequestUrl = () => {
|
const RequestUrl = () => {
|
||||||
|
@ -107,5 +108,27 @@ describe('Basic', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Streaming', () => {
|
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": {
|
"compilerOptions": {
|
||||||
"target": "ESNext",
|
"target": "ESNext",
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "Bundler",
|
||||||
"rootDir": "./",
|
"rootDir": "./",
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"jsxImportSource": "react"
|
"jsxImportSource": "react"
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
|
"vitest.config.ts",
|
||||||
"src/**/*.ts",
|
"src/**/*.ts",
|
||||||
"test/**/*.tsx",
|
"test/**/*.tsx",
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
/// <reference types="vitest" />
|
import { defineWorkersProject } from '@cloudflare/vitest-pool-workers/config'
|
||||||
import { defineConfig } from 'vitest/config'
|
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineWorkersProject({
|
||||||
test: {
|
test: {
|
||||||
globals: true,
|
globals: true,
|
||||||
|
poolOptions: {
|
||||||
|
workers: {
|
||||||
|
miniflare: {
|
||||||
|
compatibilityDate: '2024-01-01',
|
||||||
|
compatibilityFlags: ['nodejs_compat'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue