forked from freeCodeCamp/chapter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcypress.config.ts
70 lines (56 loc) · 2.16 KB
/
cypress.config.ts
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { execSync } from 'child_process';
import { defineConfig } from 'cypress';
import { config } from 'dotenv';
import coverage from '@cypress/code-coverage/task';
import { prisma } from './server/src/prisma';
import { InstanceRole } from './server/prisma/generator/factories/instanceRoles.factory';
const getChapterMembers = (chapterId: number) =>
prisma.chapter_users.findMany({
where: { chapter_id: chapterId },
include: { user: true },
});
export type ChapterMembers = Awaited<ReturnType<typeof getChapterMembers>>;
const getEventUsers = (eventId: number) =>
prisma.event_users.findMany({
where: { event_id: eventId },
include: { user: true, rsvp: true },
});
export type EventUsers = Awaited<ReturnType<typeof getEventUsers>>;
const promoteToOwner = async ({ email }: { email: string }) => {
const name: InstanceRole['name'] = 'owner';
return await prisma.users.update({
where: { email },
data: { instance_role: { connect: { name } } },
});
};
const seedDb = () => execSync('node server/prisma/generator/seed.js');
config();
export default defineConfig({
e2e: {
projectId: 're65q6',
baseUrl: 'http://localhost:3000',
retries: { runMode: 3, openMode: 3 },
setupNodeEvents(on, config) {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
config.env = config.env || {};
// TODO: ideally the email address should have a common source (since it's
// used in the db generator, too)
config.env.SERVER_URL =
process.env.NEXT_PUBLIC_SERVER_URL || 'http://localhost:5000';
config.env.GQL_URL = `${config.env.SERVER_URL}/graphql`;
// This makes sure the db is populated before running any tests. Without this,
// it's difficult (when running docker-compose up) to guarantee that both the
// docker container is running and that the db has been seeded.
on('before:run', () => {
execSync('npm run db:reset');
});
on('task', { getChapterMembers, getEventUsers, seedDb, promoteToOwner });
coverage(on, config);
return config;
},
},
env: {
mailHogUrl: 'http://localhost:8025',
},
});