Skip to content

Commit 4f9bb1d

Browse files
test: move tests to src directory (#1075)
* test(react-renderer): move tests to src directory * test: move tests to src directory * test: ensure vitest-pool-workers is installed at the root
1 parent 5fac2ef commit 4f9bb1d

File tree

38 files changed

+129
-120
lines changed

38 files changed

+129
-120
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"devDependencies": {
6161
"@changesets/changelog-github": "^0.4.8",
6262
"@changesets/cli": "^2.26.0",
63+
"@cloudflare/vitest-pool-workers": "^0.7.8",
6364
"@cloudflare/workers-types": "^4.20230307.0",
6465
"@ryoppippi/unplugin-typia": "^1.2.0",
6566
"@types/node": "^20.14.8",

packages/ajv-validator/test/index.test.ts renamed to packages/ajv-validator/src/index.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { JSONSchemaType, type ErrorObject } from 'ajv'
22
import { Hono } from 'hono'
33
import type { Equal, Expect } from 'hono/utils/types'
4-
import { ajvValidator } from '../src'
4+
import { ajvValidator } from '.'
55

66
type ExtractSchema<T> = T extends Hono<infer _, infer S> ? S : never
77

@@ -193,7 +193,7 @@ describe('With Hook', () => {
193193
{
194194
keyword: 'required',
195195
instancePath: '',
196-
message: 'must have required property \'title\'',
196+
message: "must have required property 'title'",
197197
},
198198
])
199199
})

packages/auth-js/test/index.test.ts renamed to packages/auth-js/src/index.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type { Adapter } from '@auth/core/adapters'
33
import Credentials from '@auth/core/providers/credentials'
44
import { Hono } from 'hono'
55
import { describe, expect, it, vi } from 'vitest'
6-
import type { AuthConfig } from '../src'
7-
import { authHandler, verifyAuth, initAuthConfig, reqWithEnvUrl } from '../src'
6+
import type { AuthConfig } from '.'
7+
import { authHandler, verifyAuth, initAuthConfig, reqWithEnvUrl } from '.'
88

99
describe('Config', () => {
1010
it('Should return 500 if AUTH_SECRET is missing', async () => {

packages/casbin/test/index.test.ts renamed to packages/casbin/src/index.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { Hono } from 'hono'
33
import { basicAuth } from 'hono/basic-auth'
44
import { jwt, sign } from 'hono/jwt'
55
import { describe, it, expect } from 'vitest'
6-
import { casbin } from '../src'
7-
import { basicAuthorizer, jwtAuthorizer } from '../src/helper'
6+
import { basicAuthorizer, jwtAuthorizer } from './helper'
7+
import { casbin } from '.'
88

99
describe('Casbin Middleware Tests', () => {
1010
describe('BasicAuthorizer', () => {

packages/class-validator/test/index.test.ts renamed to packages/class-validator/src/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IsInt, IsString, ValidateNested } from 'class-validator'
44
import { Hono } from 'hono'
55
import type { ExtractSchema } from 'hono/types'
66
import type { Equal, Expect } from 'hono/utils/types'
7-
import { classValidator } from '../src'
7+
import { classValidator } from '.'
88

99
describe('Basic', () => {
1010
const app = new Hono()

packages/cloudflare-access/src/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { describe, expect, it, vi } from 'vitest'
33

44
import crypto from 'crypto'
55
import { promisify } from 'util'
6-
import { cloudflareAccess } from '../src'
6+
import { cloudflareAccess } from '.'
77

88
const generateKeyPair = promisify(crypto.generateKeyPair)
99

packages/conform-validator/test/common.test.ts renamed to packages/conform-validator/src/common.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { parseWithZod } from '@conform-to/zod'
22
import { Hono } from 'hono'
33
import { z } from 'zod'
4-
import { conformValidator } from '../src'
4+
import { conformValidator } from '.'
55

66
describe('Validate common processing', () => {
77
const app = new Hono()

packages/conform-validator/test/hook.test.ts renamed to packages/conform-validator/src/hook.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Hono } from 'hono'
33
import { hc } from 'hono/client'
44
import { vi } from 'vitest'
55
import * as z from 'zod'
6-
import { conformValidator } from '../src'
6+
import { conformValidator } from '.'
77

88
describe('Validate the hook option processing', () => {
99
const app = new Hono()

packages/conform-validator/test/valibot.test.ts renamed to packages/conform-validator/src/valibot.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ExtractSchema, ParsedFormValue } from 'hono/types'
55
import type { StatusCode } from 'hono/utils/http-status'
66
import type { Equal, Expect } from 'hono/utils/types'
77
import * as v from 'valibot'
8-
import { conformValidator } from '../src'
8+
import { conformValidator } from '.'
99

1010
describe('Validate requests using a Valibot schema', () => {
1111
const app = new Hono()

packages/conform-validator/test/yup.test.ts renamed to packages/conform-validator/src/yup.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ExtractSchema, ParsedFormValue } from 'hono/types'
55
import type { StatusCode } from 'hono/utils/http-status'
66
import type { Equal, Expect } from 'hono/utils/types'
77
import * as y from 'yup'
8-
import { conformValidator } from '../src'
8+
import { conformValidator } from '.'
99

1010
describe('Validate requests using a Yup schema', () => {
1111
const app = new Hono()

packages/conform-validator/test/zod.test.ts renamed to packages/conform-validator/src/zod.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ExtractSchema, ParsedFormValue } from 'hono/types'
55
import type { StatusCode } from 'hono/utils/http-status'
66
import type { Equal, Expect } from 'hono/utils/types'
77
import * as z from 'zod'
8-
import { conformValidator } from '../src'
8+
import { conformValidator } from '.'
99

1010
describe('Validate requests using a Zod schema', () => {
1111
const app = new Hono()

packages/effect-validator/test/index.test.ts renamed to packages/effect-validator/src/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Schema as S } from 'effect'
22
import { Hono } from 'hono'
33
import type { StatusCode } from 'hono/utils/http-status'
44
import type { Equal, Expect } from 'hono/utils/types'
5-
import { effectValidator } from '../src'
5+
import { effectValidator } from '.'
66

77
// eslint-disable-next-line @typescript-eslint/no-unused-vars
88
type ExtractSchema<T> = T extends Hono<infer _, infer S> ? S : never

packages/esbuild-transpiler/test/node.test.ts renamed to packages/esbuild-transpiler/src/transpilers/node.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Hono } from 'hono'
22
import { describe, it, expect } from 'vitest'
3-
import { esbuildTranspiler } from '../src/transpilers/node'
3+
import { esbuildTranspiler } from './node'
44

55
const TS = 'function add(a: number, b: number) { return a + b; }'
66
const BAD = 'function { !!! !@#$ add(a: INT) return a + b + c; }'

packages/firebase-auth/test/index.test.ts renamed to packages/firebase-auth/src/index.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { setCookie } from 'hono/cookie'
66
import { HTTPException } from 'hono/http-exception'
77
import { Miniflare } from 'miniflare'
88
import { describe, it, expect, beforeAll, vi } from 'vitest'
9-
import type { VerifyFirebaseAuthEnv } from '../src'
10-
import { verifyFirebaseAuth, getFirebaseToken, verifySessionCookieFirebaseAuth } from '../src'
9+
import type { VerifyFirebaseAuthEnv } from '.'
10+
import { verifyFirebaseAuth, getFirebaseToken, verifySessionCookieFirebaseAuth } from '.'
1111

1212
describe('verifyFirebaseAuth middleware', () => {
1313
const emulatorHost = '127.0.0.1:9099'

packages/hello/src/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Hono } from 'hono'
2-
import { hello } from '../src'
2+
import { hello } from '.'
33

44
describe('Hello middleware', () => {
55
const app = new Hono()

packages/medley-router/src/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Hono } from 'hono'
2-
import { MedleyRouter } from '../src'
2+
import { MedleyRouter } from '.'
33

44
describe('Basic', () => {
55
const app = new Hono({ router: new MedleyRouter() })

packages/oauth-providers/test/handlers.ts renamed to packages/oauth-providers/mocks.ts

+26-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import type { DefaultBodyType, StrictResponse } from 'msw'
22
import { HttpResponse, http } from 'msw'
33

4-
import type { DiscordErrorResponse, DiscordTokenResponse } from '../src/providers/discord'
4+
import type { DiscordErrorResponse, DiscordTokenResponse } from './src/providers/discord'
55
import type {
66
FacebookErrorResponse,
77
FacebookTokenResponse,
88
FacebookUser,
9-
} from '../src/providers/facebook'
10-
import type { GitHubErrorResponse, GitHubTokenResponse } from '../src/providers/github'
11-
import type { GoogleErrorResponse, GoogleTokenResponse, GoogleUser } from '../src/providers/google'
12-
import type { LinkedInErrorResponse, LinkedInTokenResponse } from '../src/providers/linkedin'
13-
import type { TwitchErrorResponse, TwitchTokenResponse, TwitchTokenSuccess } from '../src/providers/twitch'
14-
import type { XErrorResponse, XRevokeResponse, XTokenResponse } from '../src/providers/x'
9+
} from './src/providers/facebook'
10+
import type { GitHubErrorResponse, GitHubTokenResponse } from './src/providers/github'
11+
import type { GoogleErrorResponse, GoogleTokenResponse, GoogleUser } from './src/providers/google'
12+
import type { LinkedInErrorResponse, LinkedInTokenResponse } from './src/providers/linkedin'
13+
import type {
14+
TwitchErrorResponse,
15+
TwitchTokenResponse,
16+
TwitchTokenSuccess,
17+
} from './src/providers/twitch'
18+
import type { XErrorResponse, XRevokeResponse, XTokenResponse } from './src/providers/x'
1519

1620
export const handlers = [
1721
// Google
@@ -150,7 +154,9 @@ export const handlers = [
150154
// Twitch
151155
http.post(
152156
'https://id.twitch.tv/oauth2/token',
153-
async ({ request }): Promise<StrictResponse<Partial<TwitchTokenResponse> | TwitchErrorResponse>> => {
157+
async ({
158+
request,
159+
}): Promise<StrictResponse<Partial<TwitchTokenResponse> | TwitchErrorResponse>> => {
154160
const params = new URLSearchParams(await request.text())
155161
const code = params.get('code')
156162
const grant_type = params.get('grant_type')
@@ -174,25 +180,29 @@ export const handlers = [
174180
const params = new URLSearchParams(await request.text())
175181
const token = params.get('token')
176182
if (token === 'wrong-token') {
177-
return HttpResponse.json<{ status: number; message?: string }>(twitchRevokeTokenError, { status: 400 })
183+
return HttpResponse.json<{ status: number; message?: string }>(twitchRevokeTokenError, {
184+
status: 400,
185+
})
178186
}
179187
return HttpResponse.json<null>(null, { status: 200 }) // Return 200 with empty body
180188
}
181189
),
182190
// Twitch validate token handler
183191
http.get(
184192
'https://id.twitch.tv/oauth2/validate',
185-
async ({ request }): Promise<StrictResponse<typeof twitchValidateSuccess | typeof twitchValidateError>> => {
193+
async ({
194+
request,
195+
}): Promise<StrictResponse<typeof twitchValidateSuccess | typeof twitchValidateError>> => {
186196
const authHeader = request.headers.get('authorization')
187197
if (!authHeader || !authHeader.startsWith('Bearer ')) {
188198
return HttpResponse.json(twitchValidateError, { status: 401 })
189199
}
190-
200+
191201
const token = authHeader.split(' ')[1]
192202
if (token === 'twitchr4nd0m4cc3sst0k3n') {
193203
return HttpResponse.json(twitchValidateSuccess)
194204
}
195-
205+
196206
return HttpResponse.json(twitchValidateError, { status: 401 })
197207
}
198208
),
@@ -509,7 +519,8 @@ export const twitchUser = {
509519
type: '',
510520
broadcaster_type: 'partner',
511521
description: 'Supporting third-party developers building Twitch integrations',
512-
profile_image_url: 'https://static-cdn.jtvnw.net/jtv_user_pictures/example-profile-picture.png',
522+
profile_image_url:
523+
'https://static-cdn.jtvnw.net/jtv_user_pictures/example-profile-picture.png',
513524
offline_image_url: 'https://static-cdn.jtvnw.net/jtv_user_pictures/example-offline-image.png',
514525
view_count: 5980557,
515526
@@ -540,10 +551,10 @@ export const twitchValidateSuccess = {
540551
login: 'younis',
541552
scopes: ['user:read:email', 'channel:read:subscriptions', 'bits:read'],
542553
user_id: '12345678',
543-
expires_in: 14400
554+
expires_in: 14400,
544555
}
545556

546557
export const twitchValidateError = {
547558
status: 401,
548-
message: 'invalid access token'
559+
message: 'invalid access token',
549560
}

packages/oauth-providers/test/index.test.ts renamed to packages/oauth-providers/src/index.test.ts

+35-39
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
11
import { Hono } from 'hono'
22
import { setupServer } from 'msw/node'
3-
import type { DiscordUser } from '../src/providers/discord'
4-
import {
5-
discordAuth,
6-
refreshToken as discordRefresh,
7-
revokeToken as discordRevoke,
8-
} from '../src/providers/discord'
9-
import { facebookAuth } from '../src/providers/facebook'
10-
import type { FacebookUser } from '../src/providers/facebook'
11-
import { githubAuth } from '../src/providers/github'
12-
import type { GitHubUser } from '../src/providers/github'
13-
import { googleAuth } from '../src/providers/google'
14-
import type { GoogleUser } from '../src/providers/google'
15-
import { linkedinAuth } from '../src/providers/linkedin'
16-
import type { LinkedInUser } from '../src/providers/linkedin'
17-
import type { TwitchUser } from '../src/providers/twitch'
18-
import {
19-
twitchAuth,
20-
refreshToken as twitchRefresh,
21-
revokeToken as twitchRevoke,
22-
validateToken as twitchValidate
23-
} from '../src/providers/twitch'
24-
import type { XUser } from '../src/providers/x'
25-
import { refreshToken, revokeToken, xAuth } from '../src/providers/x'
26-
import type { Token } from '../src/types'
273
import {
284
discordCodeError,
295
discordRefreshToken,
@@ -57,7 +33,31 @@ import {
5733
twitchUser,
5834
twitchValidateSuccess,
5935
twitchValidateError,
60-
} from './handlers'
36+
} from '../mocks'
37+
import type { DiscordUser } from './providers/discord'
38+
import {
39+
discordAuth,
40+
refreshToken as discordRefresh,
41+
revokeToken as discordRevoke,
42+
} from './providers/discord'
43+
import { facebookAuth } from './providers/facebook'
44+
import type { FacebookUser } from './providers/facebook'
45+
import { githubAuth } from './providers/github'
46+
import type { GitHubUser } from './providers/github'
47+
import { googleAuth } from './providers/google'
48+
import type { GoogleUser } from './providers/google'
49+
import { linkedinAuth } from './providers/linkedin'
50+
import type { LinkedInUser } from './providers/linkedin'
51+
import type { TwitchUser } from './providers/twitch'
52+
import {
53+
twitchAuth,
54+
refreshToken as twitchRefresh,
55+
revokeToken as twitchRevoke,
56+
validateToken as twitchValidate,
57+
} from './providers/twitch'
58+
import type { XUser } from './providers/x'
59+
import { refreshToken, revokeToken, xAuth } from './providers/x'
60+
import type { Token } from './types'
6161

6262
const server = setupServer(...handlers)
6363
server.listen()
@@ -405,11 +405,7 @@ describe('OAuth Middleware', () => {
405405
})
406406
})
407407
app.get('/twitch/refresh', async (c) => {
408-
const response = await twitchRefresh(
409-
client_id,
410-
client_secret,
411-
'twitchr4nd0mr3fr3sht0k3n'
412-
)
408+
const response = await twitchRefresh(client_id, client_secret, 'twitchr4nd0mr3fr3sht0k3n')
413409
return c.json(response)
414410
})
415411
app.get('/twitch/refresh/error', async (c) => {
@@ -858,14 +854,14 @@ describe('OAuth Middleware', () => {
858854
})
859855

860856
describe('twitchAuth middleware', () => {
861-
it('Should work with custom state', async () => {
862-
const res = await app.request('/twitch-custom-state')
863-
expect(res).not.toBeNull()
864-
expect(res.status).toBe(302)
865-
const redirectLocation = res.headers.get('location')!
866-
const redirectUrl = new URL(redirectLocation)
867-
expect(redirectUrl.searchParams.get('state')).toBe('test-state')
868-
})
857+
it('Should work with custom state', async () => {
858+
const res = await app.request('/twitch-custom-state')
859+
expect(res).not.toBeNull()
860+
expect(res.status).toBe(302)
861+
const redirectLocation = res.headers.get('location')!
862+
const redirectUrl = new URL(redirectLocation)
863+
expect(redirectUrl.searchParams.get('state')).toBe('test-state')
864+
})
869865
})
870866

871867
describe('twitchAuth middleware', () => {
@@ -970,7 +966,7 @@ describe('OAuth Middleware', () => {
970966
const res = await twitchValidate('twitchr4nd0m4cc3sst0k3n')
971967
expect(res).toEqual(twitchValidateSuccess)
972968
})
973-
969+
974970
it('Should throw error for invalid token', async () => {
975971
const res = twitchValidate('invalid-token')
976972
await expect(res).rejects.toThrow(twitchValidateError.message)

0 commit comments

Comments
 (0)