diff --git a/src/helpers/report-builder.cjs b/src/helpers/report-builder.cjs index 2eae798..61f84fe 100644 --- a/src/helpers/report-builder.cjs +++ b/src/helpers/report-builder.cjs @@ -58,10 +58,14 @@ class ReportBuilderBase { this._data = {}; } - toJSON() { + get data() { return this._data; } + toJSON() { + return this.data; + } + _setProperty(key, value, { override = false } = {}) { if (override) { this._data[key] = value; @@ -187,7 +191,9 @@ class ReportDetailBuilder extends ReportBuilderBase { } setName(name, options) { - this._setProperty('name', escapeSpecialCharacters(name), options); + const sanitizedName = escapeSpecialCharacters(name.trim()); + + this._setProperty('name', sanitizedName, options); return this; } @@ -350,8 +356,9 @@ class ReportBuilder extends ReportBuilderBase { let countSkipped = 0; let countFlaky = 0; - for (const [, detail] of this._data.details) { - const { status, retries } = detail.toJSON(); + for (const [, { data: detailData }] of this._data.details) { + const detail = detailData; + const { status, retries } = detail; if (status === 'passed') { if (retries !== 0) { @@ -366,7 +373,7 @@ class ReportBuilder extends ReportBuilderBase { } if (this._verbose) { - const { name, location, type, tool, experience } = detail.toJSON(); + const { name, location, type, tool, experience } = detail; const prefix = `Test '${name}' at '${location}' is missing`; if (!type) { @@ -393,12 +400,10 @@ class ReportBuilder extends ReportBuilderBase { } toJSON() { - const data = super.toJSON(); - return { - ...data, - summary: data.summary.toJSON(), - details: [...data.details].map(([, detail]) => detail.toJSON()) + ...super.toJSON(), + summary: this.data.summary.toJSON(), + details: [...this.data.details].map(([, detail]) => detail.toJSON()) }; }