Skip to content

Commit

Permalink
2.8.0 - Improved test appending, Bumped versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Hargne committed Dec 10, 2019
1 parent 011c381 commit e090795
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Please note that all configuration properties are optional.
| `sort` | `STRING` | Sorts the test results using the given method. Available sorting methods can be found in the [documentation](https://github.com/Hargne/jest-html-reporter/wiki/Sorting-Methods). | `"default"`
| `statusIgnoreFilter` | `STRING` | A comma-separated string of the test result statuses that should be ignored when rendering the report. Available statuses are: `"passed"`, `"pending"`, `"failed"` | `null`
| `boilerplate` | `STRING` | The path to a boilerplate file that should be used to render the body of the test results into. `{jesthtmlreporter-content}` within the boilerplate will be replaced with the test results | `null`
| `append` *NEW | `BOOLEAN` | If set to true, new test results will be appended to the existing test report | `false`
| `append` | `BOOLEAN` | If set to true, new test results will be appended to the existing test report | `false`

> *The plugin will search for the *styleOverridePath* from the root directory, therefore there is no need to prepend the string with `./` or `../` - You can read more about the themes in the [documentation](https://github.com/Hargne/jest-html-reporter/wiki/Test-Report-Themes).
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

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

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": "2.7.0",
"version": "2.8.0",
"description": "Jest test results processor for generating a summary in HTML",
"main": "dist/main",
"unpkg": "dist/main.min.js",
Expand Down
38 changes: 34 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,41 @@ const appendFile = ({ filePath, content }) => new Promise((resolve, reject) => {
if (mkdirpError) {
return reject(new Error(`Something went wrong when creating the folder: ${mkdirpError}`));
}
return fs.appendFile(filePath, content, (writeFileError) => {
if (writeFileError) {
return reject(new Error(`Something went wrong when appending the file: ${writeFileError}`));

// Check if the file exists or not
return fs.readFile(filePath, 'utf8', (err, existingContent) => {
let parsedContent = content;
// The file exists - we need to strip all unecessary html
if (!err) {
const contentSearch = /<body>(.*?)<\/body>/gm.exec(content);
if (contentSearch) {
const [strippedContent] = contentSearch;
parsedContent = strippedContent;
}
// Then we need to add the stripped content just before the </body> tag
if (existingContent) {
let newContent = existingContent;
const closingBodyTag = /<\/body>/gm.exec(existingContent);
const indexOfClosingBodyTag = closingBodyTag ? closingBodyTag.index : 0;

newContent = [existingContent.slice(0, indexOfClosingBodyTag), parsedContent, existingContent.slice(indexOfClosingBodyTag)]
.join('');

return fs.writeFile(filePath, newContent, (writeFileError) => {
if (writeFileError) {
return reject(new Error(`Something went wrong when creating the file: ${writeFileError}`));
}
return resolve(filePath);
});
}
}
return resolve(filePath);

return fs.appendFile(filePath, parsedContent, (writeFileError) => {
if (writeFileError) {
return reject(new Error(`Something went wrong when appending the file: ${writeFileError}`));
}
return resolve(filePath);
});
});
});
});
Expand Down
3 changes: 3 additions & 0 deletions style/darkTheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ body {
padding: 3rem;
font-size: 0.85rem;
}
#jesthtml-content {
margin-bottom: 2rem;
}
header {
display: flex;
align-items: center;
Expand Down
3 changes: 3 additions & 0 deletions style/defaultTheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ body {
padding: 1rem;
font-size: 0.85rem;
}
#jesthtml-content {
margin-bottom: 2rem;
}
header {
display: flex;
align-items: center;
Expand Down
3 changes: 3 additions & 0 deletions style/lightTheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ body {
padding: 3rem;
font-size: 0.85rem;
}
#jesthtml-content {
margin-bottom: 2rem;
}
header {
display: flex;
align-items: center;
Expand Down

0 comments on commit e090795

Please sign in to comment.