Skip to content

Commit

Permalink
test: update custom handlers (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Mar 30, 2022
1 parent 2f3c19c commit f01d9b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion test/presets/cloudflare.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { resolve } from 'pathe'
import { Miniflare } from 'miniflare'
import destr from 'destr'
import { describe } from 'vitest'

import { setupTest, testNitro } from '../utils'
Expand All @@ -15,7 +16,7 @@ describe('nitro:preset:cloudflare', () => {
body
})
return {
data: await res.text(),
data: destr(await res.text()),
status: res.status
}
}
Expand Down
5 changes: 3 additions & 2 deletions test/presets/lambda.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { resolve } from 'pathe'
import { describe } from 'vitest'
import destr from 'destr'
import type { APIGatewayProxyEvent, APIGatewayProxyEventV2 } from 'aws-lambda'
import { setupTest, testNitro } from '../utils'

Expand All @@ -22,7 +23,7 @@ describe('nitro:preset:lambda', () => {
}
const res = await handler(event)
return {
data: res.body,
data: destr(res.body),
status: res.statusCode
}
}
Expand Down Expand Up @@ -51,7 +52,7 @@ describe('nitro:preset:lambda', () => {
}
const res = await handler(event)
return {
data: res.body,
data: destr(res.body),
status: res.statusCode
}
}
Expand Down
10 changes: 9 additions & 1 deletion test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ export function testNitro (_ctx, getHandler) {

it('handles errors', async () => {
const { data, status } = await handler({ url: '/api/error' })
expect(data).toMatchInlineSnapshot('"{\\"url\\":\\"/\\",\\"statusCode\\":503,\\"statusMessage\\":\\"Service Unavailable\\",\\"message\\":\\"Service Unavailable\\",\\"description\\":\\"\\"}"')
expect(data).toMatchInlineSnapshot(`
{
"description": "",
"message": "Service Unavailable",
"statusCode": 503,
"statusMessage": "Service Unavailable",
"url": "/",
}
`)
expect(status).toBe(503)
const { data: heyData } = await handler({ url: '/api/hey' })
expect(heyData).to.have.string('Hey API')
Expand Down

0 comments on commit f01d9b8

Please sign in to comment.