honojs / middleware

monorepo for Hono third-party middleware/helpers/wrappers
https://hono.dev
408 stars 141 forks source link

Test Suite in OpenAPI Hono Won't Compile #298

Open bramses opened 9 months ago

bramses commented 9 months ago

Running Jest on the original Hono works fine

import { Hono } from "hono";

const app = new Hono();

results in an expected failure (endpoint not setup):

Screenshot 2023-12-09 20-45-25

Simply converting to OpenAPIHono causes tests to not compile successfully:

import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";

const app = new OpenAPIHono();

Screenshot 2023-12-09 20-48-52

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"
  },
}
yusukebe commented 9 months ago

Hi @bramses

This jest issue is troublesome. If possible, please try using vitest. It might not cause the error.

bramses commented 9 months ago

@yusukebe ok ill try it and let you know. Is OpenAPIHono built on Vite?

yusukebe commented 9 months ago

@bramses

Is OpenAPIHono built on Vite?

No. But, it uses esbuild which is also used in Vite.