@tapico/msw-webarchive
Advanced tools
Comparing version 1.0.1 to 1.0.3
# Changelog | ||
## [1.0.3](https://github.com/Tapico/tapico-msw-webarchive/compare/v1.0.2...v1.0.3) (2024-04-13) | ||
### Bug Fixes | ||
* remove the missing version:update call ([22f0e9e](https://github.com/Tapico/tapico-msw-webarchive/commit/22f0e9ed4afee233d4a5db5f09b7e1a23019e9d5)) | ||
## [1.0.2](https://github.com/Tapico/tapico-msw-webarchive/compare/v1.0.1...v1.0.2) (2024-04-13) | ||
### Bug Fixes | ||
* update the GitHub workflows ([#31](https://github.com/Tapico/tapico-msw-webarchive/issues/31)) ([515815b](https://github.com/Tapico/tapico-msw-webarchive/commit/515815b9f091a66835c343faeb3edba110e8e9ad)) | ||
## [1.0.1](https://github.com/Tapico/tapico-msw-webarchive/compare/v1.0.0...v1.0.1) (2024-04-01) | ||
@@ -4,0 +18,0 @@ |
@@ -86,3 +86,3 @@ import { http, delay, HttpResponse } from 'msw'; | ||
const requestMethod = request.method.toLowerCase(); | ||
const supportedMethods = Object.keys(http).filter(method => method !== 'all'); | ||
const supportedMethods = Object.keys(http).filter((method) => method !== 'all'); | ||
logger(`Registering route for ${entry.request.method} for ${entry.request.url}`); | ||
@@ -116,4 +116,3 @@ if (!supportedMethods.includes(requestMethod)) { | ||
// Set the all headers for the response | ||
const responseHeaders = headers | ||
.reduce((headerObj, { name, value }) => { | ||
const responseHeaders = headers.reduce((headerObj, { name, value }) => { | ||
const lowercaseName = name.toLowerCase(); | ||
@@ -128,5 +127,3 @@ if (lowercaseName === 'content-encoding') { | ||
logger(`CORS header detected, requesting new origin for ${value}`); | ||
value = (options === null || options === void 0 ? void 0 : options.resolveCrossOrigins) | ||
? options.resolveCrossOrigins(value) | ||
: value; | ||
value = (options === null || options === void 0 ? void 0 : options.resolveCrossOrigins) ? options.resolveCrossOrigins(value) : value; | ||
} | ||
@@ -146,7 +143,9 @@ headerObj[name] = value; | ||
headers: responseHeaders, | ||
status: responseStatus | ||
status: responseStatus, | ||
}); | ||
}); | ||
// Ensure the right request route method is used for the registration | ||
const route = http[requestMethod](fullQualifiedUrl, resolver, { once: !!(options === null || options === void 0 ? void 0 : options.useUniqueRequests) }); | ||
const route = http[requestMethod](fullQualifiedUrl, resolver, { | ||
once: !!(options === null || options === void 0 ? void 0 : options.useUniqueRequests), | ||
}); | ||
if (!route) { | ||
@@ -170,3 +169,3 @@ return null; | ||
.map((definitionEntry) => createRequestHandler(definitionEntry, options)) | ||
.filter(handler => handler !== null); | ||
.filter((handler) => handler !== null); | ||
serverInstance.use(...requestHandlers); | ||
@@ -173,0 +172,0 @@ } |
@@ -90,3 +90,3 @@ (function (global, factory) { | ||
const requestMethod = request.method.toLowerCase(); | ||
const supportedMethods = Object.keys(msw.http).filter(method => method !== 'all'); | ||
const supportedMethods = Object.keys(msw.http).filter((method) => method !== 'all'); | ||
logger(`Registering route for ${entry.request.method} for ${entry.request.url}`); | ||
@@ -120,4 +120,3 @@ if (!supportedMethods.includes(requestMethod)) { | ||
// Set the all headers for the response | ||
const responseHeaders = headers | ||
.reduce((headerObj, { name, value }) => { | ||
const responseHeaders = headers.reduce((headerObj, { name, value }) => { | ||
const lowercaseName = name.toLowerCase(); | ||
@@ -132,5 +131,3 @@ if (lowercaseName === 'content-encoding') { | ||
logger(`CORS header detected, requesting new origin for ${value}`); | ||
value = (options === null || options === void 0 ? void 0 : options.resolveCrossOrigins) | ||
? options.resolveCrossOrigins(value) | ||
: value; | ||
value = (options === null || options === void 0 ? void 0 : options.resolveCrossOrigins) ? options.resolveCrossOrigins(value) : value; | ||
} | ||
@@ -150,7 +147,9 @@ headerObj[name] = value; | ||
headers: responseHeaders, | ||
status: responseStatus | ||
status: responseStatus, | ||
}); | ||
}); | ||
// Ensure the right request route method is used for the registration | ||
const route = msw.http[requestMethod](fullQualifiedUrl, resolver, { once: !!(options === null || options === void 0 ? void 0 : options.useUniqueRequests) }); | ||
const route = msw.http[requestMethod](fullQualifiedUrl, resolver, { | ||
once: !!(options === null || options === void 0 ? void 0 : options.useUniqueRequests), | ||
}); | ||
if (!route) { | ||
@@ -174,3 +173,3 @@ return null; | ||
.map((definitionEntry) => createRequestHandler(definitionEntry, options)) | ||
.filter(handler => handler !== null); | ||
.filter((handler) => handler !== null); | ||
serverInstance.use(...requestHandlers); | ||
@@ -177,0 +176,0 @@ } |
@@ -88,3 +88,3 @@ 'use strict'; | ||
const requestMethod = request.method.toLowerCase(); | ||
const supportedMethods = Object.keys(msw.http).filter(method => method !== 'all'); | ||
const supportedMethods = Object.keys(msw.http).filter((method) => method !== 'all'); | ||
logger(`Registering route for ${entry.request.method} for ${entry.request.url}`); | ||
@@ -118,4 +118,3 @@ if (!supportedMethods.includes(requestMethod)) { | ||
// Set the all headers for the response | ||
const responseHeaders = headers | ||
.reduce((headerObj, { name, value }) => { | ||
const responseHeaders = headers.reduce((headerObj, { name, value }) => { | ||
const lowercaseName = name.toLowerCase(); | ||
@@ -130,5 +129,3 @@ if (lowercaseName === 'content-encoding') { | ||
logger(`CORS header detected, requesting new origin for ${value}`); | ||
value = (options === null || options === void 0 ? void 0 : options.resolveCrossOrigins) | ||
? options.resolveCrossOrigins(value) | ||
: value; | ||
value = (options === null || options === void 0 ? void 0 : options.resolveCrossOrigins) ? options.resolveCrossOrigins(value) : value; | ||
} | ||
@@ -148,7 +145,9 @@ headerObj[name] = value; | ||
headers: responseHeaders, | ||
status: responseStatus | ||
status: responseStatus, | ||
}); | ||
}); | ||
// Ensure the right request route method is used for the registration | ||
const route = msw.http[requestMethod](fullQualifiedUrl, resolver, { once: !!(options === null || options === void 0 ? void 0 : options.useUniqueRequests) }); | ||
const route = msw.http[requestMethod](fullQualifiedUrl, resolver, { | ||
once: !!(options === null || options === void 0 ? void 0 : options.useUniqueRequests), | ||
}); | ||
if (!route) { | ||
@@ -155,0 +154,0 @@ return null; |
{ | ||
"name": "@tapico/msw-webarchive", | ||
"version": "1.0.1", | ||
"version": "1.0.3", | ||
"description": "An utility to drive requests handlers through a `.har` web-archive file", | ||
@@ -14,3 +14,6 @@ "main": "dist/umd/index.js", | ||
}, | ||
"./node": "./node/index.js", | ||
"./node": { | ||
"types": "./dist/types/node/index.d.ts", | ||
"default": "./node/index.js" | ||
}, | ||
"./package.json": "./package.json" | ||
@@ -69,3 +72,3 @@ }, | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.57.0", | ||
"eslint": "8.57.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
@@ -94,2 +97,3 @@ "eslint-plugin-prettier": "^5.1.3", | ||
"lint": "eslint \"src/**/*.ts\"", | ||
"format": "prettier .", | ||
"build": "pnpm run clean && cross-env NODE_ENV=production rollup -c rollup.config.mjs", | ||
@@ -96,0 +100,0 @@ "test": "pnpm run test:unit", |
# @tapico/msw-webarchive | ||
A utility to drive requests handlers through a `.har` web-archive file for the [Mock Service Worker](https://github.com/mswjs/msw) library. This utility allows you to mock server handlers by using `.har` web-archive file which can be created by using applications like Charles, ProxyMan or the Chrome Developer Tools. | ||
A utility to drive requests handlers through a `.har` web-archive file for the | ||
[Mock Service Worker](https://github.com/mswjs/msw) library. This utility allows you to mock server | ||
handlers by using `.har` web-archive file which can be created by using applications like Charles, | ||
ProxyMan or the Chrome Developer Tools. | ||
## Why you use this? | ||
We have been using it during the development of web-applications, while the backend API endpoints weren't available yet or when we want to reproduce a problem of a customer. This way we can request the customer to send us a .har web-archive file and let this file drive the network requests to our back-end, this has greatly eased reproducing problems reported. | ||
We have been using it during the development of web-applications, while the backend API endpoints | ||
weren't available yet or when we want to reproduce a problem of a customer. This way we can request | ||
the customer to send us a .har web-archive file and let this file drive the network requests to our | ||
back-end, this has greatly eased reproducing problems reported. | ||
## Getting started | ||
To use this library you need to have a HAR (`*.har`) file generated from the network traffic of your application. Follow the instructions below to learn how to do that. | ||
To use this library you need to have a HAR (`*.har`) file generated from the network traffic of your | ||
application. Follow the instructions below to learn how to do that. | ||
@@ -29,3 +36,4 @@ ### Install | ||
- Open the DevTools in Chrome (<kbd>Option</kbd> + <kbd>Command</kbd> + <kbd>I</kbd> / <kbd>Shift</kbd> + <kbd>CTRL</kbd> + <kbd>J</kbd>). | ||
- Open the DevTools in Chrome (<kbd>Option</kbd> + <kbd>Command</kbd> + <kbd>I</kbd> / | ||
<kbd>Shift</kbd> + <kbd>CTRL</kbd> + <kbd>J</kbd>). | ||
- Go to the "_Network_" tab in the DevTools. | ||
@@ -39,3 +47,4 @@ - Click on the downward-facing arrow icon to "_Export HAR_". | ||
- Open the DevTools in Firefox (<kbd>Option</kbd> + <kbd>Command</kbd> + <kbd>I</kbd> / <kbd>Shift</kbd> + <kbd>CTRL</kbd> + <kbd>I</kbd>). | ||
- Open the DevTools in Firefox (<kbd>Option</kbd> + <kbd>Command</kbd> + <kbd>I</kbd> / | ||
<kbd>Shift</kbd> + <kbd>CTRL</kbd> + <kbd>I</kbd>). | ||
- Go to the "_Network_" tab in the DevTools. | ||
@@ -77,3 +86,4 @@ - Click on the cog icon on the left of the top bar. | ||
Stricly match a request URL query parameters during request URL matching. When set to `false`, request URL query parameters are ignored during matching. | ||
Stricly match a request URL query parameters during request URL matching. When set to `false`, | ||
request URL query parameters are ignored during matching. | ||
@@ -104,3 +114,5 @@ ```js | ||
Allow mapping the domains in your har file to something else. This may be useful if you are making relative requests against the origin (eg. `fetch('/hello')`), you may want to use a domainMapping configuration like: | ||
Allow mapping the domains in your har file to something else. This may be useful if you are making | ||
relative requests against the origin (eg. `fetch('/hello')`), you may want to use a domainMapping | ||
configuration like: | ||
@@ -110,10 +122,7 @@ ```js | ||
domainMappings: { | ||
"http://example.com" : "http://localhost" | ||
} | ||
}); | ||
'http://example.com': 'http://localhost', | ||
}, | ||
}) | ||
``` | ||
[msw-install]: https://mswjs.io/docs/getting-started/install |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
35442
124
0
536