New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[V3] feat: Pact should overwrite existing contract files automatically, or at least provide an option to do so #731
Comments
We do support this. I thought it was well documented, but perhaps it isn't as I can't find it right now. The option you want is Part of the problem isn't pact, but rather the way that JS testing frameworks work. When Jest runs, it runs each spec separately and potentially in parallel, without context on whether other specs are being run. When mocha runs, it runs all tests in one execution. We need to be able to support both cases. Can you elaborate on why you're expecting an update in your first case? Maybe this needs to be better documented, but I don't think we can implement the behaviour you're asking for in a way that would work for everyone. If we implemented logic that said "if this new interaction is exactly the same as another one, just rename the other one", we might stamp out interactions from other spec files. Your second case sounds like a bug. Are you able to share some code that reproduces this?
They should be. So, if they're not, let's dig deeper. The advice to remove the spec files first isn't because interactions can't be updated correctly in place, it's because interactions that no longer exist can't always be removed if |
I wasn't aware of |
Ah! Apologies, I'm not sure how I missed that you were asking about v3. It seems clear in your question. The rust core doesn't have the same lifecycle, so many of the options from the current release are not applicable to the beta release. Having said that, we're trying to get the next release as close as possible to a drop-in release. One major difference in the lifecycle with the rust core is that the pact file is written at the end of each test (when you call Your first use case is solved by clearing the pact files at the start of the run. I would like to better support the clearing of pact files automatically at the start of the test run, but in js land we have to do that on a per-framework basis. If you could let us know what framework you're using, we can prioritise that one first. The second use case still sounds like a bug - could you provide an example that we can reproduce? |
We use Nx, which by default uses Jest under the covers.
Then, we run it and the pact file gets generated, with the response body containing a "state" of "staged". |
^ This is why you're seeing that behaviour. The
If you want the pact file to exactly match
|
Sorry, my bad, even without the |
Because of the way the new core works, it can allow several concurrent processes (tests) to be running in parallel on different ports. If there is an interaction conflict (uniqueness is by the combination of a description, verb, path) it doesn't know what to do - i.e. which one should take priority? Neither, that could result in a bug. I believe it should warn/error in this case, saying that there is a conflict. If not, that should be a bug. As you've discovered, you should clear all pacts before running tests locally. Apologies, this does appear to be documented (and is a divergence from the current mainline). There are ways to resolve it, but the trade off is we can't allow concurrency. It's analogous to this behaviour. |
Closing as not supported. The pact files can be cleared before the tests run. |
Before making a feature request, I have:
Feature description
Pact should overwrite existing contract files automatically, or at least provide an option to do so.
Use case
I’m seeing some interesting things regarding pact file creation in pact-js v3 beta and I’m wondering if they're expected. I’ll describe the 2 cases I’m seeing:
uponReceiving
string slightly in one of those tests and re-run them. It turns out that pact will actually add a third interaction with the updateduponReceiving
string to the existing pact file. I was expecting pact to simply regenerate the pact (e.g. overwrite the existing file) with theuponReceiving
string updated in the appropriate interaction (meaning, the pact file would still have 2 interactions, rather than 3).The common thread here seems to be that pact files may not be re-generated properly if they already exist. I get it that removing pact files before running tests avoids these issues. However, is there any value in doing, for example, what’s described in issue 2 above, namely not updating the existing pact file with the new body values (that one seems like a bug to me)? I was just wondering why doesn’t Pact overwrite existing pact files automatically, or at least provide an option to do so. For example, in
PactV3Options
there could be a boolean field, called something likeoverwrite
, which when set totrue
would automatically overwrite a previously existing pact file with the one generated by the current run.The text was updated successfully, but these errors were encountered: