codeceptjs / CodeceptJS

Supercharged End 2 End Testing Framework for NodeJS
http://codecept.io
MIT License
4.11k stars 722 forks source link

feat(rest): print curl #4396

Closed kobenguyent closed 3 months ago

kobenguyent commented 3 months ago

Motivation/Description of the PR

    › [CURL Request] curl --location --request POST https://httpbin.org/post -H "X-API-Key: apiKey-onRequest" -H "Content-Type: application/json" -d '{"_overheadLength":161,"_valueLength":0,"_valuesToMeasure":[{"fd":null,"path":"/Users/t/Desktop/projects/codeceptjs-rest-demo/src/fixtures/test_image.png","flags":"r","mode":438,"end":null,"bytesRead":0,"_readableState":{"state":6176,"highWaterMark":65536,"buffer":{"head":null,"tail":null,"length":0},"length":0,"pipes":[],"flowing":false,"errored":null,"defaultEncoding":"utf8","awaitDrainWriters":null,"decoder":null,"encoding":null},"_events":{},"_eventsCount":3}],"writable":false,"readable":true,"dataSize":0,"maxDataSize":2097152,"pauseStreams":true,"_released":false,"_streams":["----------------------------807986065015258526651649\r\nContent-Disposition: form-data; name=\"attachment\"; filename=\"test_image.png\"\r\nContent-Type: image/png\r\n\r\n",{"source":{"fd":null,"path":"/Users/t/Desktop/projects/codeceptjs-rest-demo/src/fixtures/test_image.png","flags":"r","mode":438,"end":null,"bytesRead":0,"_readableState":{"state":6176,"highWaterMark":65536,"buffer":{"head":null,"tail":null,"length":0},"length":0,"pipes":[],"flowing":false,"errored":null,"defaultEncoding":"utf8","awaitDrainWriters":null,"decoder":null,"encoding":null},"_events":{},"_eventsCount":3},"dataSize":0,"maxDataSize":null,"pauseStream":true,"_maxDataSizeExceeded":false,"_released":false,"_bufferedEvents":[{"0":"pause"}],"_events":{},"_eventsCount":1},null],"_currentStream":null,"_insideLoop":false,"_pendingNext":false,"_boundary":"--------------------------807986065015258526651649"}'

Applicable helpers:

Type of change

Checklist:

kobenguyent commented 3 months ago

ready for testing: codeceptjs@3.6.4-beta.2

kobenguyent commented 3 months ago

Looks really good to me I checked alternative implementation at https://github.com/anthonygauthier/axios-curlirize/blob/master/src/lib/CurlHelper.js and I think your is better yet minimal.

However, I can assume it doesn't cover all cases.

Should we inform users somehow on that?

Or I have a better idea, ignore CURL output if request is not JSON. I don't think we need to fit for all cases

updated as proposed!