-
Notifications
You must be signed in to change notification settings - Fork 12
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
[WIP]: jest watch placeholder #53
Conversation
looks like adding
As we set the log & pact output directories, we should be able to hook into the API and ignore them (and also support user configured paths)
|
re-running only failed tests - https://github.com/pact-foundation/pact-js#re-run-specific-verification-failures Re-run specific verification failuresIf you prefix your test command (e.g. For the e2e example, let's assume we have the following failure: 3 interactions, 2 failures
Failed interactions:
* A request for all animals given Has some animals
* A request for an animal with id 1 given Has an animal with ID 1 If we wanted to target the second failure, we can extract the description and state as the bits before and after the word "given": PACT_DESCRIPTION="a request for an animal with ID 1" PACT_PROVIDER_STATE="Has an animal with ID 1" npm t Also note that |
jest notes https://github.com/pact-foundation/pact-js#timeout Note on JestJest uses JSDOM under the hood which may cause issues with libraries making HTTP request. You'll need to add the following snippet to your "jest": {
"testEnvironment": "node"
} Also, from Jest 20, you can add the environment to the top of the test file as a comment. This will allow your pact test to run along side the rest of your JSDOM env tests. /**
* @jest-environment node
*/ Jest also runs tests in parallel by default, which can be problematic with Pact which is stateful. See parallel tests to see how to make it run in parallel, or run Jest with the See this issue for background, |
parallel execution - what is the best pactfile write mode. How can we avoid
Parallel tests https://github.com/pact-foundation/pact-js#parallel-testsPact tests are inherently stateful, as we need to keep track of the interactions on a per-test basis, to ensure each contract is validated in isolation from others. However, in larger test suites, this can result in slower test execution. Modern testing frameworks like Ava and Jest support parallel execution out-of-the-box, which The good news is, parallel test execution is possible, you need to ensure that:
When all of your tests have completed, the result is the union of the all of the interactions from each test case in the generated pact file. See the following examples for working parallel tests: Splitting tests across multiple filesPact tests tend to be quite long, due to the need to be specific about request/response payloads. Often times it is nicer to be able to split your tests across multiple files for manageability. You have a number of options to achieve this feat:
|
Lots to unpack here, thanks for writing this all up. If possible, I'd like not to bake in assumptions about how people have set up their environment. For example, not everyone will have their tests output to Similarly, I name my tests Ideally we'd read all of this from config somehow, but it's not clear where the best place is (there's a little bit of discussion here). I think probably package.json, but it seems likely that some of that would want to be picked up by pact-js directly. I think we'd want to configure the jest plugin to clean out the pacts directory on start, then use update for the pact file write mode. This avoids keeping removed interactions around, while still allowing multiple test files to describe the same consumer/provider pairing. I think the best value is "what would the expected functionality be" - how can we help developers not have to think about the way pact is configured, and have it work for the majority of setups? |
No worries homie, yeah quite a few things to consider.
Agree with you completely here about not wanting to bake in assumptions. The less opinionated we can build the adaptor the better. We can take a user defined location by exposing
By taking in user provided paths, we can then support it on our defaults
Just thinking about that further, that would mean that a user would need to provide the log/dir directories every time they use
The adaptor doesn't need to know what the files are called, that it up to the end-user and their own configuration setup. The only thing we need to know about really is where the generated pact contracts & logs live, so we can get rid of them on each test run, and ignore them with a
There is some really good discussion points on there. I like the notion of reading from
Yeah we currently use If we have 4 pact tests for diff consumer/provider pairs, when we update a single pact test in watch mode, we would expect that only that file is re-executed by Jest. If we delete all the pacts, and only re-run one, we will be missing 3 of our consumer/provider pacts. If we can find a way to only delete one pact file, that would work nicely, expect for the scenario where we have the same consumer/provider pair across multiple test files, as deleting the pact and running only one test, would again mean we are missing some information.
Agree fully on this point, and it is a tough nut to crack. I think the main point, is not requiring developers to need to think about how pact needs to be configured before you can even start writing a test. It currently requires a reasonable amount of cognitive load, and it is easy to get the ordering wrong, and get into a muddle. Making it work the majority of setups is really difficult as it is hard to assume what other peoples setups are, without seeing them / or getting feedback on the pain points in setting up pact, to see if we can absolve some of that. Wonder if it is worth asking for some input on Slack to get others thoughts. With regards to the |
I've raised an proposal/featureRequest on the jest github repo, as looking at the docs, I am not sure if the watch plugin will cover our use cases. Thought it was worth asking the question :) |
Man I can't believe I wrote all that about 😂 Anyway it sounds like this might be doable now with a monkey patch see jestjs/jest#8714 |
Closing this down, as there was no real work here, just investigation. will add a note to the readme if anyone is interested to pick it up |
Placeholder for integration with jest watch mode
Considerations
https://jestjs.io/docs/en/watch-plugins
Existing watch plugins
node-recorder
.