Skip to content

Commit

Permalink
prettier --write '**/*.{js,json,md}'
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed May 11, 2021
1 parent b700c9b commit 924fee4
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 53 deletions.
27 changes: 14 additions & 13 deletions lib/UnexpectedMitmMocker.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,8 @@ class UnexpectedMitmMocker {
// on https://github.com/moll/node-mitm/pull/36
return;
}
let {
clientSocket,
clientSocketOptions,
} = req.connection._handle._mitm;
let { clientSocket, clientSocketOptions } =
req.connection._handle._mitm;
if (typeof clientSocketOptions.port === 'string') {
// The port could have been defined as a string in a 3rdparty library doing the http(s) call, and that seems to be valid use of the http(s) module
clientSocketOptions = _.defaults(
Expand Down Expand Up @@ -433,12 +431,14 @@ class UnexpectedMitmMocker {
response: null,
error: null,
}))
.catch((
err // ensure delivery of the caught error to the underlying socket
) => ({
response: null,
error: err,
}));
.catch(
(
err // ensure delivery of the caught error to the underlying socket
) => ({
response: null,
error: err,
})
);
} else {
return getMockResponse(responseProperties);
}
Expand Down Expand Up @@ -558,9 +558,10 @@ class UnexpectedMitmMocker {

return Promise.resolve()
.then(() => {
expectedRequestProperties = resolveExpectedRequestProperties(
remainingDescription && remainingDescription.request
);
expectedRequestProperties =
resolveExpectedRequestProperties(
remainingDescription && remainingDescription.request
);
// set the response to be constructed based on the strategy
responseProperties = remainingDescription.response;
})
Expand Down
11 changes: 4 additions & 7 deletions lib/UnexpectedMitmRecorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ const consumeReadableStream = require('./consumeReadableStream');
const createSerializedRequestHandler = require('./createSerializedRequestHandler');
const performRequest = require('./performRequest');

const metadataPropertyNames = messy.HttpRequest.metadataPropertyNames.concat(
'rejectUnauthorized'
);
const metadataPropertyNames =
messy.HttpRequest.metadataPropertyNames.concat('rejectUnauthorized');

function handleRequest(req, metadata) {
return consumeReadableStream(req, { skipConcat: true }).then((result) => {
Expand Down Expand Up @@ -65,10 +64,8 @@ class UnexpectedMitmRecorder {
.on(
'request',
createSerializedRequestHandler((req, res) => {
const {
clientSocket,
clientSocketOptions,
} = req.connection._handle._mitm;
const { clientSocket, clientSocketOptions } =
req.connection._handle._mitm;
const metadata = Object.assign(
{},
_.pick(
Expand Down
5 changes: 2 additions & 3 deletions lib/mockstrategies/OrderedMockStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ module.exports = class OrderedMockStrategy {
return null;
}

const description = this.requestDescriptions[
this.nextRequestDescriptionIndex
];
const description =
this.requestDescriptions[this.nextRequestDescriptionIndex];
this.nextRequestDescriptionIndex += 1;

if (!requestStruct) {
Expand Down
5 changes: 2 additions & 3 deletions lib/resolveExpectedRequestProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ module.exports = function resolveExpectedRequestProperties(
}
if (expectedRequestProperties) {
if (typeof expectedRequestProperties.url === 'string') {
const matchMethod = expectedRequestProperties.url.match(
/^([A-Z]+) ([\s\S]*)$/
);
const matchMethod =
expectedRequestProperties.url.match(/^([A-Z]+) ([\s\S]*)$/);
if (matchMethod) {
expectedRequestProperties.method =
expectedRequestProperties.method || matchMethod[1];
Expand Down
3 changes: 2 additions & 1 deletion lib/unexpectedMitm.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ module.exports = {
if (detectedIndent) {
indentationWidth = detectedIndent.amount;
}
const searchRegExp = /([ ]*)(.*)(['"])with http recorded and injected(\3,| )/g;
const searchRegExp =
/([ ]*)(.*)(['"])with http recorded and injected(\3,| )/g;
// Ensure the search for the for the assertion string occurs from
// the line number of the callsite until it is found. Since we can
// only set an index within the source string to search from, we
Expand Down
31 changes: 5 additions & 26 deletions test/unexpectedMitm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1599,12 +1599,9 @@ describe('unexpectedMitm', () => {
expect(
expect(
() =>
expect(
'http://www.google.com/foo',
'to yield response',
200
).then(() =>
expect('http://www.google.com/foo', 'to yield response', 200)
expect('http://www.google.com/foo', 'to yield response', 200).then(
() =>
expect('http://www.google.com/foo', 'to yield response', 200)
),
'with http mocked out',
[],
Expand Down Expand Up @@ -3078,16 +3075,7 @@ describe('unexpectedMitm', () => {
res.setHeader('Content-Type', 'text/html; charset=ISO-8859-1');
res.end(
Buffer.from([
0x62,
0x6c,
0xe5,
0x62,
0xe6,
0x72,
0x67,
0x72,
0xf8,
0x64,
0x62, 0x6c, 0xe5, 0x62, 0xe6, 0x72, 0x67, 0x72, 0xf8, 0x64,
])
);
};
Expand All @@ -3104,16 +3092,7 @@ describe('unexpectedMitm', () => {
'Content-Type': 'text/html; charset=ISO-8859-1',
},
body: Buffer.from([
0x62,
0x6c,
0xe5,
0x62,
0xe6,
0x72,
0x67,
0x72,
0xf8,
0x64,
0x62, 0x6c, 0xe5, 0x62, 0xe6, 0x72, 0x67, 0x72, 0xf8, 0x64,
]),
},
},
Expand Down

0 comments on commit 924fee4

Please sign in to comment.