Comparing version 0.3.3 to 0.3.4
@@ -0,1 +1,2 @@ | ||
/// <reference types="ts-toolbelt" /> | ||
import { Mask } from '../composeMocks'; | ||
@@ -25,3 +26,3 @@ import { MockedContext } from '../context'; | ||
} | ||
declare const createHandler: import("ts-toolbelt/out/types/src/Function/Curry").Curry<(method: RESTMethods, mask: Mask, resolver: ResponseResolver) => SchemaEntryGetter>; | ||
declare const createHandler: import("Function/Curry").Curry<(method: RESTMethods, mask: Mask, resolver: ResponseResolver) => SchemaEntryGetter>; | ||
export default createHandler; |
@@ -0,9 +1,10 @@ | ||
/// <reference types="ts-toolbelt" /> | ||
declare const _default: { | ||
get: import("ts-toolbelt/out/types/src/Function/Curry").Curry<(mask: import("../composeMocks").Mask, resolver: import("./createHandler").ResponseResolver) => import("./createHandler").SchemaEntryGetter>; | ||
post: import("ts-toolbelt/out/types/src/Function/Curry").Curry<(mask: import("../composeMocks").Mask, resolver: import("./createHandler").ResponseResolver) => import("./createHandler").SchemaEntryGetter>; | ||
put: import("ts-toolbelt/out/types/src/Function/Curry").Curry<(mask: import("../composeMocks").Mask, resolver: import("./createHandler").ResponseResolver) => import("./createHandler").SchemaEntryGetter>; | ||
delete: import("ts-toolbelt/out/types/src/Function/Curry").Curry<(mask: import("../composeMocks").Mask, resolver: import("./createHandler").ResponseResolver) => import("./createHandler").SchemaEntryGetter>; | ||
patch: import("ts-toolbelt/out/types/src/Function/Curry").Curry<(mask: import("../composeMocks").Mask, resolver: import("./createHandler").ResponseResolver) => import("./createHandler").SchemaEntryGetter>; | ||
options: import("ts-toolbelt/out/types/src/Function/Curry").Curry<(mask: import("../composeMocks").Mask, resolver: import("./createHandler").ResponseResolver) => import("./createHandler").SchemaEntryGetter>; | ||
get: import("Function/Curry").Curry<(mask: import("../composeMocks").Mask, resolver: import("./createHandler").ResponseResolver) => import("./createHandler").SchemaEntryGetter>; | ||
post: import("Function/Curry").Curry<(mask: import("../composeMocks").Mask, resolver: import("./createHandler").ResponseResolver) => import("./createHandler").SchemaEntryGetter>; | ||
put: import("Function/Curry").Curry<(mask: import("../composeMocks").Mask, resolver: import("./createHandler").ResponseResolver) => import("./createHandler").SchemaEntryGetter>; | ||
delete: import("Function/Curry").Curry<(mask: import("../composeMocks").Mask, resolver: import("./createHandler").ResponseResolver) => import("./createHandler").SchemaEntryGetter>; | ||
patch: import("Function/Curry").Curry<(mask: import("../composeMocks").Mask, resolver: import("./createHandler").ResponseResolver) => import("./createHandler").SchemaEntryGetter>; | ||
options: import("Function/Curry").Curry<(mask: import("../composeMocks").Mask, resolver: import("./createHandler").ResponseResolver) => import("./createHandler").SchemaEntryGetter>; | ||
}; | ||
export default _default; |
{ | ||
"name": "msw", | ||
"version": "0.3.3", | ||
"description": "Serverless client-side API mocking without a single change to the codebase.", | ||
"version": "0.3.4", | ||
"description": "Deviation-less client-side runtime API mocking using Service Workers.", | ||
"main": "lib/index.js", | ||
@@ -22,5 +22,12 @@ "types": "lib/index.d.ts", | ||
"license": "MIT", | ||
"files": [ | ||
"cli", | ||
"lib", | ||
"mockServiceWorker.js", | ||
"LICENSE.md", | ||
"README.md" | ||
], | ||
"dependencies": { | ||
"chalk": "^2.4.2", | ||
"path-to-regexp": "3.0.0", | ||
"chalk": "^3.0.0", | ||
"path-to-regexp": "3.1.0", | ||
"ramda": "0.26.1", | ||
@@ -30,4 +37,4 @@ "yargs": "14.0.0" | ||
"devDependencies": { | ||
"@babel/core": "^7.6.0", | ||
"@babel/preset-env": "^7.6.0", | ||
"@babel/core": "^7.8.3", | ||
"@babel/preset-env": "^7.8.3", | ||
"@types/jest": "24.0.18", | ||
@@ -38,13 +45,13 @@ "@types/ramda": "^0.26.21", | ||
"babel-plugin-ramda": "2.0.0", | ||
"cross-env": "^5.2.0", | ||
"cross-env": "^7.0.0", | ||
"express": "^4.17.1", | ||
"jest": "24.9.0", | ||
"jest": "^25.1.0", | ||
"node-fetch": "^2.6.0", | ||
"prettier": "^1.18.2", | ||
"prettier": "^1.19.1", | ||
"regenerator-runtime": "0.13.3", | ||
"ts-jest": "^24.1.0", | ||
"typescript": "^3.5.3", | ||
"webpack": "^4.40.2", | ||
"webpack-cli": "^3.3.8" | ||
"ts-jest": "^25.0.0", | ||
"typescript": "^3.7.5", | ||
"webpack": "^4.41.0", | ||
"webpack-cli": "^3.3.9" | ||
} | ||
} |
@@ -18,3 +18,3 @@ <p align="center"> | ||
<p align="center">MSW (<i>Mock Service Worker</i>) is a library for mocking requests to actual production URI.</p> | ||
<p align="center">MSW (<i>Mock Service Worker</i>) is an API mocking library that operates by intercepting production requests.</p> | ||
@@ -24,3 +24,3 @@ ## Features | ||
- **Server-less**. Doesn't establish any servers, operates entirely in a browser; | ||
- **Deviation-free**. Request the very same resources (urls) you would in production, and let MSW _intercept_ them and mock their responses; | ||
- **Deviation-free**. Intercepts production URI requests from your page and mocks their responses; | ||
- **Mocking as a tool**. Enable/disable/change mocking logic on runtime instantly without any compilations or rebuilds. Control the MSW lifecycle from your browser's DevTools; | ||
@@ -31,9 +31,9 @@ - **Essentials**. Mock status codes, headers, delay responses, and create custom response mocking functions. | ||
There are several points that I find annoying when conducting API mocking with any solution I've found: | ||
Conventional API mocking suffers from the following pain-points: | ||
- Often relies on a separate mocking server which you need to run and maintain; | ||
- Doesn't really mock requests, rather _replaces_ their urls to point to a mocking server, instead of a real server; | ||
- Brings extra dependencies to your application, instead of being a simple dependency-free development tool. | ||
- Relies on a dedicated mocking server which you need to run and maintain; | ||
- There is no actual mocking in place: instead you _replace_ requests' urls to point to the mocking server that _seemingly_ behaves as the production one; | ||
- Brings extra dependencies to your application where it should have been a plain development tool. | ||
This library annihilates those problems, as it takes an entirely different approach to the client-side API mocking. | ||
MSW is immune to all of the above, as it's mocking principle doesn't revolve around servers. | ||
@@ -54,4 +54,6 @@ ## Explanation | ||
A mocking function contains information about the request, so you can _perform a real request_ and then patch it with the mocked data, if needed. | ||
> **Note:** Service Workers is a browser API, which makes MSW usable only on the client-side. You won't be able to use this mock when hitting your website via Postman, for example. | ||
A mocking function contains information about the request, so you can _perform the actual request_ and then patch it with the mocked data, if needed. | ||
<br /> | ||
@@ -65,3 +67,3 @@ | ||
MSW uses conventional path definitions (as Express), making it ease to filter which outgoing traffic you want to mock. Requests not matching any mocking definition are bypassed and performed as if it was production. | ||
MSW uses conventional path definitions (like the ones in [ExpressJS](https://expressjs.com/)), making it easer to target outgoing traffic for mocking. Requests not matching any mocking definition are bypassed and performed as usual. | ||
@@ -104,21 +106,27 @@ ## Getting started | ||
const { start } = composeMocks( | ||
rest.get('https://api.github.com/repo/:repoName', | ||
(req, res, { status, set, delay, json }) => { | ||
// access request's params | ||
const { repoName } = req.params | ||
rest.get( | ||
'https://api.github.com/repos/:owner/:repo', | ||
(req, res, { status, set, delay, json }) => { | ||
// access request's params | ||
const { owner, repo } = req.params | ||
return res( | ||
// set custom status | ||
status(403), | ||
return res( | ||
// set custom status | ||
status(200), | ||
// set headers | ||
set({ 'Custom-Header': 'foo' }), | ||
// set headers | ||
set({ 'X-Header': 'Mocked value' }), | ||
// delay the response | ||
delay(1000), | ||
// delay the response | ||
delay(1000), | ||
// send JSON response body | ||
json({ errorMessage: `Repository "${repoName}" not found` }), | ||
) | ||
) | ||
// send JSON response body | ||
json({ | ||
name: 'mocked-name', | ||
owner, | ||
repo, | ||
}), | ||
) | ||
}, | ||
), | ||
) | ||
@@ -177,16 +185,2 @@ | ||
## How does it work? | ||
MSW (_Mock Service Worker_) uses Service Worker API with its primary ability to intercept requests, but instead of caching responses it imitates them according to the provided mock definitions. Here's a simplified internal flow: | ||
1. MSW spawns a dedicated Service Worker and creates a communication channel between the worker and the client. | ||
1. Service Worker then signals any outgoing requests on the page to the MSW, which attempts to match them against the defined mocking routes. | ||
1. When any match occurs, the `resolver` function is executed, and its payload is returned as the mocked response. | ||
## Browser support | ||
This library is meant to be used for **development only**. It doesn't require, nor encourage you to install any Service Worker on production environment. | ||
> [**See browser support table for ServiceWorkers**](https://caniuse.com/#feat=serviceworkers) | ||
## API | ||
@@ -211,4 +205,18 @@ | ||
## How does it work? | ||
MSW (_Mock Service Worker_) uses Service Worker API with its primary ability to intercept requests, but instead of caching responses it imitates them according to the provided mock definitions. Here's a simplified internal flow: | ||
1. MSW spawns a dedicated Service Worker and creates a communication channel between the worker and the client. | ||
1. Service Worker then signals any outgoing requests on the page to the MSW, which attempts to match them against the defined mocking routes. | ||
1. When any match occurs, the `resolver` function is executed, and its payload is returned as the mocked response. | ||
## Browser support | ||
This library is meant to be used for **development only**. It doesn't require, nor encourage you to install any Service Worker on production environment. | ||
> [**See browser support table for ServiceWorkers**](https://caniuse.com/#feat=serviceworkers) | ||
## Contribute | ||
Have an idea? Found a bug? Please communicate it through using the [issues](https://github.com/open-draft/msw/issues) tab of this repository. [Pull requests](https://github.com/open-draft/msw/pulls) are welcome as well! |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3027
215
117018
16
+ Addedansi-styles@4.3.0(transitive)
+ Addedchalk@3.0.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedpath-to-regexp@3.1.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
- Removedchalk@2.4.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedpath-to-regexp@3.0.0(transitive)
- Removedsupports-color@5.5.0(transitive)
Updatedchalk@^3.0.0
Updatedpath-to-regexp@3.1.0