Closed ImLunaHey closed 1 year ago
Good catch! This might be a bug. I'll look into it
Ok, I've looked into this. In bun, Request
is a global, so you don't need to import it. In the next release I'll see about exporting Request just for consistency with the node package.
Your code should look like this:
import { createApplication } from '@nbit/bun';
import { expect, test } from 'bun:test';
const { defineRoutes, createRequestHandler } = createApplication();
const routes = defineRoutes((app) => [
app.get('/', (request) => {
return { hello: 'world' };
}),
]);
const requestHandler = createRequestHandler(routes);
test('should handle a request', async () => {
const request = new Request('http://localhost/');
const response = await requestHandler(request);
expect(response.status).toBe(200);
const data = await response.json();
expect(data).toEqual({ hello: 'world' });
});
Note: You need to use a fully-qualified url for new Request(url)
or else it will show:
Failed to construct 'Request': Invalid URL (missing a hostname)
In the next release I'll see about exporting Request just for consistency with the node package
Done in v0.9
When switching to
@nbit/bun
I get this errorModule '"@nbit/bun"' has no exported member 'Request'.