-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvitest.setup.ts
82 lines (71 loc) · 2.04 KB
/
vitest.setup.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
71
72
73
74
75
76
77
78
79
80
81
82
import { afterAll, afterEach, beforeAll, beforeEach, vi } from "vitest";
import {
API_CONFIG,
API_ENDPOINT,
AUTH_CONFIG,
IDENTITY_POOL_ID,
OPENSEARCH_DOMAIN,
OPENSEARCH_INDEX_NAMESPACE,
PROJECT,
REGION,
STAGE,
USER_POOL_CLIENT_DOMAIN,
USER_POOL_CLIENT_ID,
USER_POOL_ID,
ATTACHMENT_BUCKET_NAME,
ATTACHMENT_BUCKET_REGION,
KAFKA_BROKERS,
setDefaultStateSubmitter,
mockedKafka,
} from "mocks";
import { mockedServiceServer as mockedServer } from "mocks/server";
import { Amplify } from "aws-amplify";
Amplify.configure({
API: API_CONFIG,
Auth: AUTH_CONFIG,
});
vi.mock("kafkajs", async (importOriginal) => {
return {
...(await importOriginal<typeof import("kafkajs")>()),
Kafka: mockedKafka,
};
});
beforeAll(() => {
setDefaultStateSubmitter();
console.log("starting MSW listener for lib tests");
mockedServer.listen({
onUnhandledRequest: "warn",
});
});
beforeEach(() => {
process.env.PROJECT = PROJECT;
process.env.REGION_A = REGION;
process.env.STAGE = STAGE;
process.env.isDev = "true";
process.env.project = PROJECT;
process.env.region = REGION;
process.env.stage = STAGE;
process.env.applicationEndpointUrl = API_ENDPOINT;
process.env.identityPoolId = IDENTITY_POOL_ID;
process.env.userPoolId = USER_POOL_ID;
process.env.idmClientId = USER_POOL_CLIENT_ID;
process.env.idmClientIssuer = USER_POOL_CLIENT_DOMAIN;
process.env.osDomain = OPENSEARCH_DOMAIN;
process.env.indexNamespace = OPENSEARCH_INDEX_NAMESPACE;
process.env.attachmentsBucketName = ATTACHMENT_BUCKET_NAME;
process.env.attachmentsBucketRegion = ATTACHMENT_BUCKET_REGION;
process.env.emailAddressLookupSecretName = "mock-email-secret"; // pragma: allowlist secret
process.env.DLQ_URL = "https://sqs.us-east-1.amazonaws.com/123/test";
process.env.configurationSetName = "SES";
process.env.brokerString = KAFKA_BROKERS;
});
afterEach(() => {
vi.useRealTimers();
vi.clearAllMocks();
setDefaultStateSubmitter();
mockedServer.resetHandlers();
});
afterAll(() => {
vi.resetAllMocks();
mockedServer.close();
});