Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
playwright-msw
Advanced tools
A Mock Service Worker API for Playwright.
The example below shows how playwright-msw
can be be used to create custom test fixtures which allow API calls to be automatically mocked, while also exposing the msw
worker instance as a fixture so that mocks may be overridden on a per test basis. For an up to date example, please refer to test.ts.
import { test as base, expect } from "@playwright/test";
import { rest } from "msw";
import type { MockServiceWorker } from "playwright-msw";
import { createWorkerFixture } from "playwright-msw";
const handlers = [
rest.get("/api/users", (_, response, context) =>
response(
context.delay(500),
context.status(200),
context.json([
{
id: "bcff5c0e-10b6-407b-94d1-90d741363885",
firstName: "Rhydian",
lastName: "Greig",
},
{
id: "b44e89e4-3254-415e-b14a-441166616b20",
firstName: "Alessandro",
lastName: "Metcalfe",
},
{
id: "6e369942-6b5d-4159-9b39-729646549183",
firstName: "Erika",
lastName: "Richards",
},
])
)
),
];
const test = base.extend<{
worker: MockServiceWorker;
rest: typeof rest;
}>({
worker: createWorkerFixture(...handlers),
rest,
});
export { text, expect };
The example below shows playwright-msw
can be used to automatically mock API calls, while still allowing them to be mocked on a per test basis. For an up to date example, please refer to demo.spec.ts.
import { expect, test } from "../test";
test.describe.parallel("A demo of playwright-msw's functionality", () => {
test("should use the default handlers without requiring handlers to be specified on a per-test basis", async ({
page,
}) => {
await page.goto("/");
await expect(page.locator('text="Alessandro Metcalfe"')).toBeVisible();
});
test.only("should allow mocks to be overridden on a per test basis", async ({
page,
worker,
rest,
}) => {
await worker.use(
rest.get("/api/users", (_, response, context) =>
response(context.delay(250), context.status(403))
)
);
await page.goto("/");
await expect(page.locator('text="Alessandro Metcalfe"')).toBeHidden();
await expect(page.locator('text="Failed to load users"')).toBeVisible();
});
});
FAQs
A Mock Service Worker API for Playwright.
The npm package playwright-msw receives a total of 53,902 weekly downloads. As such, playwright-msw popularity was classified as popular.
We found that playwright-msw demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.