wirepig
Version:
Better testing through the power of sockets.
62 lines (54 loc) • 1.11 kB
JavaScript
import {
alias,
always,
or,
and,
obj,
isUndefined,
isPlainObject,
branch,
branchWithFunction,
exclusive,
} from '../validate.js';
import {
optComparable,
optBufferable,
funcOptBufferable,
delay,
destroySocket,
port,
} from '../http/schema.js';
const resObj = obj({
body: funcOptBufferable,
bodyDelay: delay,
destroySocket,
});
const res = branchWithFunction(
[ ],
[ ],
'if defined must be object, string, or buffer'
);
const connectionPinned = alias(
exclusive(['init'], ['_pinnedTo']),
'init not supported on a connection-pinned mock'
);
export const mockSchemaObj = and(
obj({
_pinnedTo: or(isUndefined, isPlainObject),
init: optBufferable,
req: optComparable,
res,
}),
exclusive(['init'], ['req', 'res']),
connectionPinned
);
export const mockSchema = branch(
[ ],
[ ],
'if defined must be plain object'
);
export const tcpSchema = branch(
[ ],
[ ],
'if defined must be plain object'
);