middleware
middleware copied to clipboard
Test Suite in OpenAPI Hono Won't Compile
Running Jest on the original Hono works fine
import { Hono } from "hono";
const app = new Hono();
results in an expected failure (endpoint not setup):
Simply converting to OpenAPIHono causes tests to not compile successfully:
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
const app = new OpenAPIHono();
Details:
/Users/bram/Dropbox/PARA/Projects/cf-gpts-quickstart/node_modules/yaml/browser/index.js:3
import * as YAML from './dist/index.js'
^^^^^^
SyntaxError: Cannot use import statement outside a module
it seems that one of the node_modules, yaml is failing to mock.
Jest config is the same across both runs:
module.exports = {
testEnvironment: 'miniflare',
testMatch: ['**/test/**/*.+(ts|tsx)', '**/src/**/(*.)+(spec|test).+(ts|tsx)'],
transform: {
'^.+\\.(ts|tsx)$': 'esbuild-jest',
},
transformIgnorePatterns: ['/node_modules/'],
}
same with tsconfig:
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true,
"lib": [
"esnext"
],
"types": [
"@cloudflare/workers-types",
"jest"
],
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx"
},
}
Hi @bramses
This jest issue is troublesome. If possible, please try using vitest. It might not cause the error.
@yusukebe ok ill try it and let you know. Is OpenAPIHono built on Vite?
@bramses
Is
OpenAPIHonobuilt on Vite?
No. But, it uses esbuild which is also used in Vite.