Nanciee / cypress-autorecord

Simplify API mocking by auto-recording/stubbing HTTP interactions and automating the process of updating/deleting mocks.
223 stars 53 forks source link

content-type based mocks #31

Open denpolischuk opened 4 years ago

denpolischuk commented 4 years ago

So I tried to use cypress-autorecord in one of the project I am working on and faced an issue with XHR responses which content-types are different from application/json. If the XHR response data is oversized (isFileOversized) then it is being written to fixtures/.json and on the next run of tests when they are trying to get data from those mock fixtures the JSON validation error is being thrown.

My solution:

IF content-type == 'application/json'
THEN
    IF isFileOversized
    THEN
        writeDataToFixture('<fixture-name>.json')
    ELSE 
        writeDataToMock('<test-name>.spec.json')
ELSE
    writeDataToFixture('<fixture-name>.<fixture-extantion>')

Currently it handles only text/html and application/json content types. For all other types it adds '.odt' extension.