mirror of
https://github.com/honojs/hono.git
synced 2024-11-22 11:17:33 +01:00
test: Use vitest for fastly compute testing (#1828)
* use vitest for fastly compute testing * reflect reviews and solve problem * chore: update comment * run lint:fix
This commit is contained in:
parent
77bc4416d9
commit
7a55399bc2
@ -13,7 +13,7 @@
|
||||
"test": "tsc --noEmit && vitest --run",
|
||||
"test:deno": "env NAME=Deno deno test --allow-read --allow-env runtime_tests/deno && deno test --no-lock -c runtime_tests/deno-jsx/deno.precompile.json runtime_tests/deno-jsx && deno test --no-lock -c runtime_tests/deno-jsx/deno.react-jsx.json runtime_tests/deno-jsx",
|
||||
"test:bun": "env NAME=Bun bun test --jsx-import-source ../../src/jsx runtime_tests/bun/index.test.tsx",
|
||||
"test:fastly": "jest --config ./runtime_tests/fastly/jest.config.js",
|
||||
"test:fastly": "vitest --run --config ./runtime_tests/fastly/vitest.config.ts",
|
||||
"test:lagon": "start-server-and-test \"lagon dev runtime_tests/lagon/index.ts -e runtime_tests/lagon/.env.lagon\" http://127.0.0.1:1234 \"yarn vitest --run runtime_tests/lagon/index.test.ts --config runtime_tests/lagon/vitest.config.ts\"",
|
||||
"test:node": "env NAME=Node vitest --run --config ./runtime_tests/node/vitest.config.ts",
|
||||
"test:wrangler": "vitest --run --config ./runtime_tests/wrangler/vitest.config.ts",
|
||||
@ -446,7 +446,6 @@
|
||||
"@hono/node-server": "^1.3.3",
|
||||
"@types/crypto-js": "^4.1.1",
|
||||
"@types/glob": "^8.0.0",
|
||||
"@types/jest": "^29.4.0",
|
||||
"@types/jsdom": "^21.1.4",
|
||||
"@types/node": "^20.8.2",
|
||||
"@types/node-fetch": "^2.6.2",
|
||||
@ -458,8 +457,6 @@
|
||||
"esbuild": "^0.15.12",
|
||||
"eslint": "^8.55.0",
|
||||
"form-data": "^4.0.0",
|
||||
"jest": "^29.6.4",
|
||||
"jest-preset-fastly-js-compute": "^1.3.0",
|
||||
"jsdom": "^22.1.0",
|
||||
"msw": "^1.0.0",
|
||||
"node-fetch": "2",
|
||||
@ -472,6 +469,7 @@
|
||||
"ts-jest": "^29.1.1",
|
||||
"tsx": "^3.11.0",
|
||||
"typescript": "^5.3.3",
|
||||
"vite-plugin-fastly-js-compute": "^0.4.2",
|
||||
"vitest": "^0.34.3",
|
||||
"wrangler": "3.17.1",
|
||||
"zod": "^3.20.2"
|
||||
|
@ -88,7 +88,11 @@ describe('Basic Auth Middleware with `hashFunction`', () => {
|
||||
describe('JWT Auth Middleware does not work', () => {
|
||||
const app = new Hono()
|
||||
|
||||
it('Should throw error', () => {
|
||||
// Since nodejs 20 or later, global WebCrypto object becomes stable (experimental on nodejs 18)
|
||||
// but WebCrypto does not have compatibility with Fastly Compute runtime (lacking some objects/methods in Fastly)
|
||||
// so following test should run only be polyfill-ed via vite-plugin-fastly-js-compute plugin.
|
||||
// To confirm polyfill-ed or not, check __fastlyComputeNodeDefaultCrypto field is true.
|
||||
it.runIf(!globalThis.__fastlyComputeNodeDefaultCrypto)('Should throw error', () => {
|
||||
expect(() => {
|
||||
app.use('/jwt/*', jwt({ secret: 'secret' }))
|
||||
}).toThrow(/`crypto.subtle.importKey` is undefined/)
|
||||
|
@ -1,8 +0,0 @@
|
||||
export default {
|
||||
testMatch: ['**/runtime_tests/fastly/**/*.+(ts|tsx|js)'],
|
||||
transform: {
|
||||
'^.+\\.(ts|tsx)$': 'ts-jest',
|
||||
},
|
||||
preset: 'jest-preset-fastly-js-compute/typescript/esm',
|
||||
testPathIgnorePatterns: ['jest.config.js'],
|
||||
}
|
12
runtime_tests/fastly/vitest.config.ts
Normal file
12
runtime_tests/fastly/vitest.config.ts
Normal file
@ -0,0 +1,12 @@
|
||||
/// <reference types="vitest" />
|
||||
import fastlyCompute from 'vite-plugin-fastly-js-compute'
|
||||
import { defineConfig } from 'vitest/config'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [fastlyCompute()],
|
||||
test: {
|
||||
globals: true,
|
||||
include: ['**/runtime_tests/fastly/**/(*.)+(test).+(ts|tsx)'],
|
||||
exclude: ['**/runtime_tests/fastly/vitest.config.ts'],
|
||||
},
|
||||
})
|
Loading…
Reference in New Issue
Block a user