{"_id":"@codeceptjs/mock-request","_rev":"9-98a7a4e14dbf2afbfad2fba5a42de524","name":"@codeceptjs/mock-request","dist-tags":{"latest":"0.3.1"},"versions":{"0.1.0":{"name":"@codeceptjs/mock-request","version":"0.1.0","keywords":["mock","pollyjs","codeceptjs","http-mock"],"author":{"name":"Michael Bodnarchuk @davert"},"license":"ISC","_id":"@codeceptjs/mock-request@0.1.0","maintainers":[{"name":"kaflan","email":"df117879@gmail.com"},{"name":"davert","email":"davert.ua@gmail.com"}],"dist":{"shasum":"c8e2f562c6f8e17cc0ec4450c6d56c6b9b10f895","tarball":"https://registry.npmjs.org/@codeceptjs/mock-request/-/mock-request-0.1.0.tgz","fileCount":6,"integrity":"sha512-eTTtwYwFHQKEdPEtFcj/YTXX/X9eRmO2cluqrGezwU8IUaPWpH/qbkWLiILZ/n9yi5b8gCf9lV0yf4Op/5Iw7A==","signatures":[{"sig":"MEQCIDC1gK6WrnvWTnerXTJosmhkMTN4VqDoNp9Cky/KsixgAiAIOjsI1wmlOOpUASLSvpt4s7OFrp4nWDvo2QYQaIs7wQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":13828,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJedLtCCRA9TVsSAnZWagAAQU4P/jhDmyyBEgWS2JgVXkPp\nsjHzlxICkjKWYGEVbpKtdm0CpjzSV81gloCcthnabqMwG1vZx7N9Ki2t9YUk\nHWOWwi5X7wWYUz4PphFo9q69NHZtUebxWB6uR1M/Dkq47kQk32jiucT7wprU\n3tzOYD3sWVHLNKbcilcoeUh1zxmT1UD1gADoX1cDU6qeMcZIAtxHI6SGo6IV\nvRFrRZDp+vej0kNH2cBn0AfVP+TNknjWBAfHgZXYPx43y+j4633Q/OaSJd50\nhpghT89fFNpYSQOGbjosgLITwIq8vIqK290GZt7ux9taO8DLH6mbsMWMNzNr\nIa/QTNL+FLZzEgb+0lAeiatdgj2VN/Fq96gqWgbCxtVenm52lbhbqLt15MO3\nquze8nD2S4TtGEOLwf9GESP9kQWJVna/CescB7l8DDFTsoz/nkTGloGp0+W6\nMTTygN2z6OjONwk41COdD4gWV20i8Kt816sJEdxYoJOinuCqGc/OXOyHjeJa\nLtLN6rKKuNn03y3XnEKIEUsq9rqLqNivAANgW7FJpXJtbXA7RNPuRitWkB0U\nMSrbjjlHCGjR48aAB/RDirdeLnx7rwv099XHpEYJpOtv03rrVLmTQ+aLGE+h\n1aa0wr1pwEaPEBByjdchud+4wbrlFFZVTYHvQvgv7WPdClDBSyp2evMGH9gM\nwsQ1\r\n=ydh5\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1","publish":"npm publish --access public"},"_npmUser":{"name":"davert","email":"davert.ua@gmail.com"},"_npmVersion":"6.13.4","description":"Mocking requests with PollyJS for CodeceptJS","directories":{},"_nodeVersion":"12.14.1","dependencies":{"@pollyjs/core":"^4.0.2","@pollyjs/persister-fs":"^4.0.2","@pollyjs/adapter-puppeteer":"^4.0.2"},"_hasShrinkwrap":false,"devDependencies":{"puppeteer":"^2.1.1","webdriverio":"^5.22.3"},"_npmOperationalInternal":{"tmp":"tmp/mock-request_0.1.0_1584708418233_0.8484899013749996","host":"s3://npm-registry-packages"}},"0.2.0":{"name":"@codeceptjs/mock-request","version":"0.2.0","keywords":["mock","pollyjs","codeceptjs","http-mock"],"author":{"name":"Michael Bodnarchuk @davert"},"license":"ISC","_id":"@codeceptjs/mock-request@0.2.0","maintainers":[{"name":"davert","email":"davert.ua@gmail.com"},{"name":"kaflan","email":"df117879@gmail.com"}],"dist":{"shasum":"f200335d228e841a5fb32c610437b59845ede51a","tarball":"https://registry.npmjs.org/@codeceptjs/mock-request/-/mock-request-0.2.0.tgz","fileCount":15,"integrity":"sha512-admh/8vVtMNZ+tPJcL75UoE1NBVrLhqRZblSh/DA3Evqyq0Zjad+h/wcnPB4Z3xR0kzey1cFSbBnQjvAyRfTeA==","signatures":[{"sig":"MEUCIQCp9fSdJ6IDo/OXE0KqUoly3S9yS0ZY67Qs8S5N+cabWQIgGUvppPxyrrMkfvLCaJXHY1uGAxgC0RHzUnRlflnM1Ho=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":83758,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJedn/yCRA9TVsSAnZWagAAndIP/jFJgigX4vZnQPCoZqeH\n9Ccd6PCVeMw442yNQCTl8ozK9ag/k7PHYhbQMqsuKuB8JynWFoi8Mmw/a96p\nhrJvYKfcaDb5EGIk6ESCMa4ycLWT7fBK7OXKAu+7j6zFFUyNqhhW0WIt+2o3\nP7Hpkgga/TUTKOx0WGV3cCVJHr5Qw1EVRU27Tk8HXwDij3CSHs5+mXJw2Noj\nbMo5q8fu8ejNshlSPRmXAaElAIev9boaBrBFZpH1hOap8kz/qCfDNScWHClL\nIsyFOHo5FIiw1WXAzwEimabEWGDLmQF2gadL0Y+mRH9bQ6MdHiVykkybVjLR\nkAute3pur+jEOsMMapCW0HvwhaJ9qTEwp09h7gspXMugw2IwEFTSUHywPiMe\nRWEa2atifAu98sBqXM+bnzkgPgiCsqbH1DWXDZ1+/sUq10mj6zKqvuQn+yu0\nrPqsxTHkBr54jWKY4OmT2WYRZa6cAl6yqP0TARHFGPvJqZEuee1kiwaiUhtI\nIBnF19CtNy8cTWwVSnKgSmpFMwhQys0SqE90PgLHe3UZRThv3UvNxTFdSkN5\npvl8VWY/D3wSmrmAX4+KVTjruKqegrFwjXMU80kdUmMBL3PC4MFDqjjMxPsA\ndILldQ/H/YhtVZVDUt/TP7CxZwBLa+Hvi0ilD4ASSjSFZ3Ndxr0uW8d4ce8P\nBVIs\r\n=0+XH\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","gitHead":"9bbde0557356495645914c07e95a3f9920f1d1f4","scripts":{"docs":"npx documentation readme index.js --section=API --shallow","test":"echo \"Error: no test specified\" && exit 1","publish":"npm run docs & npm publish --access public"},"_npmUser":{"name":"davert","email":"davert.ua@gmail.com"},"_npmVersion":"6.13.4","description":"Mocking requests with PollyJS for CodeceptJS","directories":{},"_nodeVersion":"12.14.1","dependencies":{"@pollyjs/core":"^4.0.2","@pollyjs/persister-fs":"^4.0.2","@pollyjs/adapter-puppeteer":"^4.0.2"},"_hasShrinkwrap":false,"devDependencies":{"puppeteer":"^2.1.1","codeceptjs":"^2.5.0","webdriverio":"^5.22.3","documentation":"^11.0.1"},"_npmOperationalInternal":{"tmp":"tmp/mock-request_0.2.0_1584824306441_0.3533388077849382","host":"s3://npm-registry-packages"}},"0.3.0":{"name":"@codeceptjs/mock-request","version":"0.3.0","keywords":["mock","pollyjs","codeceptjs","http-mock"],"author":{"name":"Michael Bodnarchuk @davert"},"license":"ISC","_id":"@codeceptjs/mock-request@0.3.0","maintainers":[{"name":"davert","email":"davert.ua@gmail.com"},{"name":"kaflan","email":"df117879@gmail.com"}],"dist":{"shasum":"4bc86a791d70a5923fcf3a9b8f06ffb21ea9d8b1","tarball":"https://registry.npmjs.org/@codeceptjs/mock-request/-/mock-request-0.3.0.tgz","fileCount":13,"integrity":"sha512-4MZkcNcvNhmtodkmuQ879N35GRoB98dNTEfawRZY9fNPDkFT13axg64XFiSF2im3Vnnr9aG3uPEJMpqqi+5myg==","signatures":[{"sig":"MEQCID1icoghRJ+qmYQm/ALouB53iwZ1vpKgyBboEn7oS02UAiATWR5NeI/VEQ53fBFUBpzlGLB2jE5Ol8gBfYxse5tbtA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":42874,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJef41aCRA9TVsSAnZWagAA9cQP/RRvocb+1lqsqEv6Bh6W\nQE6hEeTmA5kTPPAmWOCg64LMlRaAiTj3UF4H6PDi4GCuUN+WQ/gJ7Gghh54j\n1dIw+2YnWd1crgNRotiKCyUCZl3oYMBCMwg8tUNsqiUffWBPSPdUO+TucFNN\nIzZRJyVwwWngb/c3JXF9owrFdwlFy4kSARfm5XizjTg4d1bENcNUK+jb26mA\nS8NRbUM57FvVOpjFU4UcTSAEEzLkWeNFHFlZ6jLo13YE5/ScFZjO97/ECuIw\nQe9wPy7yKTEL7Z+u3FAnqLlzIfmjHL1k0m2/1wVDA4JcKk8QnTJoaUHnnMe7\nTaTZMgOMh6p8/NADd03lwpfMW4KwEj6RUyeSbY9fCYT3JZY7zyP6IAMv4Pae\nMJJvvxbNP7e/eyps+7zvtPNEym6BLsIBxk6AxSZYJ3cLPAaJlpWHL+zKV9fJ\ntZ2K8ltzXJovp+8R4UWmIkEn5ijEUtK2qaG1qV94x8y6KNACJFhDGPp8t/eV\neCVZnOZOhi6ry3ev+E/vQD9jvKaoFKteRrQuy1bAQ46dakfdmfltVHlIfRcB\nQvSW1s5NucXPFuFce/4mRW1qUZTCEWLJMohfzV6DEdILdSautrbimnUuv8Vb\n310WiRUReepHu0CGQRrhbGdW2iUhYMylIerthFH7ME/Co9tKLiLCHRqZeD8P\nWh04\r\n=R8ni\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","gitHead":"6cb7013d857eab8cefe204f21e35bdeb5e61a58d","scripts":{"docs":"npx documentation readme index.js --section=API --shallow","test":"npx codeceptjs run -c test/codecept.puppeteer.conf.js --debug --grep @Puppeteer","publish":"npm run docs & npm publish --access public","test-webdriver":"npx codeceptjs run -c test/codecept.webdriver.conf.js --debug --grep @WebDriver"},"_npmUser":{"name":"davert","email":"davert.ua@gmail.com"},"_npmVersion":"6.13.4","description":"Mocking requests with PollyJS for CodeceptJS","directories":{},"_nodeVersion":"12.14.1","dependencies":{"@pollyjs/core":"^4.0.4","@pollyjs/persister-fs":"^4.0.4","@pollyjs/adapter-puppeteer":"^4.0.4"},"_hasShrinkwrap":false,"devDependencies":{"rimraf":"^3.0.2","puppeteer":"^2.1.1","codeceptjs":"^2.5.0","webdriverio":"^5.22.4","documentation":"^11.0.1"},"_npmOperationalInternal":{"tmp":"tmp/mock-request_0.3.0_1585417562076_0.7259424164506247","host":"s3://npm-registry-packages"}},"0.3.1":{"name":"@codeceptjs/mock-request","version":"0.3.1","keywords":["mock","pollyjs","codeceptjs","http-mock"],"author":{"name":"Michael Bodnarchuk @davert"},"license":"ISC","_id":"@codeceptjs/mock-request@0.3.1","maintainers":[{"name":"davert","email":"davert.ua@gmail.com"},{"name":"kaflan","email":"df117879@gmail.com"}],"dist":{"shasum":"30c3cd50ced5ee42fb2d1883874adf007cb22918","tarball":"https://registry.npmjs.org/@codeceptjs/mock-request/-/mock-request-0.3.1.tgz","fileCount":13,"integrity":"sha512-w77IKJg/LiepyuQGaG4jUAAEFjU/l/AH9e+BcAwXBTsaLVtNZCRlViFsroHexSOSa6OHPp9VFrjR8PJFQpMjbw==","signatures":[{"sig":"MEUCIE1i0U33FHgcpUz8PSm4kBSzNB3PYofflHe6Z3S8IKpYAiEA1ldhd3j6chSMGXIAuKvfUKno//aFWeO+eeDBm+UdqTk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":43035,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhzdE/CRA9TVsSAnZWagAAdcwP/RX4l4amAJdlTXw0lmhV\nC5VKiq9FT53TB0q/LorixFpBPcJ6KyiBB6aGbwvykgoaYsqqjZQ8TOh9gX+c\nMAmACSKIPLG1ptrRN/W3cBqq66dqaLZdj8p8oweEmYg1rKDKMI59TNkbtYGA\nVFWXZ1e1E1EF1i1shG4P0vKZPXc8s74H9jOmYh8GDtjQAZWL3y4teVrn2AOG\nFd+nbjWEUAFPdfEO0k+jcnnsA75X5ynfKbsWnxigejgb/yrruEifw0/faARC\nV9CoGBPtIBw/AGBdhUsutJbp8nwL7nxKSs461ESQ7rTTab2+uFALrlvYN+FG\neXTgf1JX1qlL2LkxBnn+pXvA2wyrTOcD51Z6nM0l0Q65ijJovJMX9uxL/2/2\n/r031tF+D29Vn73doW+owF60vMJ7EEmrzYRwkAPEnBe8FFWKmvxhI/EPb0Pa\n7n/8o2yI2e5wVnOSYxYju47Veob38+q7CJwF/CqgJu3SSPgc+NIKK+a5bwaw\nAm+u+hyV9M5QVg8pThjyT3yxSdDcPeu1IQqvAeviYf2OVYLGaDWovzekxkb7\n77iP2f9Y6eId+riiFlwJpmYOnIRXLDw0pJgYDt43M5oHeYQRE74oL1N7ajqk\nsVdoxB7oOBmaew/PNBYygFD0uEHW6tNGKOhso8QtPzJQMqSom7g82Rl9FTcF\n84Vw\r\n=uofE\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","gitHead":"e68b7e1fe1cd5e96eff8938271715ff8b58aab3b","scripts":{"docs":"npx documentation readme index.js --section=API --shallow","test":"npx codeceptjs run -c test/codecept.puppeteer.conf.js --debug --grep @Puppeteer","publish":"npm run docs & npm publish --access public","test-webdriver":"npx codeceptjs run -c test/codecept.webdriver.conf.js --debug --grep @WebDriver"},"_npmUser":{"name":"davert","email":"davert.ua@gmail.com"},"_npmVersion":"6.14.13","description":"Mocking requests with PollyJS for CodeceptJS","directories":{},"_nodeVersion":"14.17.3","dependencies":{"@pollyjs/core":"^5.1.1","@pollyjs/persister-fs":"^5.1.1","@pollyjs/adapter-puppeteer":"^5.1.1"},"_hasShrinkwrap":false,"devDependencies":{"rimraf":"^3.0.2","puppeteer":"^11.0.0","codeceptjs":"^3.1.3","webdriverio":"^7.16.5","documentation":"^13.2.5"},"_npmOperationalInternal":{"tmp":"tmp/mock-request_0.3.1_1636543703248_0.20835601767814582","host":"s3://npm-registry-packages"}}},"time":{"created":"2020-03-20T12:46:58.031Z","modified":"2026-04-13T13:07:46.079Z","0.1.0":"2020-03-20T12:46:58.446Z","0.2.0":"2020-03-21T20:58:26.605Z","0.3.0":"2020-03-28T17:46:02.189Z","0.3.1":"2021-11-10T11:28:23.395Z"},"author":{"name":"Michael Bodnarchuk @davert"},"license":"ISC","keywords":["mock","pollyjs","codeceptjs","http-mock"],"description":"Mocking requests with PollyJS for CodeceptJS","maintainers":[{"email":"davert.ua@gmail.com","name":"davert"}],"readme":"# MockRequest helper for CodeceptJS\n\n[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fcodecept-js%2Fmock-request%2Fbadge&style=popout)](https://actions-badge.atrox.dev/codecept-js/mock-request/goto)\n\n> Playwright engine is not supported by this helper. Use native [Playwright API to mock requests](https://codecept.io/playwright/#mocking-network-requests). \n\n👻 Implements HTTP request mocking, record & replay via [PollyJS](https://netflix.github.io/pollyjs/#/) for [CodeceptJS](https://codecept.io). \n\nUse it to:\n\n-   📼 Record & Replay HTTP requests\n-   📲 Replace server responses\n-   ⛔ Block third party integrations: analytics, chats, support systems. \n\nWorks with Puppeteer & WebDriver helpers of [CodeceptJS](https://codecept.io).\n\n## API\n\n<!-- Generated by documentation.js. Update this documentation by updating the source code. -->\n\n#### Table of Contents\n\n-   [MockRequest](#mockrequest)\n    -   [Installations](#installations)\n    -   [Configuration](#configuration)\n        -   [With Puppeteer](#with-puppeteer)\n        -   [With WebDriver](#with-webdriver)\n-   [Usage](#usage)\n    -   [👻 Mock Requests](#-mock-requests)\n    -   [📼 Record & Replay](#-record--replay)\n    -   [Parameters](#parameters)\n    -   [startMocking](#startmocking)\n        -   [Parameters](#parameters-1)\n    -   [mockServer](#mockserver)\n        -   [Parameters](#parameters-2)\n    -   [recordMocking](#recordmocking)\n    -   [replayMocking](#replaymocking)\n    -   [passthroughMocking](#passthroughmocking)\n    -   [flushMocking](#flushmocking)\n    -   [stopMocking](#stopmocking)\n    -   [mockRequest](#mockrequest-1)\n        -   [Parameters](#parameters-3)\n\n### MockRequest\n\nThis helper allows to **mock requests while running tests in Puppeteer or WebDriver**.\nFor instance, you can block calls to 3rd-party services like Google Analytics, CDNs.\nAnother way of using is to emulate requests from server by passing prepared data.\n\nMockRequest helper works in these [modes](https://netflix.github.io/pollyjs/#/configuration?id=mode):\n\n-   passthrough (default) - mock prefefined HTTP requests\n-   record - record all requests into a file\n-   replay - replay all recorded requests from a file\n\nCombining record/replay modes allows testing websites with large datasets. \n\nTo use in passthrough mode set rules to mock requests and they will be automatically intercepted and replaced:\n\n```js\n// default mode\nI.mockRequest('GET', '/api/users', '[]');\n```\n\nIn record-replay mode start mocking to make HTTP requests recorded/replayed, and stop when you don't need to block requests anymore:\n\n```js\n// record or replay all XHR for /users page\nI.startMocking();\nI.amOnPage('/users');\nI.stopMocking();\n```\n\n#### Installations\n\n    npm i @codeceptjs/mock-request --save-dev\n\nRequires Puppeteer helper or WebDriver helper enabled\n\n#### Configuration\n\n##### With Puppeteer\n\nEnable helper in config file:\n\n```js\nhelpers: {\n   Puppeteer: {\n     // regular Puppeteer config here\n   },\n   MockRequestHelper: {\n     require: '@codeceptjs/mock-request',\n   }\n}\n```\n\n[Polly config options](https://netflix.github.io/pollyjs/#/configuration?id=configuration) can be passed as well:\n\n```js\n// sample options\nhelpers: {\n  MockRequestHelper: {\n     require: '@codeceptjs/mock-request',\n     mode: record,\n     recordIfMissing: true,\n     recordFailedRequests: false,\n     expiresIn: null,\n     persisterOptions: {\n       keepUnusedRequests: false\n       fs: {\n         recordingsDir: './data/requests',\n       },\n    },\n  }\n}\n```\n\n* * *\n\n**TROUBLESHOOTING**: Puppeteer does not mock requests in headless mode: \n\nProblem: request mocking does not work and in debug mode you see this in output:\n\n    Access to fetch at {url} from origin {url} has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.\n\nSolution: update Puppeteer config to include `--disable-web-security` arguments:\n\n```js\n Puppeteer: {\n   show: false,\n   chrome: {\n     args: [\n       '--disable-web-security',\n     ],\n   },\n },\n```\n\n* * *\n\n##### With WebDriver\n\nThis helper partially works with WebDriver. It can intercept and mock requests **only on already loaded page**.\n\n```js\nhelpers: {\n   WebDriver: {\n     // regular WebDriver config here\n   },\n   MockRequestHelper: {\n     require: '@codeceptjs/mock-request',\n   }\n}\n```\n\n> Record/Replay mode is not tested in WebDriver but technically can work with [REST Persister](https://netflix.github.io/pollyjs/#/examples?id=rest-persister)\n\n### Usage\n\n#### 👻 Mock Requests\n\nTo intercept API requests and mock them use following API\n\n-   [startMocking()](#startMocking) - to enable request interception\n-   [mockRequest()](#mockRequest) - to define mock in a simple way\n-   [mockServer()](#mockServer) - to use PollyJS server API to define complex mocks\n-   [stopMocking()](#stopMocking) - to stop intercepting requests and disable mocks.\n\nCalling `mockRequest` or `mockServer` will start mocking, if it was not enabled yet.\n\n```js\nI.startMocking(); // optionally\nI.mockRequest('/google-analytics/*path', 200);\n// return an empty successful response \nI.mockRequest('GET', '/api/users', 200);\n// mock users api\nI.mockServer(server => {\n  server.get('https://server.com/api/users*').\n    intercept((req, res) => { res.status(200).json(users);\n  });\n});\nI.click('Get users);\nI.stopMocking();\n```\n\n#### 📼 Record & Replay\n\n> At this moment works only with Puppeteer\n\nRecord & Replay mode allows you to record all xhr & fetch requests and save them to file.\nOn next runs those requests can be replayed. \nBy default, it stores all passed requests, but this behavior can be customized with `I.mockServer`\n\nSet mode via enironment variable, `replay` mode by default:\n\n```js\n// enable replay mode\nhelpers: {\n Puppeteer: {\n   // regular Puppeteer config here\n },\n MockRequest: {\n    require: '@codeceptjs/mock-request',\n    mode: process.env.MOCK_MODE || 'replay',\n },\n}\n```\n\nInteractions between `I.startMocking()` and `I.stopMocking()` will be recorded and saved to `data/requests` directory.\n\n```js\nI.startMocking() // record requests under 'Test' name\nI.startMocking('users') // record requests under 'users' name\n```\n\nUse `I.mockServer()` to customize which requests should be recorded and under which name:\n\n```js\nI.startMocking();\nI.mockServer((server) => {\n  // mock request only from ap1.com and api2.com and\n  // store recording into two different files\n  server.any('https://api1.com/*').passthrough(false).recordingName('api1');\n  server.any('https://api2.com/*').passthrough(false).recordingName('api2');\n});\n```\n\nTo stop request recording/replaying use `I.stopMocking()`.\n\n🎥 To record HTTP interactions execute tests with MOCK_MODE environment variable set as \"record\":\n\n    MOCK_MODE=record npx codeceptjs run --debug\n\n📼 To replay them launch tests without environment variable:\n\n    npx codeceptjs run --debug\n\n#### Parameters\n\n-   `config`  \n\n#### startMocking\n\nStarts mocking of http requests.\nIn record mode starts recording of all requests.\nIn replay mode blocks all requests and replaces them with saved.\n\nIf inside one test you plan to record/replay requests in several places, provide [recording name](https://netflix.github.io/pollyjs/#/api?id=recordingname) as the parameter.\n\n```js\n// start mocking requests for a test\nI.startMocking(); \n\n// start mocking requests for main page\nI.startMocking('main-page');\n// do actions\nI.stopMocking();\nI.startMocking('login-page');\n```\n\nTo update [PollyJS configuration](https://netflix.github.io/pollyjs/#/configuration) use secon argument:\n\n```js\n// change mode\nI.startMocking('comments', { mode: 'replay' });\n\n// override config\nI.startMocking('users-loaded', {\n   recordFailedRequests: true\n})\n```\n\n##### Parameters\n\n-   `title` **any**  (optional, default `'Test'`)\n-   `config`   (optional, default `{}`)\n\n#### mockServer\n\nUse PollyJS [Server Routes API](https://netflix.github.io/pollyjs/#/server/overview) to declare mocks via callback function:\n\n```js\n// basic usage\nserver.get('/api/v2/users').intercept((req, res) => {\n  res.sendStatus(200).json({ users });\n});\n\n// passthrough requests to \"/api/v2\"\nserver.get('/api/v1').passthrough();\n```\n\nIn record replay mode you can define which routes should be recorded and where to store them:\n\n```js\nI.startMocking('mock');\nI.mockServer((server) => {\n\n  // record requests from cdn1.com and save them to data/recording/xml\n  server.any('https://cdn1.com/*').passthrough(false).recordingName('xml');\n  \n  // record requests from cdn2.com and save them to data/recording/svg\n  server.any('https://cdn2.com/*').passthrough(false).recordingName('svg');\n\n  // record requests from /api and save them to data/recording/mock (default)\n  server.any('/api/*').passthrough(false);\n});\n```\n\n##### Parameters\n\n-   `configFn`  \n\n#### recordMocking\n\nForces record mode for mocking.\nRequires mocking to be started.\n\n```js\nI.recordMocking();\n```\n\n#### replayMocking\n\nForces replay mode for mocking.\nRequires mocking to be started.\n\n```js\nI.replayMocking();\n```\n\n#### passthroughMocking\n\nForces passthrough mode for mocking.\nRequires mocking to be started.\n\n```js\nI.passthroughMocking();\n```\n\n#### flushMocking\n\nWaits for all requests handled by MockRequests to be resolved:\n\n```js\nI.flushMocking();\n```\n\n#### stopMocking\n\nStops mocking requests.\nMust be called to save recorded requests into faile.\n\n```js\nI.stopMocking();\n```\n\n#### mockRequest\n\nMock response status\n\n```js\nI.mockRequest('GET', '/api/users', 200);\nI.mockRequest('ANY', '/secretsRoutes/*', 403);\nI.mockRequest('POST', '/secrets', { secrets: 'fakeSecrets' });\nI.mockRequest('GET', '/api/users/1', 404, 'User not found');\n```\n\nMultiple requests\n\n```js\nI.mockRequest('GET', ['/secrets', '/v2/secrets'], 403);\n```\n\n##### Parameters\n\n-   `method` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** request method. Can be `GET`, `POST`, `PUT`, etc or `ANY`.\n-   `oneOrMoreUrls` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \\| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)** url(s) to mock. Can be exact URL, a pattern, or an array of URLs.\n-   `dataOrStatusCode` **([number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) \\| [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \\| [object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))** status code when number provided. A response body otherwise\n-   `additionalData` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \\| [object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))** response body when a status code is set by previous parameter. (optional, default `null`)\n","readmeFilename":"README.md"}