{"id":18836748,"url":"https://github.com/nkyazhin/playwright-rq","last_synced_at":"2025-10-05T02:28:15.283Z","repository":{"id":46160429,"uuid":"314194218","full_name":"nkyazhin/playwright-rq","owner":"nkyazhin","description":"If you are writing playwright tests, and you want to mock your network responses easily – then this package will help you.","archived":false,"fork":false,"pushed_at":"2021-11-10T08:39:17.000Z","size":39,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T20:06:09.977Z","etag":null,"topics":["mocker","playwright","playwright-rq"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nkyazhin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-19T09:12:20.000Z","updated_at":"2022-12-21T19:33:45.000Z","dependencies_parsed_at":"2022-08-31T20:10:48.312Z","dependency_job_id":null,"html_url":"https://github.com/nkyazhin/playwright-rq","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkyazhin%2Fplaywright-rq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkyazhin%2Fplaywright-rq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkyazhin%2Fplaywright-rq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkyazhin%2Fplaywright-rq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nkyazhin","download_url":"https://codeload.github.com/nkyazhin/playwright-rq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248830826,"owners_count":21168353,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mocker","playwright","playwright-rq"],"created_at":"2024-11-08T02:31:50.890Z","updated_at":"2025-10-05T02:28:10.249Z","avatar_url":"https://github.com/nkyazhin.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# playwright-rq\n\n[![NPM version](https://img.shields.io/npm/v/playwright-rq.svg)](https://www.npmjs.com/package/playwright-rq)\n[![NPM Downloads](https://img.shields.io/npm/dm/playwright-rq.svg?style=flat)](https://www.npmjs.org/package/playwright-rq)\n\nIf you are using playwright, and you need mock your network responses, then playwright-rq will help you!\n\n## Installing\n\n```\nnpm i --save-dev playwright-rq\n```\n\n## Usage\n\n### Mocker\n\nAllows you to mock for your network responses.\n\n```ts\nimport { Mocker } from 'playwright-rq';\nconst mocker = new Mocker();\n// start mocker with options\nawait mocker.start({\n  page,\n  mockList: {\n    test: {\n      url: 'http://localhost:3000/api',\n      method: 'GET',\n      response: {\n        body: 'test',\n        status: 200,\n      },\n    },\n  },\n});\n// update mocker params\nmocker.update({\n  test: {\n    url: 'http://localhost:3000/api',\n    method: 'GET',\n    response: {\n      body: 'test',\n      status: 200,\n    },\n  },\n});\n\n// stop mocker\nawait mocker.stop();\n```\n\n#### start options\n\n```ts\nconst options = {\n  // playwright page\n  page: Page,\n  // Indicates where are mocks. Default rootDir = '__remocks__'\n  // Absolute path = path.resolve(process.cwd(), rootDir)\n  rootDir: 'test/__remocks__',\n  // If interceptType does not contain playwright request.resourceType(),\n  // then call route.continue()\n  // Default interceptType = new Set(['xhr', 'fetch'])\n  interceptType: new Set(['xhr', 'image']),\n  // If could not find mock for request,\n  // and ci = true, then call route.abort().\n  // Default ci = false\n  ci: true,\n  // mockList = Record\u003cstring, RequestParams\u003e\n  // interface RequestParams {\n  //   url: string | RegExp;\n  //   method: string;\n  //   queryParams?: Record\u003cstring, string\u003e;\n  //   bodyParams?: Record\u003cstring, any\u003e;\n  //   resopnse?: {\n  //     status?: number;\n  //     headers?: Record\u003cstring, string\u003e;\n  //     body?: string;\n  //     filePath?: string;\n  //   }\n  // }\n  // Default response = {\n  //   status: 200,\n  //   headers: {\n  //     'Content-Type': 'application/json; charset=UTF-8',\n  //   },\n  // }\n  mockList: {\n    mockName: {\n      url: '/api/test',\n      method: 'post',\n      resopnse: {\n        body: '{test:\"1234\"}',\n      },\n    },\n    test: {\n      url: /api\\/test/,\n      method: 'get',\n      queryParams: {\n        abst: '1234',\n      },\n      response: {\n        status: 200,\n        filePath: 'test',\n      },\n    },\n    mockParams: {\n      url: /api\\/test/,\n      method: 'get',\n      bodyParams: {\n        abst: '1234',\n      },\n      response: {\n        status: 200,\n        headers: {\n          'Content-Type': 'text/html; charset=utf-8',\n        },\n        body: 'text',\n      },\n    },\n  },\n};\n```\n\n#### update options\n\nUpdates mockList which you added to `mocker.start()`.\nIf a mock with such a key already exists, it is updated, otherwise it adds.\n\n```ts\nmocker.update({\n  test: {\n    url: 'http://localhost:3000/api',\n    method: 'GET',\n    response: {\n      body: 'test',\n      status: 200,\n    },\n  },\n});\n```\n\n### RequestListener\n\nAllows you to wait for a request, and return [Playwright Request](https://playwright.dev/docs/api/class-request) object.\n\n```ts\nimport { RequestListener } from 'playwright-rq';\n// start listener for request\nconst requestListener = new RequestListener({ page, url: 'http://localhost:3000/api' });\nawait page.click('#button');\n// wait request. Dafault timetout = 1000\nconst request = await requestListener.waitForRequest(3000);\nexpect(request.postDataJSON()).toEqual({ test: '1234' });\n```\n\nIf the request is not found after the specified timeout, then we get an error: `Request \"${url}\" not found, after ${timeout}ms`\n\n## Debug\n\n`playwright-rq` uses `debug` package for logs.\nExample: `DEBUG=playwright-rq* npm run test`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnkyazhin%2Fplaywright-rq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnkyazhin%2Fplaywright-rq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnkyazhin%2Fplaywright-rq/lists"}