middleware icon indicating copy to clipboard operation
middleware copied to clipboard

Test Suite in OpenAPI Hono Won't Compile

Open bramses opened this issue 2 years ago • 3 comments

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"
  },
}

bramses avatar Dec 10 '23 01:12 bramses

Hi @bramses

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

yusukebe avatar Dec 11 '23 04:12 yusukebe

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

bramses avatar Dec 11 '23 05:12 bramses

@bramses

Is OpenAPIHono built on Vite?

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

yusukebe avatar Dec 11 '23 12:12 yusukebe