-
Notifications
You must be signed in to change notification settings - Fork 10
/
setupTests.js
43 lines (36 loc) · 1.15 KB
/
setupTests.js
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
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';
import { server } from './mocks/server'
import { setupPactMswAdapter } from "@pactflow/pact-msw-adapter";
const mswPact = setupPactMswAdapter({
server,
options: {
consumer: process.env.PACT_CONSUMER ? process.env.PACT_CONSUMER : 'pactflow-example-bi-directional-consumer-msw',
providers: {
[process.env.PACT_PROVIDER ? process.env.PACT_PROVIDER : 'pactflow-example-bi-directional-provider-dredd']: ['products', 'product']
},
pactOutDir: './pacts',
excludeHeaders: ['x-powered-by']
},
});
beforeAll(() => {
// Enable the mocking in tests.
server.listen()
})
beforeEach(() => {
mswPact.newTest();
});
afterEach(() => {
mswPact.verifyTest();
// Reset any runtime handlers tests may use.
server.resetHandlers()
})
afterAll(async () => {
await mswPact.writeToFile(); // writes the pacts to a file
mswPact.clear();
// Clean up once the tests are done.
server.close()
})