Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-html-reporter

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-html-reporter - npm Package Compare versions

Comparing version 3.7.1 to 3.8.0

2

dist/index.js

@@ -1,1 +0,1 @@

"use strict";var e=require("dateformat"),t=require("fs"),s=require("mkdirp"),i=require("path"),a=require("strip-ansi"),l=require("xmlbuilder");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(e),r=n(t),u=n(s),c=n(i),d=n(a),h=n(l);const g=e=>{const t=[],s=[],i=[];return e.forEach((e=>{const a=[],l=[],n=[];e.testResults.forEach((e=>{"pending"===e.status?a.push(e):"failed"===e.status?l.push(e):n.push(e)})),a.length>0&&t.push({...e,testResults:a}),l.length>0&&s.push({...e,testResults:l}),n.length>0&&i.push({...e,testResults:n})})),[].concat(t,s,i)},f=e=>(e&&e.sort(((e,t)=>t.perfStats.end-t.perfStats.start-(e.perfStats.end-e.perfStats.start))),e),p=e=>(e&&e.sort(((e,t)=>e.perfStats.end-e.perfStats.start-(t.perfStats.end-t.perfStats.start))),e),m=e=>{if(e){const t=e.sort(((e,t)=>E(e.testFilePath,t.testFilePath,!0)));return t.forEach((e=>{e.testResults.sort(((e,t)=>E(e.ancestorTitles.join(" "),t.ancestorTitles.join(" "),!0))),e.testResults.sort(((e,t)=>E(e.title,t.title,!0)))})),t}return e},T=e=>{if(e){const t=e.sort(((e,t)=>E(e.testFilePath,t.testFilePath)));return t.forEach((e=>{e.testResults.sort(((e,t)=>E(e.ancestorTitles.join(" "),t.ancestorTitles.join(" ")))),e.testResults.sort(((e,t)=>E(e.title,t.title)))})),t}return e},E=(e,t,s=!1)=>!s&&e<t||s&&e>t?-1:!s&&e>t||s&&e<t?1:0;class S{constructor(e){this.testData=e.testData,this.jestConfig=e.jestConfig,this.consoleLogList=e.consoleLogs,this.setupConfig(e.options)}async generate(){try{const e=await this.renderTestReport(),t=this.replaceRootDirInPath(this.jestConfig?this.jestConfig.rootDir:"",this.getConfigValue("outputPath"));return await u.default(c.default.dirname(t)),this.getConfigValue("append")?await this.appendToFile(t,e.toString()):r.default.writeFileSync(t,e.toString()),this.logMessage("success",`Report generated (${t})`),e}catch(e){this.logMessage("error",e)}}async renderTestReport(){const e=await this.renderTestReportContent();if(this.getConfigValue("boilerplate")){const t=this.replaceRootDirInPath(this.jestConfig?this.jestConfig.rootDir:"",this.getConfigValue("boilerplate"));return r.default.readFileSync(t,"utf8").replace("{jesthtmlreporter-content}",e&&e.toString())}const t=h.default.create({html:{}}),s=t.ele("head");s.ele("meta",{charset:"utf-8"}),s.ele("title",{},this.getConfigValue("pageTitle"));let i=c.default.join(__dirname,`../style/${this.getConfigValue("theme")}.css`);this.getConfigValue("styleOverridePath")&&(i=this.getConfigValue("styleOverridePath"));if(!this.getConfigValue("useCssFile")&&!this.getConfigValue("styleOverridePath")){const e=r.default.readFileSync(i,"utf8");s.raw(`<style type="text/css">${e}</style>`)}else s.ele("link",{rel:"stylesheet",type:"text/css",href:i});const a=t.ele("body");return e&&a.raw(e.toString()),this.getConfigValue("customScriptPath")&&a.raw(`<script src="${this.getConfigValue("customScriptPath")}"><\/script>`),t}renderTestSuiteInfo(e,t){const s=e.ele("div",{class:"suite-info"});s.ele("div",{class:"suite-path"},t.testFilePath);const i=(t.perfStats.end-t.perfStats.start)/1e3;s.ele("div",{class:"suite-time"+(i>this.getConfigValue("executionTimeWarningThreshold")?" warn":"")},`${i}s`)}renderSuiteFailure(e,t,s){const i=e.ele("div",{id:`suite-${s+1}`,class:"suite-container"});this.renderTestSuiteInfo(i,t);i.ele("div",{class:"suite-tests"}).ele("div",{class:"test-result failed"}).ele("div",{class:"failureMessages suiteFailure"}," ").ele("pre",{class:"failureMsg"},this.sanitizeOutput(t.failureMessage))}async renderTestReportContent(){try{if(!this.testData||0===Object.entries(this.testData).length)throw Error("No test data provided");const e=h.default.begin().element("div",{id:"jesthtml-content"}),t=e.ele("header");t.ele("h1",{id:"title"},this.getConfigValue("pageTitle"));const s=this.getConfigValue("logo");s&&t.ele("img",{id:"logo",src:s});const i=e.ele("div",{id:"metadata-container"});if(this.testData.startTime&&!isNaN(this.testData.startTime)){const e=new Date(this.testData.startTime);if(e){const t=o.default(e,this.getConfigValue("dateFormat"));i.ele("div",{id:"timestamp"},`Started: ${t}`)}}const a=i.ele("div",{id:"summary"}),l=a.ele("div",{id:"suite-summary"});l.ele("div",{class:"summary-total"},`Suites (${this.testData.numTotalTestSuites})`),l.ele("div",{class:"summary-passed"+(0===this.testData.numPassedTestSuites?" summary-empty":"")},`${this.testData.numPassedTestSuites} passed`),l.ele("div",{class:"summary-failed"+(0===this.testData.numFailedTestSuites?" summary-empty":"")},`${this.testData.numFailedTestSuites} failed`),l.ele("div",{class:"summary-pending"+(0===this.testData.numPendingTestSuites?" summary-empty":"")},`${this.testData.numPendingTestSuites} pending`),this.testData.snapshot&&this.testData.snapshot.unchecked>0&&this.getConfigValue("includeObsoleteSnapshots")&&l.ele("div",{class:"summary-obsolete-snapshots"},`${this.testData.snapshot.unchecked} obsolete snapshots`);const n=a.ele("div",{id:"test-summary"});n.ele("div",{class:"summary-total"},`Tests (${this.testData.numTotalTests})`),n.ele("div",{class:"summary-passed"+(0===this.testData.numPassedTests?" summary-empty":"")},`${this.testData.numPassedTests} passed`),n.ele("div",{class:"summary-failed"+(0===this.testData.numFailedTests?" summary-empty":"")},`${this.testData.numFailedTests} failed`),n.ele("div",{class:"summary-pending"+(0===this.testData.numPendingTests?" summary-empty":"")},`${this.testData.numPendingTests} pending`);const r=((e,t)=>{switch(t&&t.toLowerCase()){case"status":return g(e);case"executiondesc":return f(e);case"executionasc":return p(e);case"titledesc":return m(e);case"titleasc":return T(e);default:return e}})(this.testData.testResults,this.getConfigValue("sort")),u=this.getConfigValue("statusIgnoreFilter");let c=[];return u&&(c=u.replace(/\s/g,"").toLowerCase().split(",")),r&&r.forEach(((t,s)=>{if(!t.testResults||t.testResults.length<=0)return void(t.failureMessage&&this.getConfigValue("includeSuiteFailure")&&this.renderSuiteFailure(e,t,s));const i=e.ele("div",{id:`suite-${s+1}`,class:"suite-container"});this.renderTestSuiteInfo(i,t);const a=i.ele("div",{class:"suite-tests"});t.testResults.filter((e=>!c.includes(e.status))).forEach((async e=>{const t=a.ele("div",{class:`test-result ${e.status}`}),s=t.ele("div",{class:"test-info"});if(s.ele("div",{class:"test-suitename"},e.ancestorTitles&&e.ancestorTitles.length>0?e.ancestorTitles.join(" > "):" "),s.ele("div",{class:"test-title"},e.title),s.ele("div",{class:"test-status"},e.status),s.ele("div",{class:"test-duration"},e.duration/1e3+"s"),e.failureMessages&&e.failureMessages.length>0&&this.getConfigValue("includeFailureMsg")){const s=t.ele("div",{class:"failureMessages"}," ");e.failureMessages.forEach((e=>{s.ele("pre",{class:"failureMsg"},this.sanitizeOutput(e))}))}})),this.consoleLogList&&this.consoleLogList.length>0&&this.getConfigValue("includeConsoleLog")&&this.renderSuiteConsoleLogs(t,i),t.snapshot&&t.snapshot.unchecked>0&&this.getConfigValue("includeObsoleteSnapshots")&&this.renderSuiteObsoleteSnapshots(i,t)})),e}catch(e){this.logMessage("error",e)}}renderSuiteConsoleLogs(e,t){const s=this.consoleLogList.find((t=>t.filePath===e.testFilePath));if(s&&s.logs.length>0){const e=t.ele("div",{class:"suite-consolelog"});e.ele("div",{class:"suite-consolelog-header"},"Console Log"),s.logs.forEach((t=>{const s=e.ele("div",{class:"suite-consolelog-item"});s.ele("pre",{class:"suite-consolelog-item-origin"},this.sanitizeOutput(t.origin)),s.ele("pre",{class:"suite-consolelog-item-message"},this.sanitizeOutput(t.message))}))}}renderSuiteObsoleteSnapshots(e,t){const s=e.ele("div",{class:"suite-obsolete-snapshots"});s.ele("div",{class:"suite-obsolete-snapshots-header"},"Obsolete snapshots");s.ele("div",{class:"suite-obsolete-snapshots-item"}).ele("pre",{class:"suite-obsolete-snapshots-item-message"},t.snapshot.uncheckedKeys.join("\n"))}setupConfig(e){const{append:t,boilerplate:s,customScriptPath:i,dateFormat:a,executionTimeWarningThreshold:l,logo:n,includeConsoleLog:o,includeFailureMsg:u,includeSuiteFailure:d,includeObsoleteSnapshots:h,outputPath:g,pageTitle:f,theme:p,sort:m,statusIgnoreFilter:T,styleOverridePath:E,useCssFile:S}=e||{};this.config={append:{defaultValue:!1,environmentVariable:"JEST_HTML_REPORTER_APPEND",configValue:t},boilerplate:{defaultValue:null,environmentVariable:"JEST_HTML_REPORTER_BOILERPLATE",configValue:s},customScriptPath:{defaultValue:null,environmentVariable:"JEST_HTML_REPORTER_CUSTOM_SCRIPT_PATH",configValue:i},dateFormat:{defaultValue:"yyyy-mm-dd HH:MM:ss",environmentVariable:"JEST_HTML_REPORTER_DATE_FORMAT",configValue:a},executionTimeWarningThreshold:{defaultValue:5,environmentVariable:"JEST_HTML_REPORTER_EXECUTION_TIME_WARNING_THRESHOLD",configValue:l},logo:{defaultValue:null,environmentVariable:"JEST_HTML_REPORTER_LOGO",configValue:n},includeFailureMsg:{defaultValue:!1,environmentVariable:"JEST_HTML_REPORTER_INCLUDE_FAILURE_MSG",configValue:u},includeSuiteFailure:{defaultValue:!1,environmentVariable:"JEST_HTML_REPORTER_INCLUDE_SUITE_FAILURE",configValue:d},includeObsoleteSnapshots:{defaultValue:!1,environmentVariable:"JEST_HTML_REPORTER_INCLUDE_OBSOLETE_SNAPSHOTS",configValue:h},includeConsoleLog:{defaultValue:!1,environmentVariable:"JEST_HTML_REPORTER_INCLUDE_CONSOLE_LOG",configValue:o},outputPath:{defaultValue:c.default.join(process.cwd(),"test-report.html"),environmentVariable:"JEST_HTML_REPORTER_OUTPUT_PATH",configValue:g},pageTitle:{defaultValue:"Test Report",environmentVariable:"JEST_HTML_REPORTER_PAGE_TITLE",configValue:f},theme:{defaultValue:"defaultTheme",environmentVariable:"JEST_HTML_REPORTER_THEME",configValue:p},sort:{defaultValue:null,environmentVariable:"JEST_HTML_REPORTER_SORT",configValue:m},statusIgnoreFilter:{defaultValue:null,environmentVariable:"JEST_HTML_REPORTER_STATUS_FILTER",configValue:T},styleOverridePath:{defaultValue:null,environmentVariable:"JEST_HTML_REPORTER_STYLE_OVERRIDE_PATH",configValue:E},useCssFile:{defaultValue:!1,environmentVariable:"JEST_HTML_REPORTER_USE_CSS_FILE",configValue:S}};try{const e=r.default.readFileSync(c.default.join(process.cwd(),"jesthtmlreporter.config.json"),"utf8");if(e){const t=JSON.parse(e);for(const e of Object.keys(t))this.config[e]&&(this.config[e].configValue=t[e]);return this.config}}catch(e){}try{const e=r.default.readFileSync(c.default.join(process.cwd(),"package.json"),"utf8");if(e){const t=JSON.parse(e)["jest-html-reporter"];for(const e of Object.keys(t))this.config[e]&&(this.config[e].configValue=t[e]);return this.config}}catch(e){}}getConfigValue(e){const t=this.config[e];if(t)return process.env[t.environmentVariable]?process.env[t.environmentVariable]:t.configValue||t.defaultValue}async appendToFile(e,t){let s=t;if(r.default.existsSync(e)){const i=r.default.readFileSync(e,"utf8"),a=/<body>(.*?)<\/body>/gm.exec(t);if(a){const[e]=a;s=e}let l=i;const n=/<\/body>/gm.exec(i),o=n?n.index:0;return l=[i.slice(0,o),s,i.slice(o)].join(""),r.default.writeFileSync(e,l)}return r.default.appendFileSync(e,s)}replaceRootDirInPath(e,t){return/^<rootDir>/.test(t)?c.default.resolve(e,c.default.normalize("./"+t.substring("<rootDir>".length))):t}logMessage(e,t){const s={default:"%s",success:"%s",error:"%s"},i=s[e]?s[e]:s.default,a=`jest-html-reporter >> ${t}`;return void 0===process.env.JEST_WORKER_ID&&console.log(i,a),{logColor:i,logMsg:a}}sanitizeOutput(e){return d.default(e.replace(/([^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFC\u{10000}-\u{10FFFF}])/gu,""))}}const R=e=>new S(e).generate();module.exports=function(e,t){const s=[];if(Object.prototype.hasOwnProperty.call(e,"testResults")){const s=e;return R({testData:s,options:t}),s}this.onTestResult=(e,t)=>{t.console&&s.push({filePath:t.testFilePath,logs:t.console})},this.onRunComplete=(i,a)=>R({testData:a,options:t,jestConfig:e,consoleLogs:s})};
"use strict";var e=require("dateformat"),t=require("fs"),s=require("mkdirp"),i=require("path"),a=require("strip-ansi"),l=require("xmlbuilder");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(e),r=n(t),u=n(s),c=n(i),d=n(a),h=n(l);const g=e=>{const t=[],s=[],i=[];return e.forEach((e=>{const a=[],l=[],n=[];e.testResults.forEach((e=>{"pending"===e.status?a.push(e):"failed"===e.status?l.push(e):n.push(e)})),a.length>0&&t.push({...e,testResults:a}),l.length>0&&s.push({...e,testResults:l}),n.length>0&&i.push({...e,testResults:n})})),[].concat(t,s,i)},f=e=>(e&&e.sort(((e,t)=>t.perfStats.end-t.perfStats.start-(e.perfStats.end-e.perfStats.start))),e),m=e=>(e&&e.sort(((e,t)=>e.perfStats.end-e.perfStats.start-(t.perfStats.end-t.perfStats.start))),e),p=e=>{if(e){const t=e.sort(((e,t)=>S(e.testFilePath,t.testFilePath,!0)));return t.forEach((e=>{e.testResults.sort(((e,t)=>S(e.ancestorTitles.join(" "),t.ancestorTitles.join(" "),!0))),e.testResults.sort(((e,t)=>S(e.title,t.title,!0)))})),t}return e},T=e=>{if(e){const t=e.sort(((e,t)=>S(e.testFilePath,t.testFilePath)));return t.forEach((e=>{e.testResults.sort(((e,t)=>S(e.ancestorTitles.join(" "),t.ancestorTitles.join(" ")))),e.testResults.sort(((e,t)=>S(e.title,t.title)))})),t}return e},S=(e,t,s=!1)=>!s&&e<t||s&&e>t?-1:!s&&e>t||s&&e<t?1:0;class E{constructor(e){this.testData=e.testData,this.jestConfig=e.jestConfig,this.consoleLogList=e.consoleLogs,this.setupConfig(e.options)}async generate(){try{const e=await this.renderTestReport(),t=this.replaceRootDirInPath(this.jestConfig?this.jestConfig.rootDir:"",this.getConfigValue("outputPath"));await u.default(c.default.dirname(t));let s=!0;if(this.getConfigValue("append")){r.default.existsSync(t)&&(await this.appendToFile(t,e.content.toString()),s=!1)}return s&&r.default.writeFileSync(t,e.fullHtml.toString()),this.logMessage("success",`Report generated (${t})`),e.fullHtml}catch(e){this.logMessage("error",e)}}async renderTestReport(){const e=await this.renderTestReportContent();if(this.getConfigValue("boilerplate")){const t=this.replaceRootDirInPath(this.jestConfig?this.jestConfig.rootDir:"",this.getConfigValue("boilerplate")),s=r.default.readFileSync(t,"utf8");return{content:e.toString(),fullHtml:s.replace("{jesthtmlreporter-content}",e&&e.toString())}}const t=h.default.create({html:{}}),s=t.ele("head");s.ele("meta",{charset:"utf-8"}),s.ele("title",{},this.getConfigValue("pageTitle"));let i=c.default.join(__dirname,`../style/${this.getConfigValue("theme")}.css`);this.getConfigValue("styleOverridePath")&&(i=this.getConfigValue("styleOverridePath"));if(!this.getConfigValue("useCssFile")&&!this.getConfigValue("styleOverridePath")){const e=r.default.readFileSync(i,"utf8");s.raw(`<style type="text/css">${e}</style>`)}else s.ele("link",{rel:"stylesheet",type:"text/css",href:i});const a=t.ele("body");return e&&a.raw(e.toString()),this.getConfigValue("customScriptPath")&&a.raw(`<script src="${this.getConfigValue("customScriptPath")}"><\/script>`),{fullHtml:t.toString(),content:e.toString()}}renderTestSuiteInfo(e,t){const s=e.ele("div",{class:"suite-info"});s.ele("div",{class:"suite-path"},t.testFilePath);const i=(t.perfStats.end-t.perfStats.start)/1e3;s.ele("div",{class:"suite-time"+(i>this.getConfigValue("executionTimeWarningThreshold")?" warn":"")},`${i}s`)}renderSuiteFailure(e,t,s){const i=e.ele("div",{id:`suite-${s+1}`,class:"suite-container"});this.renderTestSuiteInfo(i,t);i.ele("div",{class:"suite-tests"}).ele("div",{class:"test-result failed"}).ele("div",{class:"failureMessages suiteFailure"}," ").ele("pre",{class:"failureMsg"},this.sanitizeOutput(t.failureMessage))}async renderTestReportContent(){try{if(!this.testData||0===Object.entries(this.testData).length)throw Error("No test data provided");const e=h.default.begin().element("div",{class:"jesthtml-content"}),t=e.ele("header");t.ele("h1",{id:"title"},this.getConfigValue("pageTitle"));const s=this.getConfigValue("logo");s&&t.ele("img",{id:"logo",src:s});const i=e.ele("div",{id:"metadata-container"});if(this.testData.startTime&&!isNaN(this.testData.startTime)){const e=new Date(this.testData.startTime);if(e){const t=o.default(e,this.getConfigValue("dateFormat"));i.ele("div",{id:"timestamp"},`Started: ${t}`)}}const a=i.ele("div",{id:"summary"}),l=a.ele("div",{id:"suite-summary"});l.ele("div",{class:"summary-total"},`Suites (${this.testData.numTotalTestSuites})`),l.ele("div",{class:"summary-passed"+(0===this.testData.numPassedTestSuites?" summary-empty":"")},`${this.testData.numPassedTestSuites} passed`),l.ele("div",{class:"summary-failed"+(0===this.testData.numFailedTestSuites?" summary-empty":"")},`${this.testData.numFailedTestSuites} failed`),l.ele("div",{class:"summary-pending"+(0===this.testData.numPendingTestSuites?" summary-empty":"")},`${this.testData.numPendingTestSuites} pending`),this.testData.snapshot&&this.testData.snapshot.unchecked>0&&this.getConfigValue("includeObsoleteSnapshots")&&l.ele("div",{class:"summary-obsolete-snapshots"},`${this.testData.snapshot.unchecked} obsolete snapshots`);const n=a.ele("div",{id:"test-summary"});n.ele("div",{class:"summary-total"},`Tests (${this.testData.numTotalTests})`),n.ele("div",{class:"summary-passed"+(0===this.testData.numPassedTests?" summary-empty":"")},`${this.testData.numPassedTests} passed`),n.ele("div",{class:"summary-failed"+(0===this.testData.numFailedTests?" summary-empty":"")},`${this.testData.numFailedTests} failed`),n.ele("div",{class:"summary-pending"+(0===this.testData.numPendingTests?" summary-empty":"")},`${this.testData.numPendingTests} pending`);const r=((e,t)=>{switch(t&&t.toLowerCase()){case"status":return g(e);case"executiondesc":return f(e);case"executionasc":return m(e);case"titledesc":return p(e);case"titleasc":return T(e);default:return e}})(this.testData.testResults,this.getConfigValue("sort")),u=this.getConfigValue("statusIgnoreFilter");let c=[];return u&&(c=u.replace(/\s/g,"").toLowerCase().split(",")),r&&r.forEach(((t,s)=>{if(!t.testResults||t.testResults.length<=0)return void(t.failureMessage&&this.getConfigValue("includeSuiteFailure")&&this.renderSuiteFailure(e,t,s));const i=e.ele("div",{id:`suite-${s+1}`,class:"suite-container"});this.renderTestSuiteInfo(i,t);const a=i.ele("div",{class:"suite-tests"});t.testResults.filter((e=>!c.includes(e.status))).forEach((async e=>{const t=a.ele("div",{class:`test-result ${e.status}`}),s=t.ele("div",{class:"test-info"});if(s.ele("div",{class:"test-suitename"},e.ancestorTitles&&e.ancestorTitles.length>0?e.ancestorTitles.join(" > "):" "),s.ele("div",{class:"test-title"},e.title),s.ele("div",{class:"test-status"},e.status),s.ele("div",{class:"test-duration"},e.duration/1e3+"s"),e.failureMessages&&e.failureMessages.length>0&&this.getConfigValue("includeFailureMsg")){const s=t.ele("div",{class:"failureMessages"}," ");e.failureMessages.forEach((e=>{s.ele("pre",{class:"failureMsg"},this.sanitizeOutput(e))}))}})),this.consoleLogList&&this.consoleLogList.length>0&&this.getConfigValue("includeConsoleLog")&&this.renderSuiteConsoleLogs(t,i),t.snapshot&&t.snapshot.unchecked>0&&this.getConfigValue("includeObsoleteSnapshots")&&this.renderSuiteObsoleteSnapshots(i,t)})),e}catch(e){this.logMessage("error",e)}}renderSuiteConsoleLogs(e,t){const s=this.consoleLogList.find((t=>t.filePath===e.testFilePath));if(s&&s.logs.length>0){const e=t.ele("div",{class:"suite-consolelog"});e.ele("div",{class:"suite-consolelog-header"},"Console Log"),s.logs.forEach((t=>{const s=e.ele("div",{class:"suite-consolelog-item"});s.ele("pre",{class:"suite-consolelog-item-origin"},this.sanitizeOutput(t.origin)),s.ele("pre",{class:"suite-consolelog-item-message"},this.sanitizeOutput(t.message))}))}}renderSuiteObsoleteSnapshots(e,t){const s=e.ele("div",{class:"suite-obsolete-snapshots"});s.ele("div",{class:"suite-obsolete-snapshots-header"},"Obsolete snapshots");s.ele("div",{class:"suite-obsolete-snapshots-item"}).ele("pre",{class:"suite-obsolete-snapshots-item-message"},t.snapshot.uncheckedKeys.join("\n"))}setupConfig(e){const{append:t,boilerplate:s,customScriptPath:i,dateFormat:a,executionTimeWarningThreshold:l,logo:n,includeConsoleLog:o,includeFailureMsg:u,includeSuiteFailure:d,includeObsoleteSnapshots:h,outputPath:g,pageTitle:f,theme:m,sort:p,statusIgnoreFilter:T,styleOverridePath:S,useCssFile:E}=e||{};this.config={append:{defaultValue:!1,environmentVariable:"JEST_HTML_REPORTER_APPEND",configValue:t},boilerplate:{defaultValue:null,environmentVariable:"JEST_HTML_REPORTER_BOILERPLATE",configValue:s},customScriptPath:{defaultValue:null,environmentVariable:"JEST_HTML_REPORTER_CUSTOM_SCRIPT_PATH",configValue:i},dateFormat:{defaultValue:"yyyy-mm-dd HH:MM:ss",environmentVariable:"JEST_HTML_REPORTER_DATE_FORMAT",configValue:a},executionTimeWarningThreshold:{defaultValue:5,environmentVariable:"JEST_HTML_REPORTER_EXECUTION_TIME_WARNING_THRESHOLD",configValue:l},logo:{defaultValue:null,environmentVariable:"JEST_HTML_REPORTER_LOGO",configValue:n},includeFailureMsg:{defaultValue:!1,environmentVariable:"JEST_HTML_REPORTER_INCLUDE_FAILURE_MSG",configValue:u},includeSuiteFailure:{defaultValue:!1,environmentVariable:"JEST_HTML_REPORTER_INCLUDE_SUITE_FAILURE",configValue:d},includeObsoleteSnapshots:{defaultValue:!1,environmentVariable:"JEST_HTML_REPORTER_INCLUDE_OBSOLETE_SNAPSHOTS",configValue:h},includeConsoleLog:{defaultValue:!1,environmentVariable:"JEST_HTML_REPORTER_INCLUDE_CONSOLE_LOG",configValue:o},outputPath:{defaultValue:c.default.join(process.cwd(),"test-report.html"),environmentVariable:"JEST_HTML_REPORTER_OUTPUT_PATH",configValue:g},pageTitle:{defaultValue:"Test Report",environmentVariable:"JEST_HTML_REPORTER_PAGE_TITLE",configValue:f},theme:{defaultValue:"defaultTheme",environmentVariable:"JEST_HTML_REPORTER_THEME",configValue:m},sort:{defaultValue:null,environmentVariable:"JEST_HTML_REPORTER_SORT",configValue:p},statusIgnoreFilter:{defaultValue:null,environmentVariable:"JEST_HTML_REPORTER_STATUS_FILTER",configValue:T},styleOverridePath:{defaultValue:null,environmentVariable:"JEST_HTML_REPORTER_STYLE_OVERRIDE_PATH",configValue:S},useCssFile:{defaultValue:!1,environmentVariable:"JEST_HTML_REPORTER_USE_CSS_FILE",configValue:E}};try{const e=r.default.readFileSync(c.default.join(process.cwd(),"jesthtmlreporter.config.json"),"utf8");if(e){const t=JSON.parse(e);for(const e of Object.keys(t))this.config[e]&&(this.config[e].configValue=t[e]);return this.config}}catch(e){}try{const e=r.default.readFileSync(c.default.join(process.cwd(),"package.json"),"utf8");if(e){const t=JSON.parse(e)["jest-html-reporter"];for(const e of Object.keys(t))this.config[e]&&(this.config[e].configValue=t[e]);return this.config}}catch(e){}}getConfigValue(e){const t=this.config[e];if(t)return process.env[t.environmentVariable]?process.env[t.environmentVariable]:t.configValue||t.defaultValue}async appendToFile(e,t){let s=t;const i=r.default.readFileSync(e,"utf8"),a=/<body>(.*?)<\/body>/gm.exec(t);if(a){const[e]=a;s=e}let l=i;const n=/<\/body>/gm.exec(i),o=n?n.index:0;return l=[i.slice(0,o),s,i.slice(o)].join(""),r.default.writeFileSync(e,l)}replaceRootDirInPath(e,t){return/^<rootDir>/.test(t)?c.default.resolve(e,c.default.normalize("./"+t.substring(9))):t}logMessage(e,t){const s={default:"%s",success:"%s",error:"%s"},i=s[e]?s[e]:s.default,a=`jest-html-reporter >> ${t}`;return void 0===process.env.JEST_WORKER_ID&&console.log(i,a),{logColor:i,logMsg:a}}sanitizeOutput(e){return d.default(e.replace(/([^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFC\u{10000}-\u{10FFFF}])/gu,""))}}const R=e=>new E(e).generate();module.exports=function(e,t){const s=[];if(Object.prototype.hasOwnProperty.call(e,"testResults")){const s=e;return R({testData:s,options:t}),s}this.onTestResult=(e,t)=>{t.console&&s.push({filePath:t.testFilePath,logs:t.console})},this.onRunComplete=(i,a)=>R({testData:a,options:t,jestConfig:e,consoleLogs:s})};
{
"name": "jest-html-reporter",
"version": "3.7.1",
"version": "3.8.0",
"description": "Jest test results processor for generating a summary in HTML",

@@ -60,3 +60,3 @@ "main": "dist/index.js",

"@types/dateformat": "^3.0.X",
"@types/jest": "29.0.0",
"@types/jest": "^29.0.0",
"@types/mkdirp": "1.0.2",

@@ -63,0 +63,0 @@ "@types/node": "12.20.12",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc