Skip to content

Commit

Permalink
Merge pull request #39 from Hargne/feature/2.3.0
Browse files Browse the repository at this point in the history
2.3.0
  • Loading branch information
Hargne authored Apr 17, 2018
2 parents e792a72 + a257644 commit 6205805
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ To configure this plugin, create a file named `jesthtmlreporter.config.json` in
| `pageTitle` | `STRING` | The title of the document. This string will also be outputted on the top of the page. | `"Test Suite"`
| `outputPath` | `STRING` | The path to where the plugin will output the HTML report. The path must include the filename and end with .html | `"./test-report.html"`
| `includeFailureMsg` | `BOOLEAN` | If this setting is set to true, this will output the detailed failure message for each failed test. | `false`
| `includeConsoleLog` | `BOOLEAN` | If set to true, this will output all triggered console logs for each test suite. | `false`
| `styleOverridePath` | `STRING` | The path to a file containing CSS styles that should override the default styling.* | `null`
| `customScriptPath` | `STRING` | Path to a javascript file that should be injected into the test report | `null`
| `theme` | `STRING` | The name of the reporter themes to use when rendering the report. You can find the available themes in the [Documentation](https://github.com/Hargne/jest-html-reporter/wiki/Test-Report-Themes) | `"defaultTheme"`
Expand Down
1 change: 1 addition & 0 deletions jesthtmlreporter.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"pageTitle": "Test Suite Report",
"outputPath": "test-report.html",
"includeFailureMsg": true,
"includeConsoleLog": true,
"useAsReporter": false,
"sort": "titleAsc"
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-html-reporter",
"version": "2.2.0",
"version": "2.3.0",
"description": "Jest test results processor for generating a summary in HTML",
"main": "dist/main",
"unpkg": "dist/main.min.js",
Expand All @@ -10,7 +10,8 @@
],
"scripts": {
"eslint": "./node_modules/.bin/eslint ./src/**/*.js",
"test": "npm run eslint && jest --no-cache --config=jest.config.json",
"jest": "jest --no-cache --config=jest.config.json",
"test": "npm run eslint && npm run jest",
"bundle": "rollup -c rollup.config.js",
"bundle:minified": "rollup -c rollup.config.js --environment BUILD:minified",
"bundle:all": "npm run bundle && npm run bundle:minified",
Expand Down
8 changes: 8 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ const getLogo = () =>
const shouldIncludeFailureMessages = () =>
process.env.JEST_HTML_REPORTER_INCLUDE_FAILURE_MSG || config.includeFailureMsg || false;

/**
* Returns whether the report should contain console.logs or not
* @return {Boolean}
*/
const shouldIncludeConsoleLog = () =>
process.env.JEST_HTML_REPORTER_INCLUDE_CONSOLE_LOG || config.includeConsoleLog || false;

/**
* Returns the configured threshold (in seconds) when to apply a warning
* @return {Number}
Expand Down Expand Up @@ -115,6 +122,7 @@ module.exports = {
getPageTitle,
getLogo,
shouldIncludeFailureMessages,
shouldIncludeConsoleLog,
getExecutionTimeWarningThreshold,
getTheme,
getDateFormat,
Expand Down
15 changes: 15 additions & 0 deletions src/reportGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@ class ReportGenerator {
// Append data to <tr>
testTr.ele('td', { class: 'result' }, (test.status === 'passed') ? `${test.status} in ${test.duration / 1000}s` : test.status);
});

// Test Suite console.logs
if (suite.console && suite.console.length > 0 && (this.config.shouldIncludeConsoleLog())) {
// Console Log Container
const consoleLogContainer = htmlOutput.ele('div', { class: 'suite-consolelog' });
// Console Log Header
consoleLogContainer.ele('div', { class: 'suite-consolelog-header' }, 'Console Log');

// Logs
suite.console.forEach((log) => {
const logElement = consoleLogContainer.ele('div', { class: 'suite-consolelog-item' });
logElement.ele('pre', { class: 'suite-consolelog-item-origin' }, stripAnsi(log.origin));
logElement.ele('pre', { class: 'suite-consolelog-item-message' }, stripAnsi(log.message));
});
}
});
// Custom Javascript
const customScript = this.config.getCustomScriptFilepath();
Expand Down
25 changes: 25 additions & 0 deletions style/darkTheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,28 @@ header {
width: 20%;
text-align: right;
}

/* CONSOLE LOGS */
.suite-consolelog {
margin-bottom: 2rem;
padding: 1rem;
border-left: 0.5rem solid #999;
color: #999;
}
.suite-consolelog-header {
font-weight: bold;
}
.suite-consolelog-item {
padding: 0.5rem;
}
.suite-consolelog-item pre {
margin: 0;
}
.suite-consolelog-item-origin {
color: #555;
font-weight: bold;
}
.suite-consolelog-item-message {
font-size: 1rem;
padding: 0 0.5rem;
}
25 changes: 25 additions & 0 deletions style/defaultTheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,28 @@ header {
width: 20%;
text-align: right;
}

/* CONSOLE LOGS */
.suite-consolelog {
margin-bottom: 2rem;
padding: 1rem;
background-color: #efefef;
}
.suite-consolelog-header {
font-weight: bold;
}
.suite-consolelog-item {
padding: 0.5rem;
}
.suite-consolelog-item pre {
margin: 0;
}
.suite-consolelog-item-origin {
color: #777;
font-weight: bold;
}
.suite-consolelog-item-message {
color: #000;
font-size: 1rem;
padding: 0 0.5rem;
}
26 changes: 26 additions & 0 deletions style/lightTheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,29 @@ header {
width: 20%;
text-align: right;
}

/* CONSOLE LOGS */
.suite-consolelog {
margin-bottom: 2rem;
padding: 1rem;
border-left: 0.5rem solid #666;
color: #666;
box-shadow: 0px 3px 8px rgba(0, 0, 0, 0.3);
}
.suite-consolelog-header {
font-weight: bold;
}
.suite-consolelog-item {
padding: 0.5rem;
}
.suite-consolelog-item pre {
margin: 0;
}
.suite-consolelog-item-origin {
color: #aaa;
font-weight: bold;
}
.suite-consolelog-item-message {
font-size: 1rem;
padding: 0 0.5rem;
}
16 changes: 16 additions & 0 deletions test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('config', () => {
pageTitle: null,
logo: null,
includeFailureMsg: null,
includeConsoleLog: null,
executionTimeWarningThreshold: null,
dateFormat: null,
sort: null,
Expand All @@ -25,6 +26,7 @@ describe('config', () => {
delete process.env.JEST_HTML_REPORTER_PAGE_TITLE;
delete process.env.JEST_HTML_REPORTER_LOGO;
delete process.env.JEST_HTML_REPORTER_INCLUDE_FAILURE_MSG;
delete process.env.JEST_HTML_REPORTER_INCLUDE_CONSOLE_LOG;
delete process.env.JEST_HTML_REPORTER_EXECUTION_TIME_WARNING_THRESHOLD;
delete process.env.JEST_HTML_REPORTER_DATE_FORMAT;
delete process.env.JEST_HTML_REPORTER_SORT;
Expand Down Expand Up @@ -125,6 +127,20 @@ describe('config', () => {
});
});

describe('shouldIncludeConsoleLog', () => {
it('should return the value from package.json or jesthtmlreporter.config.json', () => {
config.setConfigData({ includeConsoleLog: true });
expect(config.shouldIncludeConsoleLog()).toEqual(true);
});
it('should return the environment variable', () => {
process.env.JEST_HTML_REPORTER_INCLUDE_CONSOLE_LOG = true;
expect(config.shouldIncludeConsoleLog()).toEqual('true');
});
it('should return the default value if no setting was provided', () => {
expect(config.shouldIncludeConsoleLog()).toEqual(false);
});
});

describe('getExecutionTimeWarningThreshold', () => {
it('should return the value from package.json or jesthtmlreporter.config.json', () => {
config.setConfigData({ executionTimeWarningThreshold: 10 });
Expand Down
5 changes: 2 additions & 3 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ const config = require('../src/config');

const pathToConfig = '../src/config';
// Mock the static config methods by extending the default config
const mockedConfigFunctions = {
...config,
const mockedConfigFunctions = Object.assign({
setup: jest.fn(),
getLogo: jest.fn(),
getCustomScriptFilepath: () => 'test.js',
};
}, config);

describe('index', () => {
beforeEach(() => {
Expand Down

0 comments on commit 6205805

Please sign in to comment.