GeezerVison is showing github.com — Merge pull request #196 from Hargne/feature/additional-information · Hargne/jest-html-reporter@3b80d7f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# These are supported funding model platforms | | 2 | + | | 3 | +github: [Hargne] | | 4 | +custom: ["https://paypal.me/hargne"] |
Collapse file Copy file name to clipboardExpand all lines: README.md +21-20Lines changed: 21 additions & 20 deletions - Display the source diff
- Display the rich diff
Large diffs are not rendered by default. Collapse file Copy file name to clipboardExpand all lines: package.json +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | { | 2 | 2 | "name": "jest-html-reporter", | 3 | | - "version": "4.0.1", | | 3 | + "version": "4.1.0", | 4 | 4 | "description": "Jest test results processor for generating a summary in HTML", | 5 | 5 | "main": "dist/index.js", | 6 | 6 | "unpkg": "dist/index.js", | |
Collapse file Copy file name to clipboardExpand all lines: src/extractConfiguration.ts +10-2Lines changed: 10 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import path from "path"; | 2 | 2 | import fs from "fs"; | 3 | 3 | import { JestHTMLReporterConfiguration } from "./types"; | 4 | | -import { parseBoolean, parseNumber, parseString } from "./utils"; | | 4 | +import { | | 5 | + isAdditionalInformationEntry, | | 6 | + parseArray, | | 7 | + parseBoolean, | | 8 | + parseNumber, | | 9 | + parseString, | | 10 | +} from "./utils"; | 5 | 11 |
| 6 | 12 | const defaultValues: JestHTMLReporterConfiguration = { | | 13 | + additionalInformation: [], | 7 | 14 | append: false, | 8 | 15 | boilerplate: undefined, | 9 | 16 | collapseSuitesByDefault: false, | @@ -49,8 +56,9 @@ export function readJsonFile(filePath: string) { | 49 | 56 | const typeParsers: { | 50 | 57 | [key in keyof JestHTMLReporterConfiguration]: ( | 51 | 58 | value: unknown | 52 | | - ) => string | number | boolean | undefined; | | 59 | + ) => string | number | boolean | unknown[] | undefined; | 53 | 60 | } = { | | 61 | + additionalInformation: parseArray(isAdditionalInformationEntry), | 54 | 62 | append: parseBoolean, | 55 | 63 | boilerplate: parseString, | 56 | 64 | collapseSuitesByDefault: parseBoolean, | |
Collapse file Copy file name to clipboardExpand all lines: src/htmlreporter.test.ts +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -342,4 +342,23 @@ describe("HTMLReporter", () => { | 342 | 342 | }); | 343 | 343 | }); | 344 | 344 | }); | | 345 | + | | 346 | + describe("additionalInformation", () => { | | 347 | + it("should add additional information to the report", async () => { | | 348 | + await renderReportToDOM({ | | 349 | + options: { | | 350 | + additionalInformation: [{ label: "Environment", value: "Test" }], | | 351 | + }, | | 352 | + }); | | 353 | + | | 354 | + const additionalInfoElements = document.querySelectorAll( | | 355 | + ".additional-information" | | 356 | + ); | | 357 | + expect(additionalInfoElements.length).toBe(1); | | 358 | + | | 359 | + expect(additionalInfoElements[0].textContent).toContain( | | 360 | + "Environment: Test" | | 361 | + ); | | 362 | + }); | | 363 | + }); | 345 | 364 | }); |
Collapse file Copy file name to clipboardExpand all lines: src/htmlreporter.ts +26Lines changed: 26 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -195,6 +195,11 @@ class HTMLReporter { | 195 | 195 | } | 196 | 196 | } | 197 | 197 |
| | 198 | + /** | | 199 | + * Additional Information | | 200 | + */ | | 201 | + this.renderAdditionalInformation(metaDataContainer); | | 202 | + | 198 | 203 | // Summary | 199 | 204 | const summaryContainer = metaDataContainer.ele("div", { id: "summary" }); | 200 | 205 | // Suite Summary | @@ -492,6 +497,27 @@ class HTMLReporter { | 492 | 497 | ); | 493 | 498 | } | 494 | 499 |
| | 500 | + public renderAdditionalInformation(target: xmlbuilder.XMLElement) { | | 501 | + const additionalInformation = this.getConfigValue("additionalInformation"); | | 502 | + if ( | | 503 | + additionalInformation && | | 504 | + Array.isArray(additionalInformation) && | | 505 | + additionalInformation.length > 0 | | 506 | + ) { | | 507 | + const container = target.ele("div", { | | 508 | + class: "additional-information-container", | | 509 | + }); | | 510 | + for (const info of additionalInformation) { | | 511 | + container.ele( | | 512 | + "div", | | 513 | + { class: "additional-information" }, | | 514 | + `${info.label}: ${info.value}` | | 515 | + ); | | 516 | + } | | 517 | + return container; | | 518 | + } | | 519 | + } | | 520 | + | 495 | 521 | /** | 496 | 522 | * Returns the configured value from the config in the following priority order: | 497 | 523 | * Environment Variable > JSON configured value > Default value | |
Collapse file Copy file name to clipboardExpand all lines: src/types/index.d.ts +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,10 @@ export interface JestHTMLReporterProps { | 10 | 10 | } | 11 | 11 |
| 12 | 12 | export interface JestHTMLReporterConfiguration { | | 13 | + additionalInformation?: { | | 14 | + label: string; | | 15 | + value: string; | | 16 | + }[]; | 13 | 17 | append: boolean; | 14 | 18 | boilerplate?: string; | 15 | 19 | collapseSuitesByDefault: boolean; | |
Collapse file Copy file name to clipboardExpand all lines: src/utils.ts +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -123,3 +123,23 @@ export function parseString(value: unknown): string | undefined { | 123 | 123 | } | 124 | 124 | return undefined; | 125 | 125 | } | | 126 | + | | 127 | +export const parseArray = | | 128 | + <T>(isValidItem: (item: unknown) => item is T) => | | 129 | + (value: unknown): T[] => { | | 130 | + if (Array.isArray(value)) { | | 131 | + return value.filter(isValidItem); | | 132 | + } | | 133 | + return []; | | 134 | + }; | | 135 | + | | 136 | +export function isAdditionalInformationEntry( | | 137 | + item: unknown | | 138 | +): item is { label: string; value: string } { | | 139 | + return ( | | 140 | + typeof item === "object" && | | 141 | + item !== null && | | 142 | + typeof (item as { label: unknown }).label === "string" && | | 143 | + typeof (item as { value: unknown }).value === "string" | | 144 | + ); | | 145 | +} |
Collapse file Copy file name to clipboardExpand all lines: style/defaultTheme.css +21-8Lines changed: 21 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | :root { | 2 | 2 | --text-primary: #111; | 3 | | - --text-secondary: #4F4F4F; | | 3 | + --text-secondary: #4f4f4f; | 4 | 4 | --success: #006633; | 5 | | - --success-bright: #80FFBF; | 6 | | - --danger: #CC071E; | 7 | | - --danger-bright: #FBDFE0; | 8 | | - --warning: #995C00; | 9 | | - --warning-bright: #FFEEA8; | | 5 | + --success-bright: #80ffbf; | | 6 | + --danger: #cc071e; | | 7 | + --danger-bright: #fbdfe0; | | 8 | + --warning: #995c00; | | 9 | + --warning-bright: #ffeea8; | 10 | 10 | --panel: #eee; | 11 | 11 | --border: #949494; | 12 | | - --disabled: #6B6B6B; | | 12 | + --disabled: #6b6b6b; | 13 | 13 | } | 14 | 14 |
| 15 | 15 | html, | @@ -43,10 +43,23 @@ header { | 43 | 43 | margin-top: 0.5rem; | 44 | 44 | } | 45 | 45 |
| | 46 | +#metadata-container { | | 47 | + display: flex; | | 48 | + flex-direction: column; | | 49 | + gap: 2rem; | | 50 | + margin-bottom: 2rem; | | 51 | +} | | 52 | + | | 53 | +.additional-information-container { | | 54 | + display: flex; | | 55 | + flex-direction: column; | | 56 | + gap: 0.5rem; | | 57 | + color: var(--text-secondary); | | 58 | +} | | 59 | + | 46 | 60 | /** SUMMARY */ | 47 | 61 | #summary { | 48 | 62 | color: var(--text-primary); | 49 | | - margin: 2rem 0; | 50 | 63 | display: flex; | 51 | 64 | font-family: monospace; | 52 | 65 | font-size: 1rem; | |
|