Skip to content
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

Having a "no matching interaction" on a single test crashes the entire suite #231

Closed
christopher-francisco opened this issue Oct 16, 2018 · 2 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@christopher-francisco
Copy link

christopher-francisco commented Oct 16, 2018

Software versions

  • Consumer Pact library: ^5.9.1
  • Node Version: 8.11.3

Expected behaviour

Given I add an interaction
And I'm doing TDD red-green-refactor cycle
When my callApi module makes the HTTP request
And it doesn't match the defined interaction ("red" part of the cycle)
Then only the that test should crash
And the other tests should have consistent results

Actual behaviour

All the tests that execute after the one that didn't match crashes.

Steps to reproduce

describe('callApi', () => {
  afterEach(() => provider.verify());

  it('a test that passes', () => {
    provider.addInteraction(interactionForEndpointA);
    callApi.endpointA();
  });

  it('a test that doesn\'t match the interaction', () => {
    provider.addInteraction(interactionForEndpointB);
    callApi.endpointB();
  });

  it('a test that should pass but doesn\'t, unless we comment out the previous test', () => {
    provider.addInteraction(interactionForEndpointC);
    callApi.endpointC();
  });
})

Relevant log files

ERROR -- : No matching interaction found for PUT /my/endpointB
ERROR -- : Interaction diffs for that route:
ERROR -- : Diff with interaction: "some interaction" given "some state"

Diff
--------------------------------------
Key: - is expected 
     + is actual 
Matching keys and values are not shown

 {
-  "body": {
-    "myProp": "myValue"
-  }
+  "body": "[object Object]"
 }

Description of differences
--------------------------------------
* Expected a Hash but got a String ("[object Object]") at $.body

WARN -- : Verifying - actual interactions do not match expected interactions. 
Incorrect requests:
	PUT /my/endpointB (request body did not match)

WARN -- : Incorrect requests:
	PUT /my/endpointB (request body did not match)


...... now it will register interactions for the next tests
...... and output that it found a response for the call in the next test
...... however, the verification is done against the PUT call above

INFO -- : Registered expected interaction GET /my/endpointC
DEBUG -- : {
...... the interaction definition
}
INFO -- : Received request GET /my/endpointC
DEBUG -- : {
....... the request
}
INFO -- : Found matching response for GET /my/endpointC
DEBUG -- : {
....... the response 
}
WARN -- : Verifying - actual interactions do not match expected interactions. 
Incorrect requests:
	PUT /my/endpointB (request body did not match)

WARN -- : Incorrect requests:
	PUT /my/endpointB (request body did not match)

........ I would have expected it would verify with the NEXT registered interaction, 
........ not with the one that already failed.
........ Also, the same thing happens for the rest of the tests
........ They all fail cause it's trying to verify with the failed interaction

Update

I noticed the tests that pass have this line in the logs:

INFO -- : Cleared interactions

This line is not present after a verification that failed. Maybe that's the problem?

@mefellows
Copy link
Member

Thanks for the detailed bug report @chris-fa. I think you're right, the behaviour should be to carry on, and let any "fast fail" decision happen at the test framework (e.g. Jest, Mocha) level.

@mefellows mefellows added the bug Indicates an unexpected problem or unintended behavior label Oct 17, 2018
mefellows added a commit that referenced this issue Oct 17, 2018
All successful/failed calls to pact.verify() should clear
interactions so that subsequent tests don't det out of whack.

NOTE: Promise.finally() would have been nicer, note for
upgrade to latest TS in next major release.

Fixes #231
@mefellows
Copy link
Member

OK, have made a fix in the latest release. Let us know if that fixes your issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants