mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
feat(api): add CORS headers (#50120)
* test: allow mocking of env vars Since utils/env is a module, we can mock it to control env vars in tests. However, it's not compatible with building the server in setupFilesAfterEnv, so, instead, we can use a utility function to keep things DRY. * fix: update type of fastifyTestInstance * chore: add comment about sts preload * chore: rename header plugin * test: add get util + provide origin on request * feat: add cors headers * chore: add TODO
This commit is contained in:
committed by
GitHub
parent
293fb65063
commit
46cdfd7802
@@ -0,0 +1,30 @@
|
||||
import request from 'supertest';
|
||||
|
||||
import { build } from './src/app';
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line no-var
|
||||
var fastifyTestInstance: Awaited<ReturnType<typeof build>> | undefined;
|
||||
}
|
||||
|
||||
export function superGet(endpoint: string): request.Test {
|
||||
return request(fastifyTestInstance?.server)
|
||||
.get(endpoint)
|
||||
.set('Origin', 'https://www.freecodecamp.org');
|
||||
}
|
||||
|
||||
export function setupServer(): void {
|
||||
let fastify: Awaited<ReturnType<typeof build>> | undefined;
|
||||
beforeAll(async () => {
|
||||
fastify = await build();
|
||||
await fastify.ready();
|
||||
|
||||
global.fastifyTestInstance = fastify;
|
||||
});
|
||||
|
||||
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 fastifyTestInstance?.close();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user