Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin): allow filtering entries from HAR using a custom predicate #172

Conversation

derevnjuk
Copy link
Member

@derevnjuk derevnjuk commented Jan 19, 2023

You can specify the filter option as a path to a JS/TS module that exports a function to filter out unwanted entries from the HAR. The function should take an Entry object as a parameter and return a boolean indicating whether the entry should be included in the final HAR or not.

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

cy.recordHar({ filter: '../support/include-password.ts' });

And here's an example of what the include-password.ts filter module might look like:

import { Entry } from 'har-format';

export default async (req: Entry) => {
  try {
    return /\"password":/.test(req.request.postData.text ?? '');
  } catch {
    return false;
  }
};

In this example, the filter function will only exclude entries in the HAR where the request body contains a JSON object with a password field.

You can also specify a rootDir option that will be used to resolve the path of the filter option. By default, the path is relative to the spec folder. But by providing a rootDir it will look for the module in the provided directory:

cy.recordHar({
  filter: 'cypress/support/include-password.ts',
  rootDir: Cypress.config('projectRoot')
});

closes #163

@derevnjuk derevnjuk added the Type: enhancement New feature or request. label Jan 19, 2023
@derevnjuk derevnjuk self-assigned this Jan 19, 2023
@codeclimate
Copy link

codeclimate bot commented Jan 19, 2023

Code Climate has analyzed commit b5cada5 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 96.6% (50% is the threshold).

This pull request will bring the total coverage in the repository to 92.1% (0.1% change).

View more on Code Climate.

@derevnjuk derevnjuk force-pushed the feat_#163/provide_a_flexible_and_simple_mechanism_to_filter_entries_from_the_HAR branch from 130399a to 2cf4b97 Compare January 19, 2023 17:36
@derevnjuk derevnjuk force-pushed the feat_#163/provide_a_flexible_and_simple_mechanism_to_filter_entries_from_the_HAR branch from 2cf4b97 to fc88f8f Compare January 19, 2023 17:53
src/Plugin.ts Show resolved Hide resolved
@derevnjuk derevnjuk force-pushed the feat_#163/provide_a_flexible_and_simple_mechanism_to_filter_entries_from_the_HAR branch from 22683e8 to ea61e59 Compare January 23, 2023 10:14
@derevnjuk derevnjuk force-pushed the feat_#163/provide_a_flexible_and_simple_mechanism_to_filter_entries_from_the_HAR branch from ea61e59 to 278698a Compare January 23, 2023 10:19
@derevnjuk derevnjuk force-pushed the feat_#163/provide_a_flexible_and_simple_mechanism_to_filter_entries_from_the_HAR branch from 916703a to ccbb4f8 Compare January 23, 2023 10:40
@derevnjuk derevnjuk marked this pull request as ready for review January 23, 2023 10:41
@derevnjuk derevnjuk force-pushed the feat_#163/provide_a_flexible_and_simple_mechanism_to_filter_entries_from_the_HAR branch from 3fdfc8d to a8dd7e3 Compare January 23, 2023 15:21
@derevnjuk derevnjuk marked this pull request as draft January 23, 2023 15:30
@derevnjuk derevnjuk force-pushed the feat_#163/provide_a_flexible_and_simple_mechanism_to_filter_entries_from_the_HAR branch from c8ae319 to b5cada5 Compare January 24, 2023 09:42
@derevnjuk derevnjuk marked this pull request as ready for review January 24, 2023 09:42
@derevnjuk derevnjuk merged commit e6d9553 into master Jan 24, 2023
@derevnjuk derevnjuk deleted the feat_#163/provide_a_flexible_and_simple_mechanism_to_filter_entries_from_the_HAR branch January 24, 2023 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: enhancement New feature or request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a flexible and simple mechanism to filter entries from the HAR
2 participants