NeuraLegion/cypress-har-generator

Allow to transform entries before saving a HAR

Closed this issue · 0 comments

Description
It would be useful to have a way to transform recorded entries before saving the HAR file.

Possible solution
Provide the ability to transform entries by introducing the transform option as a path to a module that exports a function to modify entries before saving the HAR. The function should take as a parameter and return an Entry object.

Here's an example of how to use the filter option:

cy.recordHar({ transform: '../support/truncate-response-body.ts' });

And here's an example of what the truncate-response-body.ts filter module might look like:

import { Entry } from 'har-format';

export default (entry: Entry): Entry => ({
  ...entry,
  response: {
    ...entry.response,
    content: {
      ...entry.response.content,
      text: entry.response.content.text?.substring(0, 100)
    }
  }
});

This example demonstrates how the transform function can be used to truncate the response body of entries.

Relates to #169 (comment)