<#1140 Not possible to use multipart form data bec...
# pact-js-development
g
#1140 Not possible to use multipart form data because of boundary Issue created by jawadsef Software versions Please provide at least OS and version of pact-js • OS:
macOS Ventura Version 13.0.1 (22A400)
• Consumer Pact library: e.g. Pact JS v2.6.0
Copy code
"@pact-foundation/pact": "^12.1.0"
"@pact-foundation/pact-core": "^14.0.5"
• Provider Pact library: not relevant, since this is just a consumer test • Node Version:
v18.14.1
Issue Checklist Please confirm the following: ☑︎ I have upgraded to the latest ☑︎ I have the read the FAQs in the Readme ☑︎ I have triple checked, that there are no unhandled promises in my code and have read the section on intermittent test failures ☑︎ I have set my log level to debug and attached a log file showing the complete request/response cycle ☑︎ For bonus points and virtual high fives, I have created a reproducible git repository (see below) to illustrate the problem Expected behavior Test passes. Actual behavior Test fails. Getting the following error:
Copy code
Mock server failed with the following mismatches:
        0) The following request was incorrect: 
                POST /test            
                         1.0    $: Failed to parse the expected body as a MIME multipart body: 'no boundary in content-type'
                         1.1    $: Failed to parse the actual body as a MIME multipart body: 'no boundary in content-type'
I tried generating the boundary but didn't work either. Steps to reproduce Clone following repo: https://github.com/jawadsef/pact-js-repro-template (
git clone git@github.com:jawadsef/pact-js-repro-template.git
) Run consumer test: https://github.com/jawadsef/pact-js-repro-template/blob/main/consumer.spec.ts (
npm run test:consumer
) Relevant log files ``` [233401.279] INFO (41652): 0.4.0: pact native library successfully found, and the correct version 2023-11-28T223401.331419Z DEBUG ThreadId(01) pact_plugin_driver:catalogue manager Updated catalogue entries: core/transport/http core/transport/https 2023-11-28T223401.333204Z DEBUG ThreadId(01) pact_plugin_driver:catalogue manager Updated catalogue entries: core/content-generator/binary core/content-generator/json core/content-matcher/json core/content-matcher/multipart-form-data core/content-matcher/text core/content-matcher/xml 2023-11-28T223401.333600Z DEBUG ThreadId(01) pact_plugin_driver:catalogue manager Updated catalogue entries: core/matcher/v1-equality core/matcher/v2-max-type core/matcher/v2-min-type core/matcher/v2-minmax-type core/matcher/v2-regex core/matcher/v2-type core/matcher/v3-content-type core/matcher/v3-date core/matcher/v3-datetime core/matcher/v3-decimal-type core/matcher/v3-includes core/matcher/v3-integer-type core/matcher/v3-null core/matcher/v3-number-type core/matcher/v3-time core/matcher/v4-array-contains core/matcher/v4-equals-ignore-order core/matcher/v4-max-equals-ignore-order core/matcher/v4-min-equals-ignore-order core/matcher/v4-minmax-equals-ignore-order core/matcher/v4-not-empty (node:41652) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time (Use
node --trace-warnings ...
to show where the warning was created) RUNS ./consumer.spec.ts 2023-11-28T223401.363863Z DEBUG tokio-runtime-worker hyper:protoh1io parsed 9 headers 2023-11-28T223401.363895Z DEBUG tokio-runtime-worker hyper:protoh1conn incoming body is chunked encoding 2023-11-28T223401.363970Z DEBUG tokio-runtime-worker hyper:protoh1decode incoming chunked header: 0x63 (99 bytes) 2023-11-28T223401.363996Z DEBUG tokio-runtime-worker pact_mock_server:hyper server Creating pact request from hyper request 2023-11-28T223401.364011Z DEBUG tokio-runtime-worker pact_mock_server:hyper server Extracting query from uri /test 2023-11-28T223401.364697Z DEBUG tokio-runtime-worker hyper:protoh1decode incoming chunked header: 0x2A (42 bytes) 2023-11-28T223401.364717Z DEBUG tokio-runtime-worker hyper:protoh1conn incoming body completed 2023-11-28T223401.365090Z INFO tokio-runtime-worker pact_mock_server:hyper server Received request HTTP Request ( method: POST, path: /test, query: None, headers: Some({"connection": ["keep-alive"], "accept": ["*/*"], "sec-fetch-mode": ["cors"], "accept-language": ["*"], "user-agent": ["undici"], "content-type": ["multipart/form-data"], "accept-encoding": ["gzip", "deflate"], "host": ["127.0.0.1:63372"], "transfer-encoding": ["chunked"]}), body: Present(141 bytes, multipart/form-data) ) 2023-11-28T223401.366169Z INFO tokio-runtime-worker pact_matching: comparing to expected HTTP Request ( method: POST, path: /test, query: None, headers: Some({"Content-Type": ["multipart/form-data"]}), body: Present(2 bytes) ) 2023-11-28T223401.366200Z DEBUG tokio-runtime-worker pact_matching: body: '7B7D (2 bytes)' 2023-11-28T223401.366205Z DEBUG tokio-runtime-worker pact_matching: matching_rules: MatchingRules { rules: {PATH: MatchingRuleCategory { name: PATH, rules: {} }, HEADER: MatchingRuleCategory { name: HEADER, rules: {} }} } 2023-11-28T223401.366222Z DEBUG tokio-runtime-worker pact_matching: generators: Generators { categories: {} } 2023-11-28T223401.366628Z DEBUG tokio-runtime-worker pact_matching:matchers String -> String: comparing '/test' to '/test' ==> true cascaded=false matcher=Equality 2023-11-28T223401.367642Z DEBUG tokio-runtime-worker pact_matching: expected content type = 'multipart/form-data', actual content type = 'multipart/form-data' 2023-11-28T223401.367705Z DEBUG tokio-runtime-worker pact_matching: content type header matcher = 'RuleList { rules: [], rule_logic: And, cascaded: false }' 2023-11-28T223401.368046Z DEBUG tokio-runtime-worker pact_plugin_driver:catalogue manager Looking for a content matcher for multipart/form-data 2023-11-28T223401.369152Z DEBUG tokio-runtime-worker pact_matching: No content matcher defined for content type 'multipart/form-data', using core matcher implementation 2023-11-28T223401.369193Z DEBUG tokio-runtime-worker pact_matching: Using body matcher for content type 'multipart/form-data' 2023-11-28T223401.369210Z DEBUG tokio-runtime-worker pact_matching:binary utils matching MIME multipart contents 2023-11-28T223401.370774Z DEBUG tokio-runtime-worker pact_matching: --> Mismatches: [BodyMismatch { path: "$", expected: Some(b"{}"), actual: Some(b"------formdata-undici-0.9267915492310101\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nJohn Doe\r\n------formdata-undici-0.9267915492310101--"), mismatch: "Failed to parse the expected body as a MIME multipart body: 'no boundary in content-type'" }, BodyMismatch { path: "$", expected: Some(b"{}"), actual: Some(b"------formdata-undici-0.9267915492310101\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nJohn Doe\r\n------formdata-undici-0.9267915492310101--"), mismatch: "Failed to parse the actual body as a MIME multipart body: 'no boundary in content-type'" }] 2023-11-28T223401.371108Z DEBUG tokio-runtime-worker pact_mock_server:hyper server Request did not match: Request did not match - HTTP Request ( method: POST, path: /test, query: None, headers: Some({"Content-Type": ["multipart/form-data"]}), body: Present(2 bytes) ) 0) $ -> Failed to parse the expected body as a MIME multipart body: 'no boundary in content-type' 1) $ -> Failed to parse the actual body as a MIME multipart body: 'no boundary in content-type' 2023-11-28T223401.371252Z DEBUG tokio-runtime-worker hyper:protoh1io flushed 1004 bytes 2023-11-28T223401.382132Z 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 2023-11-28T223401.382168Z DEBU… pact-foundation/pact-js