Closed Maxim-Filimonov closed 2 years ago
Have you cleaned out the pact directory before running the tests? By default, it will append to the pact file.
See also https://github.com/pact-foundation/pact-js/blob/master/docs/migrations/9-10.md#consumer
As per the change to pactfileWriteMode this also means pact files should be cleared out prior to each test, to avoid extraneous interactions in a pact file.
This part? Right so it seems I would need to rm -rf pacts
BEFORE running any pact tests ?
Bingo!
Right, so for anybody who stumbles on this here is solution for jest: First configure globalSetup script
// jest.config.js
module.exports {
globalSetup: './src/jest.setup.global.js',
}
Then create a script which removes pacts folder before starting tests
// jest.setup.global.js
// const fs = require('fs') // for classic node
import fs from 'fs';
module.exports = () => {
console.debug('Clearing pact contracts');
fs.rmdirSync('./pacts', { recursive: true });
};
@YOU54F this might be a good thing to bring into jest-pact
?
Because Pact JS doesn't know about the test runner and the process is stateless (because we enable parallel running), we don't actually know when we can clobber the file and start again. But jest pact (and mocha pact) might?
Software versions
Issue Checklist
Please confirm the following:
Expected behaviour
I have the following contract:
when I changed description of state:
it should update description of state in JSON contract.
Actual behaviour
Instead, I got two different contracts in my contract.json:
Steps to reproduce