Skip to content

Commit

Permalink
test: refactor integration tests (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe authored Jun 16, 2024
1 parent ccb5fdf commit 9dc714d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 152 deletions.
43 changes: 15 additions & 28 deletions test-integration/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,39 @@ describe('Basic', () => {
})

it('Should have correct routes', () => {
const routes = [
{ path: '/*', method: 'ALL', handler: expect.anything() }, // ShareContext
{ path: '/*', method: 'ALL', handler: expect.anything() },
{
path: '/about/*',
method: 'ALL',
handler: expect.anything(),
},

const routes: { path: string; method: string }[] = [
{
path: '/about/:name',
method: 'GET',
handler: expect.anything(),
},
{
path: '/about/:name/address',
method: 'GET',
handler: expect.anything(),
},
{
path: '/middleware/*',
method: 'ALL',
handler: expect.anything(),
},
{
path: '/middleware/*',
method: 'ALL',
handler: expect.anything(),
},
{
path: '/middleware',
method: 'GET',
handler: expect.anything(),
},
{
path: '/middleware/foo',
method: 'GET',
handler: expect.anything(),
},
{ path: '/*', method: 'ALL', handler: expect.anything() },
{ path: '/', method: 'GET', handler: expect.anything() },
{ path: '/foo', method: 'GET', handler: expect.anything() },
{ path: '/', method: 'GET' },
{ path: '/foo', method: 'GET' },
]

expect(app.routes).toHaveLength(routes.length)
expect(app.routes).toEqual(expect.arrayContaining(routes))
expect(app.routes).toHaveLength(routes.length * 2)
expect(app.routes).toEqual(
expect.arrayContaining(
routes.map(({ path, method }) => {
return {
path,
method,
handler: expect.any(Function),
}
})
)
)
})

it('Should return 200 response - / with a Powered By header', async () => {
Expand Down
140 changes: 16 additions & 124 deletions test-integration/apps.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { poweredBy } from 'hono/powered-by'
import { describe, expect, it, vi } from 'vitest'
import { createApp } from '../src/server'

describe('Basic', () => {
Expand All @@ -17,206 +16,99 @@ describe('Basic', () => {
})

it('Should have correct routes', () => {
const routes = [
const routes: { path: string; method: string }[] = [
{
path: '/*',
method: 'ALL',
handler: expect.any(Function), // ShareContext
},
{
path: '/*',
method: 'ALL',
handler: expect.any(Function),
},
{
path: '/about/:name/address',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/about/:name/address',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/about/:name',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/about/:name',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/about/:name',
method: 'POST',
handler: expect.any(Function),
},
{
path: '/about/:name',
method: 'POST',
handler: expect.any(Function),
},
{
path: '/non-interactive',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/non-interactive',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/interaction',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/interaction',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/interaction/anywhere',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/interaction/anywhere',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/interaction/children',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/interaction/children',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/interaction/error-boundary',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/interaction/error-boundary',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/interaction/suspense-never',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/interaction/suspense-never',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/interaction/suspense',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/interaction/suspense',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/interaction/suspense-islands',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/interaction/suspense-islands',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/interaction/nested',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/interaction/nested',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/directory',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/directory',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/directory/throw_error',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/directory/throw_error',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/directory/sub/throw_error',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/directory/sub/throw_error',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/fc',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/fc',
method: 'GET',
handler: expect.any(Function),
},
{ path: '/api', method: 'POST', handler: expect.any(Function) },
{ path: '/api', method: 'POST', handler: expect.any(Function) },
{ path: '/api', method: 'GET', handler: expect.any(Function) },
{ path: '/api', method: 'GET', handler: expect.any(Function) },
{ path: '/', method: 'GET', handler: expect.any(Function) },
{ path: '/', method: 'GET', handler: expect.any(Function) },
{ path: '/api', method: 'POST' },
{ path: '/api', method: 'GET' },
{ path: '/', method: 'GET' },
{
path: '/post',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/post',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/throw_error',
method: 'GET',
handler: expect.any(Function),
},
{
path: '/throw_error',
method: 'GET',
handler: expect.any(Function),
},
]
expect(app.routes).toHaveLength(routes.length)
expect(app.routes).toEqual(expect.arrayContaining(routes))
expect(app.routes).toHaveLength(routes.length * 2)
expect(app.routes).toEqual(
expect.arrayContaining(
routes.map(({ path, method }) => {
return {
path,
method,
handler: expect.any(Function),
}
})
)
)
})

it('Should return 200 response - / with a Powered By header', async () => {
Expand Down
3 changes: 3 additions & 0 deletions test-integration/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const appDir = '/mocks'
const islandDir = '/mocks/[^/]+/islands'

export default defineConfig({
test: {
globals: true,
},
resolve: {
alias: {
'@': path.resolve(__dirname, '../mocks/app-alias'),
Expand Down

0 comments on commit 9dc714d

Please sign in to comment.