Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor integration tests #194

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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