File tree Expand file tree Collapse file tree 8 files changed +122
-31
lines changed
Expand file tree Collapse file tree 8 files changed +122
-31
lines changed Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 11{
22 "name" : " jest-html-reporter" ,
3- "version" : " 4.0.1 " ,
3+ "version" : " 4.1.0 " ,
44 "description" : " Jest test results processor for generating a summary in HTML" ,
55 "main" : " dist/index.js" ,
66 "unpkg" : " dist/index.js" ,
Original file line number Diff line number Diff line change 11import path from "path" ;
22import fs from "fs" ;
33import { 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" ;
511
612const defaultValues : JestHTMLReporterConfiguration = {
13+ additionalInformation : [ ] ,
714 append : false ,
815 boilerplate : undefined ,
916 collapseSuitesByDefault : false ,
@@ -49,8 +56,9 @@ export function readJsonFile(filePath: string) {
4956const typeParsers : {
5057 [ key in keyof JestHTMLReporterConfiguration ] : (
5158 value : unknown
52- ) => string | number | boolean | undefined ;
59+ ) => string | number | boolean | unknown [ ] | undefined ;
5360} = {
61+ additionalInformation : parseArray ( isAdditionalInformationEntry ) ,
5462 append : parseBoolean ,
5563 boilerplate : parseString ,
5664 collapseSuitesByDefault : parseBoolean ,
Original file line number Diff line number Diff line change @@ -342,4 +342,23 @@ describe("HTMLReporter", () => {
342342 } ) ;
343343 } ) ;
344344 } ) ;
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+ } ) ;
345364} ) ;
Original file line number Diff line number Diff line change @@ -195,6 +195,11 @@ class HTMLReporter {
195195 }
196196 }
197197
198+ /**
199+ * Additional Information
200+ */
201+ this . renderAdditionalInformation ( metaDataContainer ) ;
202+
198203 // Summary
199204 const summaryContainer = metaDataContainer . ele ( "div" , { id : "summary" } ) ;
200205 // Suite Summary
@@ -492,6 +497,27 @@ class HTMLReporter {
492497 ) ;
493498 }
494499
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+
495521 /**
496522 * Returns the configured value from the config in the following priority order:
497523 * Environment Variable > JSON configured value > Default value
Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ export interface JestHTMLReporterProps {
1010}
1111
1212export interface JestHTMLReporterConfiguration {
13+ additionalInformation ?: {
14+ label : string ;
15+ value : string ;
16+ } [ ] ;
1317 append : boolean ;
1418 boilerplate ?: string ;
1519 collapseSuitesByDefault : boolean ;
Original file line number Diff line number Diff line change @@ -123,3 +123,23 @@ export function parseString(value: unknown): string | undefined {
123123 }
124124 return undefined ;
125125}
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+ }
Original file line number Diff line number Diff line change 11: root {
22 --text-primary : # 111 ;
3- --text-secondary : # 4F4F4F ;
3+ --text-secondary : # 4f4f4f ;
44 --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 ;
1010 --panel : # eee ;
1111 --border : # 949494 ;
12- --disabled : # 6B6B6B ;
12+ --disabled : # 6b6b6b ;
1313}
1414
1515html ,
@@ -43,10 +43,23 @@ header {
4343 margin-top : 0.5rem ;
4444}
4545
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+
4660/** SUMMARY */
4761# summary {
4862 color : var (--text-primary );
49- margin : 2rem 0 ;
5063 display : flex;
5164 font-family : monospace;
5265 font-size : 1rem ;
You can’t perform that action at this time.
0 commit comments