Lennart Querter
08/30/2022, 9:39 AMMac M1 pro
"@pact-foundation/pact": "^10.1.2"
"jest": "^29.0.1",
"ts-jest": "^28.0.8",
Error:
Error in native callback
at Object.mockServerMismatches (node_modules/@pact-foundation/pact-core/src/consumer/index.ts:94:13)
at PactV3.<anonymous> (node_modules/@pact-foundation/src/v3/pact.ts:207:39)
at step (node_modules/@pact-foundation/pact/src/v3/pact.js:33:23)
at Object.throw (node_modules/@pact-foundation/pact/src/v3/pact.js:14:53)
at rejected (node_modules/@pact-foundation/pact/src/v3/pact.js:6:65)
Github repo for reproduction:
https://github.com/lennartquerter/pact-v3-test
Commands:
yarn install && yarn test:pactv3Timothy Jones
09/01/2022, 1:41 PMTimothy Jones
09/01/2022, 1:48 PMLennart Querter
09/01/2022, 2:25 PMMatt (pactflow.io / pact-js / pact-go)
Lennart Querter
09/06/2022, 1:15 PMMatt (pactflow.io / pact-js / pact-go)
Lennart Querter
09/06/2022, 1:16 PMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
RUNS src/tradeLanes/tradelanes.test.pactv3.ts
2022-09-06T13:11:35.813403Z DEBUG tokio-runtime-worker hyper::proto::h1::io: parsed 4 headers
2022-09-06T13:11:35.813409Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body is empty
2022-09-06T13:11:35.813423Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Creating pact request from hyper request
2022-09-06T13:11:35.813425Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Extracting query from uri /trade-lanes?page=1&pageSize=10
2022-09-06T13:11:35.813450Z INFO tokio-runtime-worker pact_mock_server::hyper_server: Received request HTTP Request ( method: GET, path: /trade-lanes, query: Some({"pageSize": ["10"], "page": ["1"]}), headers: Some({"connection": ["close"], "user-agent": ["axios/0.27.2"], "host": ["127.0.0.1:49298"], "accept": ["application/json", "text/plain", "*/*"]}), body: Empty )
2022-09-06T13:11:35.813477Z INFO tokio-runtime-worker pact_matching: comparing to expected HTTP Request ( method: GET, path: /trade-lanes, query: Some({"page": ["1"], "pageSize": ["10"]}), headers: Some({"Accept": ["application/json"]}), body: Missing )
2022-09-06T13:11:35.815818Z DEBUG tokio-runtime-worker pact_matching: body: ''
2022-09-06T13:11:35.815822Z DEBUG tokio-runtime-worker pact_matching: matching_rules: MatchingRules { rules: {PATH: MatchingRuleCategory { name: PATH, rules: {} }, QUERY: MatchingRuleCategory { name: QUERY, rules: {} }, HEADER: MatchingRuleCategory { name: HEADER, rules: {} }} }
2022-09-06T13:11:35.815829Z DEBUG tokio-runtime-worker pact_matching: generators: Generators { categories: {} }
2022-09-06T13:11:35.815840Z DEBUG tokio-runtime-worker pact_matching::matchers: String -> String: comparing '/trade-lanes' to '/trade-lanes' ==> true cascaded=false matcher=Equality
2022-09-06T13:11:35.815846Z DEBUG tokio-runtime-worker pact_matching: expected content type = '*/*', actual content type = '*/*'
2022-09-06T13:11:35.815862Z DEBUG tokio-runtime-worker pact_matching: content type header matcher = 'RuleList { rules: [], rule_logic: And, cascaded: false }'
2022-09-06T13:11:35.816095Z DEBUG tokio-runtime-worker pact_matching::matchers: String -> String: comparing '1' to '1' ==> true cascaded=false matcher=Equality
2022-09-06T13:11:35.816105Z DEBUG tokio-runtime-worker pact_matching::matchers: String -> String: comparing '10' to '10' ==> true cascaded=false matcher=Equality
2022-09-06T13:11:35.816117Z DEBUG tokio-runtime-worker pact_matching: --> Mismatches: []
2022-09-06T13:11:35.816139Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Test context = {"mockServer": Object {"href": String("<http://127.0.0.1:49298>"), "port": Number(49298)}}
2022-09-06T13:11:35.816150Z INFO tokio-runtime-worker pact_mock_server::hyper_server: Request matched, sending response HTTP Response ( status: 200, headers: Some({"Content-Type": ["application/json"]}), body: Present(44 bytes, application/json) )
console.log
TypeError: Cannot read properties of undefined (reading '0')
at /private/tmp/pact-v3-test/src/tradeLanes/tradelanes.test.pactv3.ts:47:36
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at PactV3.<anonymous> (node_modules/@pact-foundation/src/v3/pact.ts:204:15)
RUNS src/tradeLanes/tradelanes.test.pactv3.ts
2022-09-06T13:11:35.840716Z DEBUG ThreadId(01) pact_matching::metrics: Could not get the tokio runtime, will not send metrics - there is no reactor running, must be called from the context of a Tokio 1.x runtime
2022-09-06T13:11:35.840729Z DEBUG ThreadId(01) pact_mock_server::server_manager: Shutting down mock server with ID 1e3fa86f-14ad-4f9e-9063-101ae57a2181 - MockServerMetrics { requests: 1 }
FAIL src/tradeLanes/tradelanes.test.pactv3.tspact_mock_server::mock_server: Mock server 1e3fa86f-14ad-4f9e-9063-101ae57a2181 shutdown - MockServerMetrics { requests: 1 }
GET /dogs
โ returns an HTTP 200 and a pagination result of docs (34 ms)
โ GET /dogs โบ returns an HTTP 200 and a pagination result of docs
TypeError: Cannot read properties of undefined (reading '0')
45 |
46 | // Assert: check the result
> 47 | expect(response.results[0]).toEqual(tradeLaneExample);
| ^
48 | });
49 | });
50 | });
at src/tradeLanes/tradelanes.test.pactv3.ts:47:36
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 2.436 s
Ran all test suites.
error Command failed with exit code 1.
info Visit <https://yarnpkg.com/en/docs/cli/run> for documentation about this command.Lennart Querter
09/06/2022, 1:25 PMMatt (pactflow.io / pact-js / pact-go)
Lennart Querter
09/06/2022, 1:41 PMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
{
results: [...]
}
right?
Where each item in results is of the same shape?Matt (pactflow.io / pact-js / pact-go)
const EXPECTED_BODY = MatchersV3.eachLike({
results: [tradeLaneExample]
});
should be
const EXPECTED_BODY = {
results: MatchersV3.eachLike(tradeLaneExample)
};Lennart Querter
09/06/2022, 1:45 PMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Lennart Querter
09/06/2022, 1:46 PMYousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
Matt (pactflow.io / pact-js / pact-go)
Lennart Querter
09/07/2022, 6:52 AM