-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-fixture.ts
60 lines (51 loc) · 1.52 KB
/
app-fixture.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
import { test as baseTest } from "@playwright/test";
import { StartedPostgreSqlContainer } from "@testcontainers/postgresql";
import {
migrateDb,
startDb,
takeDbSnapshot,
resetDbToSnapshot,
PostgreSqlTestcontainerConfig,
} from "../testcontainers/psql";
type DatabaseFixture = {
databaseContainer: StartedPostgreSqlContainer;
resetDatabase: () => Promise<void>;
};
const test = baseTest.extend<DatabaseFixture & PostgreSqlTestcontainerConfig>({
dbContainerName: ["container-name", { option: true }],
dbName: ["database", { option: true }],
dbUserName: ["username", { option: true }],
dbPassword: ["password", { option: true }],
dbPort: [64301, { option: true }],
databaseContainer: async (
{ dbPort, dbPassword, dbUserName, dbName, dbContainerName },
use
) => {
const container = await startDb({
dbPort,
dbPassword,
dbUserName,
dbName,
dbContainerName,
});
// eslint-disable-next-line react-hooks/rules-of-hooks
await use(container);
},
resetDatabase: async ({ databaseContainer }, use) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
await use(async () => {
await resetDbToSnapshot(databaseContainer);
});
},
});
test.beforeAll(async ({ databaseContainer }) => {
await migrateDb(databaseContainer);
await takeDbSnapshot(databaseContainer);
});
test.afterAll(async ({ databaseContainer }) => {
await databaseContainer.stop();
});
test.afterEach(async ({ resetDatabase }) => {
await resetDatabase();
});
export { test };