playwright-msw
Advanced tools
Comparing version
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -10,6 +11,11 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { createMiddleware } from "@mswjs/http-middleware"; | ||
import { json } from "body-parser"; | ||
import express from "express"; | ||
import fetch from "node-fetch"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createServer = void 0; | ||
const http_middleware_1 = require("@mswjs/http-middleware"); | ||
const body_parser_1 = require("body-parser"); | ||
const express_1 = __importDefault(require("express")); | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const rewriteBaseURL = (handler, baseUrl) => { | ||
@@ -31,3 +37,3 @@ const currentMethod = handler.info.method; | ||
.replace(`localhost:${webServerPort}`, `localhost:${workerServerPort}`); | ||
return fetch(url, Object.assign(Object.assign({ method }, (["POST", "PATCH", "PUT"].includes(method) | ||
return (0, node_fetch_1.default)(url, Object.assign(Object.assign({ method }, (["POST", "PATCH", "PUT"].includes(method) | ||
? { | ||
@@ -46,6 +52,6 @@ body: (_a = request.postData()) !== null && _a !== void 0 ? _a : "", | ||
} | ||
const app = express(); | ||
app.use(json()); | ||
const app = (0, express_1.default)(); | ||
app.use((0, body_parser_1.json)()); | ||
const transformedHandlers = [...customHandlers, ...handlers].map((handler) => rewriteBaseURL(handler, `http://localhost:${port}`)); | ||
app.use(createMiddleware(...transformedHandlers)); | ||
app.use((0, http_middleware_1.createMiddleware)(...transformedHandlers)); | ||
yield new Promise((resolve) => { | ||
@@ -81,3 +87,3 @@ server = app.listen(port, () => { | ||
}; | ||
export const createServer = ({ page, info, url, handlers, webServerPort, baseWorkerServerPort, }) => __awaiter(void 0, void 0, void 0, function* () { | ||
const createServer = ({ page, info, url, handlers, webServerPort, baseWorkerServerPort, }) => __awaiter(void 0, void 0, void 0, function* () { | ||
const workerServerPort = baseWorkerServerPort + info.parallelIndex; | ||
@@ -107,1 +113,2 @@ const worker = createWorker(workerServerPort, ...handlers); | ||
}); | ||
exports.createServer = createServer; |
{ | ||
"name": "playwright-msw", | ||
"version": "0.0.2", | ||
"description": "A Mock Service Worker API for Playwright", | ||
"version": "0.0.3", | ||
"description": "A Mock Service Worker API for Playwright.", | ||
"main": "lib/server.js", | ||
@@ -6,0 +6,0 @@ "files": [ |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
9685
4.53%125
5.93%0
-100%