Comparing version 0.5.2 to 0.6.0
@@ -7,3 +7,3 @@ import { RequestHandler } from './handlers/requestHandler'; | ||
} | ||
export declare const composeMocks: (...requestHandlers: RequestHandler[]) => PublicAPI; | ||
export declare const composeMocks: (...requestHandlers: RequestHandler<any>[]) => PublicAPI; | ||
export {}; |
import { RequestHandler } from './handlers/requestHandler'; | ||
export declare const createIncomingRequestHandler: (requestHandlers: RequestHandler[]) => (event: MessageEvent) => void; | ||
export declare const createIncomingRequestHandler: (requestHandlers: RequestHandler<any>[]) => (event: MessageEvent) => void; |
@@ -23,5 +23,5 @@ import { RequestHandler, MockedRequest } from './requestHandler'; | ||
declare const _default: { | ||
query: <QueryType, VariablesType>(selector: GraphQLRequestHandlerSelector, resolver: GraphQLResponseResolver<QueryType, VariablesType>) => RequestHandler<GraphQLMockedContext<QueryType>>; | ||
mutation: <QueryType, VariablesType>(selector: GraphQLRequestHandlerSelector, resolver: GraphQLResponseResolver<QueryType, VariablesType>) => RequestHandler<GraphQLMockedContext<QueryType>>; | ||
query: <QueryType, VariablesType = Record<string, any>>(selector: GraphQLRequestHandlerSelector, resolver: GraphQLResponseResolver<QueryType, VariablesType>) => RequestHandler<GraphQLMockedContext<QueryType>>; | ||
mutation: <QueryType, VariablesType = Record<string, any>>(selector: GraphQLRequestHandlerSelector, resolver: GraphQLResponseResolver<QueryType, VariablesType>) => RequestHandler<GraphQLMockedContext<QueryType>>; | ||
}; | ||
export default _default; |
import { Mask } from '../composeMocks'; | ||
import { MockedContext } from '../context'; | ||
import { ResponseComposition, MockedResponse } from '../response'; | ||
export declare enum RESTMethods { | ||
GET = "GET", | ||
POST = "POST", | ||
PUT = "PUT", | ||
PATCH = "PATCH", | ||
OPTIONS = "OPTIONS", | ||
DELETE = "DELETE" | ||
export interface MockedRequest { | ||
url: Request['url']; | ||
method: Request['method']; | ||
headers: Request['headers']; | ||
mode: Request['mode']; | ||
credentials: Request['credentials']; | ||
redirect: Request['redirect']; | ||
referrer: Request['referrer']; | ||
referrerPolicy: Request['referrerPolicy']; | ||
body: Record<string, any> | string; | ||
params: RequestParams; | ||
} | ||
@@ -15,10 +18,13 @@ export declare type RequestParams = { | ||
}; | ||
export declare type ResponseResolver = (req: Request & RequestParams, res: ResponseComposition, context: MockedContext) => MockedResponse; | ||
export interface RequestHandler { | ||
export declare type ResponseResolver<ContextType = any> = (req: MockedRequest, res: ResponseComposition, context: ContextType) => MockedResponse; | ||
export interface RequestHandler<ContextType = any> { | ||
mask?: Mask; | ||
/** | ||
* Predicate function that deciced whether a Request should be mocked. | ||
* Predicate function that decides whether a Request should be mocked. | ||
*/ | ||
predicate: (req: Request) => boolean; | ||
resolver: ResponseResolver; | ||
predicate: (req: MockedRequest) => boolean; | ||
defineContext: (req: MockedRequest) => ContextType; | ||
resolver: ResponseResolver<ContextType>; | ||
} | ||
declare const _default: any; | ||
export default _default; |
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; | ||
import { set } from '../context/set'; | ||
import { status } from '../context/status'; | ||
import { body } from '../context/body'; | ||
import { text } from '../context/text'; | ||
import { json } from '../context/json'; | ||
import { xml } from '../context/xml'; | ||
import { delay } from '../context/delay'; | ||
export declare enum RESTMethods { | ||
GET = "GET", | ||
POST = "POST", | ||
PUT = "PUT", | ||
PATCH = "PATCH", | ||
OPTIONS = "OPTIONS", | ||
DELETE = "DELETE" | ||
} | ||
interface RestHandlerContext { | ||
set: typeof set; | ||
status: typeof status; | ||
body: typeof body; | ||
text: typeof text; | ||
json: typeof json; | ||
xml: typeof xml; | ||
delay: typeof delay; | ||
} | ||
declare const _default: { | ||
get: (mask: Mask, resolver: ResponseResolver<RestHandlerContext>) => RequestHandler<RestHandlerContext>; | ||
post: (mask: Mask, resolver: ResponseResolver<RestHandlerContext>) => RequestHandler<RestHandlerContext>; | ||
put: (mask: Mask, resolver: ResponseResolver<RestHandlerContext>) => RequestHandler<RestHandlerContext>; | ||
delete: (mask: Mask, resolver: ResponseResolver<RestHandlerContext>) => RequestHandler<RestHandlerContext>; | ||
patch: (mask: Mask, resolver: ResponseResolver<RestHandlerContext>) => RequestHandler<RestHandlerContext>; | ||
options: (mask: Mask, resolver: ResponseResolver<RestHandlerContext>) => RequestHandler<RestHandlerContext>; | ||
}; | ||
export default restMethods; | ||
export default _default; |
@@ -1,5 +0,5 @@ | ||
export { RequestHandler, RequestParams, ResponseResolver, RESTMethods, } from './handlers/requestHandler'; | ||
export * from './handlers/requestHandler'; | ||
export { composeMocks } from './composeMocks'; | ||
export { response } from './response'; | ||
export { context } from './context'; | ||
export { default as rest } from './handlers/rest'; | ||
export { default as rest, RESTMethods } from './handlers/rest'; | ||
export { default as graphql } from './handlers/graphql'; |
@@ -13,5 +13,5 @@ export interface MockedResponse { | ||
*/ | ||
export declare type ResponseTransformer = (res: MockedResponse) => any; | ||
export declare type ResponseTransformer = (res: MockedResponse) => MockedResponse; | ||
export declare type ResponseComposition = (...transformers: ResponseTransformer[]) => MockedResponse; | ||
export declare const defaultResponse: MockedResponse; | ||
export declare const response: ResponseComposition; |
{ | ||
"name": "msw", | ||
"version": "0.5.2", | ||
"version": "0.6.0", | ||
"description": "Deviation-less client-side runtime API mocking using Service Workers.", | ||
@@ -14,4 +14,4 @@ "main": "lib/index.js", | ||
"test:unit": "cross-env BABEL_ENV=test jest", | ||
"test": "yarn run test:unit", | ||
"test:integration": "jest --config=test/jest.config.js", | ||
"test": "yarn run test:unit --runInBand", | ||
"test:integration": "jest --config=test/jest.config.js --runInBand", | ||
"test:focused": "node_modules/.bin/ts-node --project=test/tsconfig.json test/focusedTest.ts", | ||
@@ -34,2 +34,3 @@ "prepublishOnly": "yarn test && yarn run build" | ||
"chalk": "^3.0.0", | ||
"graphql": "^14.6.0", | ||
"node-match-path": "^0.2.2", | ||
@@ -36,0 +37,0 @@ "ramda": "^0.27.0", |
Sorry, the diff of this file is too big to display
156516
4530
5
+ Addedgraphql@^14.6.0
+ Addedgraphql@14.7.0(transitive)
+ Addediterall@1.3.0(transitive)