mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-10-24 23:49:06 +08:00
test(api): always start server before testing (#49994)
This commit is contained in:
+4
-19
@@ -1,28 +1,13 @@
|
||||
import request, { Response } from 'supertest';
|
||||
|
||||
import { build } from './app';
|
||||
import request from 'supertest';
|
||||
|
||||
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('/');
|
||||
const res = await request(fastifyTestInstance?.server).get('/');
|
||||
expect(res?.statusCode).toBe(200);
|
||||
});
|
||||
|
||||
test('return { "hello": "world"}', () => {
|
||||
test('return { "hello": "world"}', async () => {
|
||||
const res = await request(fastifyTestInstance?.server).get('/');
|
||||
expect(res?.body).toEqual({ hello: 'world' });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user