-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjest_setup.ts
More file actions
32 lines (28 loc) · 995 Bytes
/
Copy pathjest_setup.ts
File metadata and controls
32 lines (28 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { loadEnvConfig } from '@next/env';
import * as fs from 'fs/promises';
import * as path from 'path';
import { getServerContext } from 'services/server_context';
const projectDir = process.cwd();
loadEnvConfig(projectDir);
async function initTestData() {
const { pool } = await getServerContext();
const seedSqlPath = path.resolve(__dirname, '../../supabase/seed.sql');
const seedSql = await fs.readFile(seedSqlPath).then((b) => b.toString());
await pool.query(`
TRUNCATE maps, difficulties, users, favorites CASCADE;
${seedSql}
`);
}
beforeEach(async () => {
// TODO: figure out a better way to do this now that Next and Jest don't run in the same server
// context.
if (process.env.NODE_ENV === 'production' || (process.env.NODE_ENV as string) === 'prod') {
throw new Error('Almost dropped DB on prod env');
}
await initTestData();
});
afterAll(async () => {
const { pool } = await getServerContext();
await pool.end();
});
global.console.info = jest.fn();