Replies: 1 comment 2 replies
-
|
There are some issues when testing it with Vitest and a Miniflare environment. Thus, it's recommended to use unstable_dev in import { expect, describe, beforeAll, afterAll, it } from 'vitest'
import { unstable_dev } from 'wrangler'
describe('Worker', () => {
let worker
beforeAll(async () => {
worker = await unstable_dev('src/index.ts')
})
afterAll(async () => {
await worker.stop()
})
it('should return Hello World', async () => {
const resp = await worker.fetch()
if (resp) {
const text = await resp.text()
expect(text).toMatchInlineSnapshot(`"Hello World!"`)
}
})
}) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using vitest to test my hono application that is built to run on Cloudflare. I just added serveStatic to be able to serve static assets and now I'm getting the following error when I run my tests:
Error: Cannot find package '__STATIC_CONTENT_MANIFEST' imported from /Users/{username}/projects/atomic-lti-worker/node_modules/hono/dist/adapter/cloudflare-workers/server-static-module.js
I've added the following to wrangler.toml:
[site]
bucket = "./assets"
The application runs fine it's just the tests that are failing. I tried doing this in vite.config.js but I can't seem to get vite to alias "__STATIC_CONTENT_MANIFEST".
import { defineConfig } from 'vitest/config';
import path from 'path';
export default defineConfig({
test: {
environment: 'miniflare',
alias: {
__STATIC_CONTENT_MANIFEST: path.resolve(__dirname, './test/manifest.ts'),
},
},
});
These are the lines where I use serveStatic:
app.use('/*', serveStatic({ root: './' }));
app.use('/favicon.ico', serveStatic({ path: './favicon.ico' }));
app.use('/robots.txt', serveStatic({ path: './robots.txt' }));
If I comment those out everything runs fine.
Any tips on how to get this working?
Any tips for getting this working?
Beta Was this translation helpful? Give feedback.
All reactions