Skip to content

Commit

Permalink
Fix Status and Added interceptPattern in config
Browse files Browse the repository at this point in the history
Merge pull request Nanciee#50 from filestage/master

This cherry pick includes just the syntactical changes from the
filestage/master pull request
  • Loading branch information
mhssmnn committed Aug 23, 2021
1 parent ee9c73e commit 3ab633d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ Stale mocks that are no longer being used can be automatically removed when you

**_NOTE: Only mocks that are used during the run are considered "active". Make sure to only set `cleanMocks` to `true` when you are running ALL your tests. Remove any unintentional `.only` or `.skip`._**

## Set Recording Pattern For Cypress Intercept

By default autorecorder is recording all outgoing requests but if you want to record only specific calls based on pattern(Ex. just record api calls on backend), you can set `interceptPattern` in `cypress.json`. it can be string, regex or glob

```json
{
"autorecord": {
"interceptPattern": "http://localhost:3000/api/*"
}
}
```

## How It Works

### How does the recording and stubbing work?
Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const isCleanMocks = cypressConfig.cleanMocks || false;
const isForceRecord = cypressConfig.forceRecord || false;
const recordTests = cypressConfig.recordTests || [];
const blacklistRoutes = cypressConfig.blacklistRoutes || [];
const interceptPattern = cypressConfig.interceptPattern || '*';
const whitelistHeaders = cypressConfig.whitelistHeaders || [];
const supportedMethods = ['get', 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'];

Expand Down Expand Up @@ -64,7 +65,7 @@ module.exports = function autoRecord() {
// Reset routes before each test case
routes = [];

cy.intercept('*', (req) => {
cy.intercept(interceptPattern, (req) => {
// This is cypress loading the page
if (
Object.keys(req.headers).some((k) => k === 'x-cypress-authorization')
Expand All @@ -74,7 +75,7 @@ module.exports = function autoRecord() {

req.reply((res) => {
const url = req.url;
const status = req.status;
const status = res.statusCode;
const method = req.method;
const data =
res.body.constructor.name === 'Blob'
Expand Down

0 comments on commit 3ab633d

Please sign in to comment.