is there a way to run an http server *

is there a way to run an http server within a test. For example I have this snippet:
import { describe, expect, it } from 'vitest';
import { Miniflare } from 'miniflare';

describe('MiniflareFun', () => {
it('end-to-end', async () => {
const mf = new Miniflare({
modules: true,
script: `
export default {
async fetch(request, env, ctx) {
return new Response("Hello Miniflare!");
}
}
`,
});

const res = await mf.dispatchFetch('http://localhost:8787/');
console.log(await res.text()); // Hello Miniflare!
await mf.dispose();
expect(true).toBe(true);
});
});
import { describe, expect, it } from 'vitest';
import { Miniflare } from 'miniflare';

describe('MiniflareFun', () => {
it('end-to-end', async () => {
const mf = new Miniflare({
modules: true,
script: `
export default {
async fetch(request, env, ctx) {
return new Response("Hello Miniflare!");
}
}
`,
});

const res = await mf.dispatchFetch('http://localhost:8787/');
console.log(await res.text()); // Hello Miniflare!
await mf.dispose();
expect(true).toBe(true);
});
});
But then I get this error:
bash Error: No such module "node:os".
bash Error: No such module "node:os".
I cannot use fetchmock for this, it needs to be some sort of HTTP server on an arbitrary port.
1 Reply
Ben
BenOP3w ago
Actually i can use fetch mock with persistence, that will work for my needs, thanks!

Did you find this page helpful?