Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Feb 26, 2021
1 parent 2704886 commit 38763e7
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export const onRequestReceived: HandlerFn<CyHttpMessages.IncomingRequest> = (Cyp
const { data: req, requestId, routeHandlerId } = frame

parseJsonBody(req)
console.log({ req })

const request: Interception = {
id: requestId,
Expand Down
4 changes: 2 additions & 2 deletions packages/net-stubbing/lib/external-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export namespace CyHttpMessages {
export type IncomingResponse = BaseMessage & {
statusCode: number
statusMessage: string
delay?: number
delayMs?: number
throttleKbps?: number
}

Expand Down Expand Up @@ -349,7 +349,7 @@ export interface GenericStaticResponse<Fixture, Body> {
/**
* Milliseconds to delay before the response is sent.
*/
delayMs?: number
delayMs?: number
}

/**
Expand Down
2 changes: 0 additions & 2 deletions packages/net-stubbing/lib/server/driver-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ function subscribe (state: NetStubbingState, options: NetEvent.ToServer.Subscrib
}

function eventHandlerResolved (state: NetStubbingState, options: NetEvent.ToServer.EventHandlerResolved) {
console.log('PENDING EV HANDLERS', state.pendingEventHandlers)

const pendingEventHandler = state.pendingEventHandlers[options.eventId]

if (!pendingEventHandler) {
Expand Down
15 changes: 1 addition & 14 deletions packages/net-stubbing/lib/server/intercept-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ export const InterceptRequest: RequestMiddleware = async function () {
lastRoute = route
}

console.log('SUBS', subscriptions)

if (!subscriptions.length || !lastRoute) {
console.log('NEXTING')

// not intercepted, carry on normally...
return this.next()
}
Expand All @@ -92,7 +88,6 @@ export const InterceptRequest: RequestMiddleware = async function () {
res: this.res,
subscriptions,
handleSubscriptions: async ({ eventName, data, mergeChanges }) => {
console.log('HANDLING', eventName)
const handleSubscription = async (subscription: Subscription) => {
const eventId = _.uniqueId('Event')
const eventFrame: NetEvent.ToDriver.Event<any> = {
Expand All @@ -119,8 +114,6 @@ export const InterceptRequest: RequestMiddleware = async function () {

const changedData = await p

console.log('GOT CHANGED DATA!', changedData)

return mergeChanges(data, changedData as any)
}

Expand Down Expand Up @@ -157,7 +150,6 @@ export const InterceptRequest: RequestMiddleware = async function () {
url: request.req.proxiedUrl,
}) as CyHttpMessages.IncomingRequest

console.log('REQ CREATED')
request.res.once('finish', async () => {
request.handleSubscriptions<CyHttpMessages.ResponseComplete>({
eventName: 'response-complete',
Expand Down Expand Up @@ -194,8 +186,6 @@ export const InterceptRequest: RequestMiddleware = async function () {

request.req.body = req.body

console.log('AFTER ENSUREBODY', req.body)

const mergeChanges = (before: CyHttpMessages.IncomingRequest, after: CyHttpMessages.IncomingRequest) => {
if (before.headers['content-length'] === after.headers['content-length']) {
// user did not purposely override content-length, let's set it
Expand All @@ -214,15 +204,12 @@ export const InterceptRequest: RequestMiddleware = async function () {
mergeChanges,
})

console.log('AFTER HANDLESUBSCRIPTIONS')

if (lastRoute.staticResponse) {
console.log('LASTROUTE HAS STATICRESPONSE')

return sendStaticResponse(request, lastRoute.staticResponse)
}

mergeChanges(req, modifiedReq)
// @ts-ignore
mergeChanges(request.req, req)

return request.continueRequest()
Expand Down
4 changes: 0 additions & 4 deletions packages/net-stubbing/lib/server/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,6 @@ export function getBodyStream (body: Buffer | string | Readable | undefined, opt
return (body as Readable).pipe(writable)
}

// if (!_.isString(body)) {
// throw new Error(`body must be a string or a Buffer. Received: ${body}`)
// }

writable.write(body)
}

Expand Down

0 comments on commit 38763e7

Please sign in to comment.