Comparing version 0.3.4 to 0.4.0
@@ -1,10 +0,8 @@ | ||
import { SchemaEntryGetter, SchemaEntry, SchemaEntryBody } from './handlers/createHandler'; | ||
import { RequestHandler } from './handlers/requestHandler'; | ||
export declare type Mask = RegExp | string; | ||
export declare type MockingSchema = SchemaEntry<SchemaEntryBody[]>; | ||
interface PublicAPI { | ||
schema: MockingSchema; | ||
start(serviceWorkerURL: string, options?: RegistrationOptions): void; | ||
stop(): void; | ||
} | ||
export default function composeMocks(...handlers: SchemaEntryGetter[]): PublicAPI; | ||
export declare const composeMocks: (...requestHandlers: RequestHandler[]) => PublicAPI; | ||
export {}; |
@@ -48,3 +48,2 @@ import { ResponseTransformer } from './response'; | ||
} | ||
declare const context: MockedContext; | ||
export default context; | ||
export declare const context: MockedContext; |
@@ -1,2 +0,1 @@ | ||
/// <reference types="ts-toolbelt" /> | ||
import { Mask } from '../composeMocks'; | ||
@@ -26,3 +25,3 @@ import { MockedContext } from '../context'; | ||
} | ||
declare const createHandler: import("Function/Curry").Curry<(method: RESTMethods, mask: Mask, resolver: 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,11 @@ | ||
/// <reference types="ts-toolbelt" /> | ||
declare const _default: { | ||
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>; | ||
import { RequestHandler, ResponseResolver } from './requestHandler'; | ||
import { Mask } from '../composeMocks'; | ||
declare const restMethods: { | ||
get: (mask: Mask, resolver: ResponseResolver) => RequestHandler; | ||
post: (mask: Mask, resolver: ResponseResolver) => RequestHandler; | ||
put: (mask: Mask, resolver: ResponseResolver) => RequestHandler; | ||
delete: (mask: Mask, resolver: ResponseResolver) => RequestHandler; | ||
patch: (mask: Mask, resolver: ResponseResolver) => RequestHandler; | ||
options: (mask: Mask, resolver: ResponseResolver) => RequestHandler; | ||
}; | ||
export default _default; | ||
export default restMethods; |
@@ -1,4 +0,5 @@ | ||
export { default as composeMocks } from './composeMocks'; | ||
export { default as res } from './response'; | ||
export { default as context } from './context'; | ||
export { RequestHandler, RequestParams, ResponseResolver, RESTMethods, } from './handlers/requestHandler'; | ||
export { composeMocks } from './composeMocks'; | ||
export { response } from './response'; | ||
export { context } from './context'; | ||
export { default as rest } from './handlers/rest'; |
@@ -16,3 +16,2 @@ export interface MockedResponse { | ||
export declare const defaultResponse: MockedResponse; | ||
declare const response: ResponseComposition; | ||
export default response; | ||
export declare const response: ResponseComposition; |
@@ -1,2 +0,2 @@ | ||
import { RequestParams } from '../handlers/createHandler'; | ||
import { RequestParams } from '../handlers/requestHandler'; | ||
export interface MatchPathOptions { | ||
@@ -3,0 +3,0 @@ path?: RegExp | string; |
{ | ||
"name": "msw", | ||
"version": "0.3.4", | ||
"version": "0.4.0", | ||
"description": "Deviation-less client-side runtime API mocking using Service Workers.", | ||
@@ -32,10 +32,10 @@ "main": "lib/index.js", | ||
"path-to-regexp": "3.1.0", | ||
"ramda": "0.26.1", | ||
"yargs": "14.0.0" | ||
"ramda": "^0.27.0", | ||
"yargs": "^15.1.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.8.3", | ||
"@babel/preset-env": "^7.8.3", | ||
"@types/jest": "24.0.18", | ||
"@types/ramda": "^0.26.21", | ||
"@babel/core": "^7.8.4", | ||
"@babel/preset-env": "^7.8.4", | ||
"@types/jest": "^25.1.2", | ||
"@types/ramda": "^0.26.41", | ||
"awesome-typescript-loader": "^5.2.1", | ||
@@ -50,7 +50,7 @@ "babel-loader": "8.0.6", | ||
"regenerator-runtime": "0.13.3", | ||
"ts-jest": "^25.0.0", | ||
"ts-jest": "^25.2.0", | ||
"typescript": "^3.7.5", | ||
"webpack": "^4.41.0", | ||
"webpack-cli": "^3.3.9" | ||
"webpack": "^4.41.6", | ||
"webpack-cli": "^3.3.11" | ||
} | ||
} |
@@ -181,5 +181,5 @@ <p align="center"> | ||
### `composeMocks(...MockDef): PublicAPI` | ||
### `composeMocks(...args: RequestHandler[]): PublicAPI` | ||
Composes given mocking definitions into a single schema. | ||
Composes given mocking request handlers into a single schema. | ||
@@ -199,2 +199,25 @@ #### Example | ||
## Recipes | ||
### Custom request handler | ||
```js | ||
import { composeMocks } from 'msw' | ||
const hasHeader = (headerName, resolver) => ({ | ||
predicate(req) { | ||
return req.headers[headerName] | ||
}, | ||
resolver, | ||
}) | ||
const { start } = composeMocks( | ||
hasHeader('X-Mock-Response', (req, res, { json }) => { | ||
return res(json({ mocked: true })) | ||
}), | ||
) | ||
start() | ||
``` | ||
## How does it work? | ||
@@ -201,0 +224,0 @@ |
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
19
3122
238
112637
+ Addedansi-regex@5.0.1(transitive)
+ Addedcliui@6.0.0(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedfind-up@4.1.0(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedlocate-path@5.0.0(transitive)
+ Addedp-locate@4.1.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedramda@0.27.2(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedwrap-ansi@6.2.0(transitive)
+ Addedyargs@15.4.1(transitive)
+ Addedyargs-parser@18.1.3(transitive)
- Removedansi-regex@4.1.1(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedcliui@5.0.0(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedemoji-regex@7.0.3(transitive)
- Removedfind-up@3.0.0(transitive)
- Removedis-fullwidth-code-point@2.0.0(transitive)
- Removedlocate-path@3.0.0(transitive)
- Removedp-locate@3.0.0(transitive)
- Removedpath-exists@3.0.0(transitive)
- Removedramda@0.26.1(transitive)
- Removedstring-width@3.1.0(transitive)
- Removedstrip-ansi@5.2.0(transitive)
- Removedwrap-ansi@5.1.0(transitive)
- Removedyargs@14.0.0(transitive)
- Removedyargs-parser@13.1.2(transitive)
Updatedramda@^0.27.0
Updatedyargs@^15.1.0