Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

msw

Package Overview
Dependencies
Maintainers
1
Versions
271
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

msw - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

flackyTest.sh

3

lib/handlers/createHandler.d.ts

@@ -1,2 +0,1 @@

import * as R from 'ramda';
import { Mask } from '../composeMocks';

@@ -26,3 +25,3 @@ import { MockedContext } from '../context';

}
declare const createHandler: R.CurriedFunction3<RESTMethods, Mask, ResponseResolver, SchemaEntryGetter>;
declare const createHandler: import("ts-toolbelt/out/types/src/Function/Curry").Curry<(method: RESTMethods, mask: Mask, resolver: ResponseResolver) => SchemaEntryGetter>;
export default createHandler;

@@ -1,10 +0,9 @@

/// <reference types="ramda" />
declare const _default: {
get: import("ramda").CurriedFunction2<import("../composeMocks").Mask, import("./createHandler").ResponseResolver, import("./createHandler").SchemaEntryGetter>;
post: import("ramda").CurriedFunction2<import("../composeMocks").Mask, import("./createHandler").ResponseResolver, import("./createHandler").SchemaEntryGetter>;
put: import("ramda").CurriedFunction2<import("../composeMocks").Mask, import("./createHandler").ResponseResolver, import("./createHandler").SchemaEntryGetter>;
delete: import("ramda").CurriedFunction2<import("../composeMocks").Mask, import("./createHandler").ResponseResolver, import("./createHandler").SchemaEntryGetter>;
patch: import("ramda").CurriedFunction2<import("../composeMocks").Mask, import("./createHandler").ResponseResolver, import("./createHandler").SchemaEntryGetter>;
options: import("ramda").CurriedFunction2<import("../composeMocks").Mask, import("./createHandler").ResponseResolver, import("./createHandler").SchemaEntryGetter>;
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>;
};
export default _default;
{
"name": "msw",
"version": "0.3.1",
"version": "0.3.2",
"description": "Serverless client-side API mocking without a single change to the codebase.",

@@ -23,25 +23,26 @@ "main": "lib/index.js",

"dependencies": {
"path-to-regexp": "^2.4.0",
"ramda": "^0.25.0",
"yargs": "^12.0.5"
"path-to-regexp": "3.0.0",
"ramda": "0.26.1",
"yargs": "14.0.0"
},
"devDependencies": {
"@babel/core": "^7.1.5",
"@babel/preset-env": "^7.1.5",
"@types/jest": "^23.3.9",
"@types/ramda": "^0.25.41",
"@babel/core": "7.5.5",
"@babel/preset-env": "7.5.5",
"@types/jest": "24.0.18",
"@types/ramda": "0.26.19",
"awesome-typescript-loader": "^5.2.1",
"babel-loader": "^8.0.4",
"babel-plugin-ramda": "^1.6.3",
"babel-loader": "8.0.6",
"babel-plugin-ramda": "2.0.0",
"chalk": "^2.4.1",
"cross-env": "^5.2.0",
"express": "^4.16.4",
"jest": "^23.6.0",
"node-fetch": "^2.3.0",
"prettier": "^1.15.2",
"ts-jest": "^23.10.4",
"typescript": "^3.1.6",
"webpack": "^4.25.1",
"webpack-cli": "^3.1.2"
"express": "^4.17.1",
"jest": "24.9.0",
"node-fetch": "^2.6.0",
"prettier": "^1.18.2",
"regenerator-runtime": "0.13.3",
"ts-jest": "24.0.2",
"typescript": "^3.5.3",
"webpack": "4.39.2",
"webpack-cli": "3.3.7"
}
}
<p align="center">
<a href="https://www.npmjs.com/package/msw">
<a href="https://www.npmjs.com/package/msw" target="_blank">
<img src="https://img.shields.io/npm/v/msw.svg" alt="Package version" />
</a>
<a href="https://circleci.com/gh/kettanaito/msw)">
<img src="https://img.shields.io/circleci/project/github/kettanaito/msw/master.svg" alt="Build status" />
<a href="https://circleci.com/gh/open-draft/msw)" target="_blank">
<img src="https://img.shields.io/circleci/project/github/open-draft/msw/master.svg" alt="Build status" />
</a>
<a href="https://david-dm.org/open-draft/msw" target="_blank">
<img src="https://img.shields.io/david/open-draft/msw.svg" alt="Dependencies status" />
</a>
<a href="https://david-dm.org/open-draft/msw?type=dev" target="_blank">
<img src="https://img.shields.io/david/dev/open-draft/msw.svg" alt="Dev dependencies status" />
</a>
</p>

@@ -12,3 +18,3 @@

<p align="center">Serverless offline client-side API mocking for your applications.</p>
<p align="center">Serverless runtime client-side API mocking for your applications.</p>

@@ -19,3 +25,3 @@ ## Features

- **Deviation-free**. Request the very same resources (urls) you would in production, and let MSW handle the mocking of the respective 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.
- **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;
- **Essentials**. Emulate status codes, headers, delays, and create custom response mocking functions.

@@ -27,7 +33,7 @@

- Often relies on a mocking server which you need to run and maintain;
- 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.
This library aims to annihilate those problems, as it takes an entirely different approach to the client-side API mocking.
This library annihilates those problems, as it takes an entirely different approach to the client-side API mocking.

@@ -38,6 +44,4 @@ ## Getting started

First, install `msw` with any package manager (npm, yarn, etc.).
```bash
yarn install msw --dev
npm install msw --save
```

@@ -47,6 +51,6 @@

Run the following command in your project's root directory:
Run the following command in your project's public directory:
```bash
node_modiles/.bin/msw init <publicDir>
node_modules/.bin/msw init <publicDir>
```

@@ -56,7 +60,7 @@

This is going to copy the Mock Service Worker file to the specified `publicDir` location, so it's served as a static file. This makes it possible for a browser to access and register the referenced service worker.
This copies the Mock Service Worker file to the specified `publicDir`, so it's served as a static asset by your server. This way browser can access and register the mock service worker module.
#### Where is my "public" directory?
This is usually the build directory of your application (`build/`, `public/` or `dest/`). This directory is often _committed to Git_, so should be the Mock Service Worker. You can also integrate service worker generation as a part of your build step.
This is usually a build directory of your application (`build/`, `public/` or `dest/`). This directory is often _committed to Git_, so should be the Mock Service Worker. You can also integrate service worker generation as a part of your build step.

@@ -71,12 +75,17 @@ ### 3. Define mocks

/* Configure mocking routes */
// Configure mocking routes
const { start } = composeMocks(
rest.get('https://api.github.com/repo/:repoName',
(req, res, { status, set, delay, json }) => {
const { repoName } = req.params // access request's params
// access request's params
const { repoName } = req.params
return res(
status(403), // set custom status
set({ 'Custom-Header': 'foo' }), // set headers
delay(1000), // delay the response
// set custom status
status(403),
// set headers
set({ 'Custom-Header': 'foo' }),
// delay the response
delay(1000),
// send JSON response body
json({ errorMessage: `Repository "${repoName}" not found` }),

@@ -91,9 +100,9 @@ )

> You can modularize your mocking files, but be sure to call `start()` **only once!**
> Mocks structure if up to you, but be sure to call `start()` **only once!**
### 4. Integrate
Mocking is a **development-only** procedure. We highly recommend to include your mocking module (`app/mocks.js`) into your application's entry during the build. Please see examples of how this can be done below.
Mocking is a **development-only** procedure. It's highly recommended to include your mocking module (i.e. `app/mocks.js`) into your application's entry during the build. See the examples below.
#### Using webpack
#### Use webpack

@@ -106,16 +115,17 @@ ```js

entry: [
/* Include mocks when in development */
// Include mocks when in development
__DEV__ && 'app/mocks.js',
/* Include your application's entry */
// Include your application's entry
'app/index.js',
].filter(Boolean),
/* Rest of your config here */
// Rest of your config here
...webpackConfig,
}
```
#### Client-side import
#### Use conditional require
Alternatively, you can import mocking file(s) conditionally in your client bundle.
Alternatively, you can require mocking file(s) conditionally in your client bundle.

@@ -131,13 +141,13 @@ ```js

Service Workers are designed as a caching tool. However, we don't want our mocking definitions to be cached, which would result into out-of-date logic during development.
Service Workers are designed as a caching tool. However, we don't want our mocking definitions to be cached since that would result into out-of-date logic during development.
It's highly recommend to **enable "Update on reload"** option in the "Application" tab of Chrome's DevTools (under "Service Workers" section). This will force Service Worker to update on each page reload, ensuring the latest logic is applied.
It's highly recommend to **enable "Update on reload"** option in your browser (DevTools > Application > Service Workers, in Chrome). This will force Service Worker to update on each page reload, ensuring the latest logic is applied.
![Service Workers: Update on reload](https://raw.githubusercontent.com/kettanaito/msw/master/media/sw-update-on-reload.png)
![Service Workers: Update on reload](https://raw.githubusercontent.com/open-draft/msw/master/media/sw-update-on-reload.png)
> Read more on [The Service Worker Lifecycle](https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle).
> Read more about the [Service Worker Lifecycle](https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle).
## How does it work?
MSW (stands for "Mock Service Worker") uses Service Worker API with its primary ability to intercept requests, only instead of caching responses it immitates them. In a nutshell, it works as follows:
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:

@@ -150,3 +160,3 @@ 1. MSW spawns a dedicated Service Worker and creates a communication channel between the worker and the client.

This library is meant to be used for **development only**. It doesn't require, nor encourage to install any Service Worker on the production environment.
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.

@@ -157,2 +167,2 @@ > [**See browser support for ServiceWorkers**](https://caniuse.com/#feat=serviceworkers)

Have an idea? Found a bug? Please communicate it through using the [issues](https://github.com/kettanaito/msw/issues) tab of this repository. [Pull requests](https://github.com/kettanaito/msw/pulls) are welcome as well!
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc