Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Hargne/jest-html-reporter
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3.8.0
Choose a base ref
...
head repository: Hargne/jest-html-reporter
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3.9.0
Choose a head ref
  • 8 commits
  • 8 files changed
  • 1 contributor

Commits on Apr 20, 2023

  1. Update README.md

    Hargne committed Apr 20, 2023
    Copy the full SHA
    19c8944 View commit details

Commits on May 2, 2023

  1. Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    5720cdc View commit details
  2. Minor refactor

    Hargne committed May 2, 2023
    Copy the full SHA
    6223aff View commit details
  3. Removed .only

    Hargne committed May 2, 2023
    Copy the full SHA
    55b4137 View commit details
  4. Copy the full SHA
    c6ea3ae View commit details

Commits on May 3, 2023

  1. Copy the full SHA
    50ec5d2 View commit details
  2. Merge pull request #161 from Hargne/160-added-into-report-configurati…

    …on-additional-flag-includestacktrace-false
    
    Added includeStackTrace configuration option
    Hargne authored May 3, 2023
    Copy the full SHA
    722aebb View commit details
  3. Bump version

    Hargne committed May 3, 2023
    Copy the full SHA
    87d9d4f View commit details
Showing with 96 additions and 66 deletions.
  1. +2 −1 README.md
  2. +1 −1 jest.config.json
  3. +1 −1 package.json
  4. +27 −12 src/htmlreporter.ts
  5. +5 −46 src/types/index.d.ts
  6. +48 −0 test/htmlreporter.spec.ts
  7. +3 −2 test/index.spec.ts
  8. +9 −3 test/mockdata/index.ts
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
<br />
<img src="https://img.shields.io/npm/v/jest-html-reporter?style=flat-square">
<img src="https://img.shields.io/npm/dm/jest-html-reporter?style=flat-square">
<img src="https://img.shields.io/travis/com/hargne/jest-html-reporter?style=flat-square">
<img src="https://img.shields.io/github/actions/workflow/status/Hargne/jest-html-reporter/main.yml?branch=master&style=flat-square">
<br />
<br />
<small>Inspired by <a href="https://github.com/matthias-schuetz/karma-htmlfile-reporter">karma-htmlfile-reporter</a></small>
@@ -78,6 +78,7 @@ Please note that all configuration properties are optional.
| `executionTimeWarningThreshold` | `NUMBER` | The threshold for test execution time (in seconds) in each test suite that will render a warning on the report page. 5 seconds is the default timeout in Jest. | `5` |
| `includeConsoleLog` | `BOOLEAN` | If set to true, this will output all triggered console logs for each test suite. Please note that you have to run Jest together with `--verbose=false` in order to have Jest catch any logs during the tests. | `false` |
| `includeFailureMsg` | `BOOLEAN` | If this setting is set to true, this will output the detailed failure message for each failed test. | `false` |
| `includeStackTrace` | `BOOLEAN` | Turning this option off will cut the stack trace from the failure messages. | `true` |
| `includeSuiteFailure` | `BOOLEAN` | If set to true, this will output the detailed failure message for complete suite failures. | `false` |
| `includeObsoleteSnapshots` | `BOOLEAN` | If set to true, this will output obsolete snapshot names. | `false` |
| `logo` | `STRING` | Path to a logo that will be included in the header of the report | `null` |
2 changes: 1 addition & 1 deletion jest.config.json
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@
"statements": 50
}
},
"verbose": false,
"verbose": true,
"reporters": [
"default",
[
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-html-reporter",
"version": "3.8.0",
"version": "3.9.0",
"description": "Jest test results processor for generating a summary in HTML",
"main": "dist/index.js",
"unpkg": "dist/index.js",
39 changes: 27 additions & 12 deletions src/htmlreporter.ts
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ class HTMLReporter {
// Decide whether to inline the CSS or not
const inlineCSS: boolean =
!this.getConfigValue("useCssFile") &&
!!!this.getConfigValue("styleOverridePath");
!this.getConfigValue("styleOverridePath");

if (inlineCSS) {
const stylesheetContent = fs.readFileSync(stylesheetFilePath, "utf8");
@@ -116,7 +116,7 @@ class HTMLReporter {
reportBody.raw(reportContent.toString());
}
// Add any given custom script to the end of the body
if (!!this.getConfigValue("customScriptPath")) {
if (this.getConfigValue("customScriptPath")) {
reportBody.raw(
`<script src="${this.getConfigValue("customScriptPath")}"></script>`
);
@@ -404,13 +404,22 @@ class HTMLReporter {
},
" "
);
test.failureMessages.forEach((failureMsg) => {
failureMsgDiv.ele(
"pre",
{ class: "failureMsg" },
this.sanitizeOutput(failureMsg)
);
});
test.failureMessages
.map((failureMsg) =>
!this.getConfigValue("includeStackTrace")
? failureMsg
.split(/\n\s+at/)[0]
.trim()
.replace(/\n+$/, "")
: failureMsg
)
.forEach((failureMsg) => {
failureMsgDiv.ele(
"pre",
{ class: "failureMsg" },
this.sanitizeOutput(failureMsg)
);
});
}
});

@@ -517,6 +526,7 @@ class HTMLReporter {
logo,
includeConsoleLog,
includeFailureMsg,
includeStackTrace,
includeSuiteFailure,
includeObsoleteSnapshots,
outputPath,
@@ -565,6 +575,11 @@ class HTMLReporter {
environmentVariable: "JEST_HTML_REPORTER_INCLUDE_FAILURE_MSG",
configValue: includeFailureMsg,
},
includeStackTrace: {
defaultValue: true,
environmentVariable: "JEST_HTML_REPORTER_INCLUDE_STACK_TRACE",
configValue: includeStackTrace,
},
includeSuiteFailure: {
defaultValue: false,
environmentVariable: "JEST_HTML_REPORTER_INCLUDE_SUITE_FAILURE",
@@ -625,7 +640,7 @@ class HTMLReporter {
if (jesthtmlreporterconfig) {
const parsedConfig = JSON.parse(jesthtmlreporterconfig);
for (const key of Object.keys(parsedConfig)) {
if (this.config[key as keyof IJestHTMLReporterConfig]) {
if (key in this.config) {
this.config[key as keyof IJestHTMLReporterConfig].configValue =
parsedConfig[key];
}
@@ -644,7 +659,7 @@ class HTMLReporter {
if (packageJson) {
const parsedConfig = JSON.parse(packageJson)["jest-html-reporter"];
for (const key of Object.keys(parsedConfig)) {
if (this.config[key as keyof IJestHTMLReporterConfig]) {
if (key in this.config) {
this.config[key as keyof IJestHTMLReporterConfig].configValue =
parsedConfig[key];
}
@@ -669,7 +684,7 @@ class HTMLReporter {
if (process.env[option.environmentVariable]) {
return process.env[option.environmentVariable];
}
return option.configValue || option.defaultValue;
return option.configValue ?? option.defaultValue;
}

/**
51 changes: 5 additions & 46 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ export type IJestHTMLReporterConfigOptions = {
executionTimeWarningThreshold?: number;
includeConsoleLog?: boolean;
includeFailureMsg?: boolean;
includeStackTrace?: boolean;
includeSuiteFailure?: boolean;
includeObsoleteSnapshots?: boolean;
logo?: string;
@@ -35,53 +36,11 @@ export interface IJestHTMLReporterConfigOption<T> {
defaultValue: T;
}

export interface IJestHTMLReporterConfig {
append: IJestHTMLReporterConfigOption<
IJestHTMLReporterConfigOptions["append"]
export type IJestHTMLReporterConfig = {
[key in keyof IJestHTMLReporterConfigOptions]: IJestHTMLReporterConfigOption<
IJestHTMLReporterConfigOptions[key]
>;
boilerplate: IJestHTMLReporterConfigOption<
IJestHTMLReporterConfigOptions["boilerplate"]
>;
customScriptPath: IJestHTMLReporterConfigOption<
IJestHTMLReporterConfigOptions["customScriptPath"]
>;
dateFormat: IJestHTMLReporterConfigOption<
IJestHTMLReporterConfigOptions["dateFormat"]
>;
executionTimeWarningThreshold: IJestHTMLReporterConfigOption<
IJestHTMLReporterConfigOptions["executionTimeWarningThreshold"]
>;
includeConsoleLog: IJestHTMLReporterConfigOption<
IJestHTMLReporterConfigOptions["includeConsoleLog"]
>;
includeFailureMsg: IJestHTMLReporterConfigOption<
IJestHTMLReporterConfigOptions["includeFailureMsg"]
>;
includeSuiteFailure: IJestHTMLReporterConfigOption<
IJestHTMLReporterConfigOptions["includeSuiteFailure"]
>;
includeObsoleteSnapshots: IJestHTMLReporterConfigOption<
IJestHTMLReporterConfigOptions["includeObsoleteSnapshots"]
>;
logo: IJestHTMLReporterConfigOption<IJestHTMLReporterConfigOptions["logo"]>;
outputPath: IJestHTMLReporterConfigOption<
IJestHTMLReporterConfigOptions["outputPath"]
>;
pageTitle: IJestHTMLReporterConfigOption<
IJestHTMLReporterConfigOptions["pageTitle"]
>;
sort: IJestHTMLReporterConfigOption<IJestHTMLReporterConfigOptions["sort"]>;
statusIgnoreFilter: IJestHTMLReporterConfigOption<
IJestHTMLReporterConfigOptions["statusIgnoreFilter"]
>;
styleOverridePath: IJestHTMLReporterConfigOption<
IJestHTMLReporterConfigOptions["styleOverridePath"]
>;
theme: IJestHTMLReporterConfigOption<IJestHTMLReporterConfigOptions["theme"]>;
useCssFile: IJestHTMLReporterConfigOption<
IJestHTMLReporterConfigOptions["useCssFile"]
>;
}
};

export interface IJestHTMLReporterConsole {
filePath: string;
48 changes: 48 additions & 0 deletions test/htmlreporter.spec.ts
Original file line number Diff line number Diff line change
@@ -182,6 +182,54 @@ describe("HTMLReporter", () => {
});
});

describe("includeStackTrace", () => {
it("should remove stack traces in failure messages if set to false", async () => {
const reporter = new HTMLReporter({
testData: mockedJestResponseSingleTestResult,
options: {
includeFailureMsg: true,
includeStackTrace: false,
},
});
const reportContent = await reporter.renderTestReportContent();
expect(reportContent).toBeDefined();
expect(
reportContent!
.toString()
.indexOf(
'<pre class="failureMsg">Error: failures that happened</pre>'
)
).not.toBe(-1);
});
it("should keep stack trace in failure messages if set to true", async () => {
const reporter = new HTMLReporter({
testData: mockedJestResponseSingleTestResult,
options: {
includeFailureMsg: true,
includeStackTrace: true,
},
});
const reportContent = await reporter.renderTestReportContent();
expect(reportContent).toBeDefined();
expect(
reportContent!.toString().indexOf("at stack trace")
).toBeGreaterThan(-1);
});
it("should keep stack trace in failure messages if undefined", async () => {
const reporter = new HTMLReporter({
testData: mockedJestResponseSingleTestResult,
options: {
includeFailureMsg: true,
},
});
const reportContent = await reporter.renderTestReportContent();
expect(reportContent).toBeDefined();
expect(
reportContent!.toString().indexOf("at stack trace")
).toBeGreaterThan(-1);
});
});

describe("includeSuiteFailure", () => {
it("should include suite failure message", async () => {
const reporter = new HTMLReporter({
5 changes: 3 additions & 2 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ import sinon, { SinonStub } from "sinon";

import JestHTMLReporter from "../src";
import {
mockedFullReportOutput,
mockedJestGlobalConfig,
mockedJestResponseSingleTestResult,
} from "./mockdata";
@@ -12,7 +11,9 @@ describe("index", () => {
let writeFileSync: SinonStub;

beforeEach(() => {
writeFileSync = sinon.stub(fs, "writeFileSync").returns(null as void);
writeFileSync = sinon
.stub(fs, "writeFileSync")
.returns(null as unknown as void);
});
afterEach(() => {
writeFileSync.restore();
12 changes: 9 additions & 3 deletions test/mockdata/index.ts
Original file line number Diff line number Diff line change
@@ -99,7 +99,9 @@ export const mockedJestResponseSingleTestResult: AggregatedResult = {
title: "title",
status: "pending",
ancestorTitles: ["ancestor"],
failureMessages: ["failure"],
failureMessages: [
"Error: failures that happened\n" + "\n" + " at stack trace",
],
failureDetails: ["detailed failure"],
numPassingAsserts: 0,
fullName: "pending",
@@ -215,7 +217,9 @@ export const mockedJestResponseMultipleTestResult: AggregatedResult = {
title: "title c",
status: "failed",
ancestorTitles: ["ancestor c", "ancestor child"],
failureMessages: ["failure"],
failureMessages: [
"Error: failures that happened\n" + "\n" + " at stack trace",
],
failureDetails: ["detailed failure"],
numPassingAsserts: 0,
fullName: "failed",
@@ -279,7 +283,9 @@ export const mockedJestResponseMultipleTestResult: AggregatedResult = {
title: "title c",
status: "failed",
ancestorTitles: ["ancestor c"],
failureMessages: ["failure"],
failureMessages: [
"Error: failures that happened\n" + "\n" + " at stack trace",
],
failureDetails: ["detailed failure"],
numPassingAsserts: 0,
fullName: "failed",