honojs / examples

Examples using Hono.
https://hono.dev
609 stars 46 forks source link

Static site and __STATIC_CONTENT_MANIFEST with test framework #109

Closed rustymagnet3000 closed 4 months ago

rustymagnet3000 commented 4 months ago

The static example works great.

import { Hono } from 'hono'

import { serveStatic } from 'hono/cloudflare-workers'
import manifest from '__STATIC_CONTENT_MANIFEST'

const app = new Hono()

app.get('/static/*', serveStatic({ root: './', manifest }))
app.use('/favicon.ico', serveStatic({ path: './favicon.ico', manifest  }))
app.get('/', (c) => c.text('This is Home! You can access: /static/fallback.txt'))

Is there a way to get vitest or jest to stop complaining about __STATIC_CONTENT_MANIFEST?

Error: Failed to load url __STATIC_CONTENT_MANIFEST (resolved id: __STATIC_CONTENT_MANIFEST) in foo.test.js. Does the file exist?
 ❯ loadAndTransform node_modules/vite/dist/node/chunks/dep-C-KAszbv.js:53848:21
yusukebe commented 4 months ago

Hi @rustymagnet3000

I've never tried with __STATIC_CONTENT_MANIFEST but how about using @cloudflare/vitest-pool-workers?

https://developers.cloudflare.com/workers/testing/vitest-integration/get-started/write-your-first-test/

rustymagnet3000 commented 4 months ago

Thanks for all you do @yusukebe.

At the moment I have solved it by using JSX instead of the static site instructions. I'll close the issue as I think the alternatives ( using JSX or the link you provided above ) are strong.

yusukebe commented 4 months ago

Hi @rustymagnet3000

FYI. The serve static on Cloudflare Workers will be actually deprecated because Worker Sites that is used in the serve static is now deprecated. So, I recommend using Cloudflare Pages starter with the npm create hono command if your application will serve static assets.