diff --git a/README.md b/README.md index 4ebdbe8..27f6e4d 100644 --- a/README.md +++ b/README.md @@ -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? diff --git a/index.js b/index.js index 9e8192c..96bc6c5 100644 --- a/index.js +++ b/index.js @@ -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']; @@ -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') @@ -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'