puppeteer-rq
If you are writing puppeteer tests, and you want to mock your network responses easily – then this package will help you.
Getting Started
Installing
To use "Puppeteer-rq" in your project, run:
npm i --save-dev puppeteer-rq
Usage
// first you need to import the package;// start mocker with paramsawait mockerstartoptions; // and stop mocker after test runawait mocker;//Both `mocker.start()` and `mocker.stop()` return a `Promise`.
You could use options
const options = // puppeteer page page: page // default namespace: '__remocks__' namespace: 'mockDirPath' mockList: '_api/method': 'mockFilePath' '_api/method2': GET: 'getMockFilePath' POST: 'postMockFilePath' '_api/method3': GET: body: 'response' queryParams: test: '123' '_api/method4': GET: body: 'response' headers: 'Content-Type': 'application/json' POST: filePath: 'postMockFilePath' headers: 'Content-Type': 'application/json' // default: false // interruption of requests that are not in mockList and request.resourceType() == 'xhr' or 'fetch' ci: true