Files
freeCodeCamp/api/src/server.test.ts
Oliver Eyton-Williams a128dd8fcd chore(api): compile TS into /dist (#49812
* chore: compile TS into /dist

Having the output co-located with the source meant that the js would be
imported by default. Given that we don't recompile on source changes,
this means the server got 'stuck' at the point of compilation and would
only register changes on build.

Also, compiling to a dist directory should make it easier to build when
we want to deploy. That said, the motivation is mostly DX.

* fix: put schema.prisma in the default location
2023-03-28 19:42:20 +05:30

29 lines
736 B
TypeScript

import request, { Response } from 'supertest';
import { build } from './app';
describe('GET /', () => {
let res: undefined | Response;
let fastify: undefined | Awaited<ReturnType<typeof build>>;
beforeAll(async () => {
fastify = await build();
await fastify.ready();
}, 20000);
afterAll(async () => {
// Due to a prisma bug, this is not enough, we need to --force-exit jest:
// https://github.com/prisma/prisma/issues/18146
await fastify?.close();
});
test('have a 200 response', async () => {
res = await request(fastify?.server).get('/');
expect(res?.statusCode).toBe(200);
});
test('return { "hello": "world"}', () => {
expect(res?.body).toEqual({ hello: 'world' });
});
});