-
Notifications
You must be signed in to change notification settings - Fork 15
/
pactFromMswWorker.spec.js
83 lines (76 loc) · 2.15 KB
/
pactFromMswWorker.spec.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
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
83
// / <reference types="cypress" />
import { setupPactMswAdapter } from '@pactflow/pact-msw-adapter';
let pactMswAdapter = undefined;
describe('Tests setupPactMswAdapter with msw works', async () => {
beforeEach(() => {
cy.visit('http://localhost:3000');
if (!pactMswAdapter) {
cy.window().then((window) => {
pactMswAdapter = setupPactMswAdapter({
worker: window.msw.worker,
options: {
consumer: 'testConsumer',
timeout: 1000,
providers: {
['testProvider']: ['/products'],
['testProvider2']: ['/product/09']
},
// pactOutDir: './pacts',
// excludeUrl: ['static/'],
includeUrl: ['/products', '/product/09'],
excludeHeaders: ['ignore-me']
// debug: true
}
});
pactMswAdapter.newTest();
});
} else {
pactMswAdapter.newTest();
}
});
afterEach(() => {
if (!pactMswAdapter) return;
try {
pactMswAdapter.verifyTest();
} catch (err) {
// cypress doesn't like errors on hooks...
if (process.env.NODE_ENV !== 'production') {
console.groupCollapsed(
'%cError generating pacts.',
'color:coral;font-weight:bold;'
);
console.log(err);
console.groupEnd();
} else {
// fail on pipelines
console.log(err);
throw err;
}
}
});
after(async () => {
if (!pactMswAdapter) return;
try {
await pactMswAdapter.writeToFile((path, data) => {
console.log(JSON.stringify(data));
cy.writeFile(path, data);
});
} catch (err) {
console.groupCollapsed(
'%cError generating pacts.',
'color:coral;font-weight:bold;'
);
console.log(err);
console.groupEnd();
throw err;
}
pactMswAdapter.clear();
});
it('should record a msw interaction and turn it into a back', () => {
// Filter to the product we want
cy.get('#input-product-search').type('Gem Visa');
cy.get('.btn').click();
cy.url().should('include', '/products/09');
cy.contains('Gem Visa');
});
});