feat: add native logging with headers and body to CloudEvent (#437)
* feat: add native logging with headers and body to CloudEvent Signed-off-by: Grant Timmerman <timmerman+devrel@google.com> * ci: simplify Signed-off-by: Grant Timmerman <timmerman+devrel@google.com> * ci: simplify Signed-off-by: Grant Timmerman <timmerman+devrel@google.com> * ci: returns to return Signed-off-by: Grant Timmerman <timmerman+devrel@google.com> * ci: Update test/integration/cloud_event_test.ts Co-authored-by: Lance Ball <lball@redhat.com> * ci: revert symbol change Signed-off-by: Grant Timmerman <timmerman+devrel@google.com> * refactor: improve ts for toString Signed-off-by: Grant Timmerman <timmerman+devrel@google.com> Co-authored-by: Lance Ball <lball@redhat.com>
This commit is contained in:
parent
2ff7852c36
commit
b38a48fa59
|
@ -195,4 +195,12 @@ See: https://github.com/cloudevents/spec/blob/v1.0/spec.md#type-system`);
|
|||
): CloudEvent {
|
||||
return new CloudEvent(Object.assign({}, this.toJSON(), options) as CloudEvent, strict);
|
||||
}
|
||||
|
||||
/**
|
||||
* The native `console.log` value of the CloudEvent.
|
||||
* @return {string} The string representation of the CloudEvent.
|
||||
*/
|
||||
[Symbol.for("nodejs.util.inspect.custom")](): string {
|
||||
return this.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,13 @@ describe("A CloudEvent", () => {
|
|||
expect(new CloudEvent(JSON.parse(JSON.stringify(ce)))).to.deep.equal(ce);
|
||||
});
|
||||
|
||||
it("serializes as JSON with raw log", () => {
|
||||
const ce = new CloudEvent({ ...fixture, data: { lunch: "tacos" } });
|
||||
const inspectSymbol = (Symbol.for("nodejs.util.inspect.custom") as unknown) as string;
|
||||
const ceToString = (ce[inspectSymbol] as CallableFunction).bind(ce);
|
||||
expect(ce.toString()).to.deep.equal(ceToString());
|
||||
});
|
||||
|
||||
it("Throw a validation error for invalid extension names", () => {
|
||||
expect(() => {
|
||||
new CloudEvent({ "ext-1": "extension1", ...fixture });
|
||||
|
|
Loading…
Reference in New Issue