Wondering what’s next for npm?Check out our public roadmap! »

playwright-rq

1.0.1 • Public • Published

playwright-rq

NPM version NPM Downloads

If you are writing playwright tests, and you want to mock your network responses easily – then this package will help you.

Getting Started

Installing

To use "Playwright-rq" in your project, run:

npm i --save-dev playwright-rq

Usage

// first you need to import the package
import mocker from 'playwright-rq';
// start mocker with params
await mocker.start(options);

// and stop mocker after test run
await mocker.stop();
//Both `mocker.start()` and `mocker.stop()` return a `Promise`.

You could use options

const options = {
  // playwright 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
}

Install

npm i playwright-rq

DownloadsWeekly Downloads

46

Version

1.0.1

License

ISC

Unpacked Size

23.1 kB

Total Files

17

Last publish

Collaborators

  • avatar