Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Bind log functions to sanitized context #27 #29

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/IncomingMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ function createConnectionObject(context) {
*/
function sanitizeContext(context) {
const sanitizedContext = {
...context,
log : context.log.bind(context)
...context
};

// We don't want the developper to mess up express flow
Expand Down
4 changes: 0 additions & 4 deletions test/ExpressAdapter.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { ExpressAdapter } from "../src";

const NOOP = () => {};

describe("ExpressAdapter", () => {

it("Should work", done => {
Expand All @@ -16,7 +14,6 @@ describe("ExpressAdapter", () => {
});

const context = {
log : NOOP,
bindings : { req: { originalUrl: "http://foo.com/bar" } },
done : () => {
expect(listenerCalled).toBe(true);
Expand Down Expand Up @@ -48,7 +45,6 @@ describe("ExpressAdapter", () => {
});

const context = {
log : NOOP,
bindings : { req: { originalUrl: "http://foo.com/bar" } },
done : () => {
expect(listenerCalled).toBe(true);
Expand Down
9 changes: 2 additions & 7 deletions test/IncomingMessage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ describe("IncomingMessage", () => {
originalUrl : "https://foo.com/bar",
headers : { "x-forwarded-for": "192.168.0.1:57996" }
}
},
log : () => {}
}
};

const req = new IncomingMessage(context);
Expand All @@ -34,8 +33,7 @@ describe("IncomingMessage", () => {
req : {
originalUrl : "http://foo.com/bar"
}
},
log : () => {}
}
};

const req = new IncomingMessage(context);
Expand All @@ -61,7 +59,6 @@ describe("IncomingMessage", () => {
originalUrl : "http://foo.com/bar"
}
},
log : () => {},
done : () => {}
};

Expand All @@ -82,8 +79,6 @@ describe("IncomingMessage", () => {
expect(req.context.invocationId).toBe(context.invocationId);
expect(req.context.bindingData).toBe(context.bindingData);
expect(req.context.bindings).toBe(context.bindings);
expect(req.context.log).not.toBe(context.log);
expect(req.context.log).toBeInstanceOf(Function);
expect(req.context.done).toBeUndefined(); // We don't want to pass done

});
Expand Down
1 change: 0 additions & 1 deletion test/expressIntegration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe("express integration", () => {
// 3. Mock Azure Function context
var context = {
bindings : { req: { method: "GET", originalUrl: "https://lol.com/api/foo/bar" } },
log : () => { throw new Error("Log should not be called"); },
done : (error) => {
expect(error).toBeUndefined();
expect(context.res.status).toBe(200);
Expand Down