Skip to content
Merged
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
8 changes: 8 additions & 0 deletions src/event/cloudevent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
7 changes: 7 additions & 0 deletions test/integration/cloud_event_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down