Skip to content

Commit

Permalink
Merge pull request #71 from DanielHaroldLane/fix/useCssFile-styleOver…
Browse files Browse the repository at this point in the history
…ridePath

Update not to load CSS content if useCssFile and styleOverridePath supplied
  • Loading branch information
Hargne authored Sep 2, 2019
2 parents b1e70de + 6869f3d commit 889c1c6
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ const getPageTitle = () =>
const getLogo = () =>
process.env.JEST_HTML_REPORTER_LOGO || config.logo || null;

/**
* Returns whether there is a user defined stylesheet override path
*/
const getHasStyleOverridePath = () =>
Boolean(process.env.JEST_HTML_REPORTER_STYLE_OVERRIDE_PATH) ||
Boolean(config.styleOverridePath);

/**
* Returns whether the report should contain failure messages or not
* @return {Boolean}
Expand All @@ -97,6 +104,11 @@ const shouldIncludeConsoleLog = () =>
const shouldUseCssFile = () =>
process.env.JEST_HTML_REPORTER_USE_CSS_FILE || config.useCssFile || false;

/**
* Returns whether the report should load the stylesheet content
*/
const shouldGetStylesheetContent = () => !(getHasStyleOverridePath() && shouldUseCssFile());

/**
* Returns the configured threshold (in seconds) when to apply a warning
* @return {Number}
Expand Down Expand Up @@ -132,12 +144,14 @@ module.exports = {
setConfigData,
getOutputFilepath,
getStylesheetFilepath,
getHasStyleOverridePath,
getCustomScriptFilepath,
getPageTitle,
getLogo,
shouldIncludeFailureMessages,
shouldIncludeConsoleLog,
shouldUseCssFile,
shouldGetStylesheetContent,
getExecutionTimeWarningThreshold,
getBoilerplatePath,
getTheme,
Expand Down
10 changes: 9 additions & 1 deletion src/reportGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ class ReportGenerator {
generate({ data, ignoreConsole }) {
const fileDestination = this.config.getOutputFilepath();
const useCssFile = this.config.shouldUseCssFile();
const shouldGetStylesheetContent = this.config.shouldGetStylesheetContent();
let stylesheetPath = null;
let stylesheetContent = null;

if (useCssFile) {
stylesheetPath = this.config.getStylesheetFilepath();
}

return this.getStylesheetContent()
if (shouldGetStylesheetContent) {
stylesheetContent = () => this.getStylesheetContent();
} else {
stylesheetContent = () => Promise.resolve();
}

return stylesheetContent()
.then(stylesheet => this.renderHtmlReport({
data,
stylesheet,
Expand Down
38 changes: 38 additions & 0 deletions test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,44 @@ describe('config', () => {
});
});

describe('getHasStyleOverridePath', () => {
it('should return true if the value from package.json or jesthtmlreporter.config.json is set', () => {
config.setConfigData({ styleOverridePath: 'setInJson.css' });
expect(config.getHasStyleOverridePath()).toEqual(true);
});
it('should return true if the environment variable is set', () => {
process.env.JEST_HTML_REPORTER_STYLE_OVERRIDE_PATH = 'setInEnv.css';
expect(config.getHasStyleOverridePath()).toEqual(true);
});
it('should return false if no setting was provided', () => {
expect(config.getHasStyleOverridePath()).toEqual(false);
});
});

describe('shouldGetStylesheetContent', () => {
it('should return false if styleOverridePath and useCssFile from package.json or jesthtmlreporter.config.json is set', () => {
config.setConfigData({
styleOverridePath: 'setInJson.css',
useCssFile: true,
});
expect(config.shouldGetStylesheetContent()).toEqual(false);
});
it('should return false if styleOverridePath and useCssFile environment variables are set', () => {
process.env.JEST_HTML_REPORTER_STYLE_OVERRIDE_PATH = 'setInEnv.css';
process.env.JEST_HTML_REPORTER_USE_CSS_FILE = true;
expect(config.shouldGetStylesheetContent()).toEqual(false);
});
it('should return true if only one variable is set', () => {
config.setConfigData({
useCssFile: true,
});
expect(config.shouldGetStylesheetContent()).toEqual(true);
});
it('should return true if no setting was provided', () => {
expect(config.shouldGetStylesheetContent()).toEqual(true);
});
});

describe('getPageTitle', () => {
it('should return the value from package.json or jesthtmlreporter.config.json', () => {
config.setConfigData({ pageTitle: 'setInJson' });
Expand Down

0 comments on commit 889c1c6

Please sign in to comment.