Skip to content

Commit

Permalink
chore: add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
shulaoda committed Dec 12, 2024
1 parent be7df7a commit 0d84d54
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
13 changes: 12 additions & 1 deletion playground/proxy-bypass/__tests__/proxy-bypass.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { expect, test, vi } from 'vitest'
import { browserLogs } from '~utils'
import { browserLogs, page, serverLogs } from '~utils'

test('proxy-bypass', async () => {
await vi.waitFor(() => {
expect(browserLogs.join('\n')).toContain('status of 404 (Not Found)')
})
})

test('async-proxy-bypass', async () => {
const content = await page.frame('async-response').content()
expect(content).toContain('Hello after 4 ms (async timeout)')
})

test('async-proxy-bypass-with-error', async () => {
await vi.waitFor(() => {
expect(serverLogs.join('\n')).toContain('bypass error')
})
})
2 changes: 2 additions & 0 deletions playground/proxy-bypass/index.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
root app<br />
<iframe src="/nonExistentApp" style="border: 0"></iframe>
<iframe src="/asyncResponse" name="async-response"></iframe>
<iframe src="/asyncThrowingError"></iframe>
18 changes: 18 additions & 0 deletions playground/proxy-bypass/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { defineConfig } from 'vite'

const timeout = (ms) => new Promise((r) => setTimeout(r, ms))

export default defineConfig({
server: {
port: 9606,
Expand All @@ -10,6 +12,22 @@ export default defineConfig({
return false
},
},
'/asyncResponse': {
bypass: async (_, res) => {
await timeout(4)
res.writeHead(200, {
'Content-Type': 'text/plain',
})
res.end('Hello after 4 ms (async timeout)')
return '/asyncResponse'
},
},
'/asyncThrowingError': {
bypass: async () => {
await timeout(4)
throw new Error('bypass error')
},
},
},
},
})

0 comments on commit 0d84d54

Please sign in to comment.