-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## [1.1.0](1.0.0...1.1.0) (2022-05-20) ### 📔 Docs * add readme ([b14bb6d](b14bb6d)) * add test docs ([11ccec9](11ccec9)) ### 🦊 CI/CD * fix publishConfig access ([9b18d84](9b18d84)) ### 🧪 Tests * fix index mkdirp mock ([a80af47](a80af47)) ### 🚀 Features * add oneFilePerSuite option ([c7691c4](c7691c4)) '
- Loading branch information
1 parent
c7691c4
commit 41046c8
Showing
7 changed files
with
257 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = filterEntries; | ||
|
||
function filterEntries(filterRegex, entries = []) { | ||
if (filterRegex == null) { | ||
return entries; | ||
} | ||
|
||
if (filterRegex instanceof RegExp) { | ||
return entries.filter(entry => !entry.match(filterRegex)); | ||
} | ||
|
||
return entries.filter(entry => !entry.match(new RegExp(filterRegex))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = groupResults; | ||
|
||
var _update = _interopRequireDefault(require("lodash/update")); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function groupResults(aggregatedResults) { | ||
return aggregatedResults.testResults.reduce((acc, testResult) => { | ||
testResult.testResults.forEach(test => { | ||
(0, _update.default)(acc, test.ancestorTitles.concat('testResults'), value => (value ?? []).concat(test)); | ||
}); | ||
return acc; | ||
}, {}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = groupSuites; | ||
|
||
var _kebabCase = _interopRequireDefault(require("lodash/kebabCase")); | ||
|
||
var _sortEntries = _interopRequireDefault(require("./sortEntries")); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function groupSuites(testResultGroup, filterRegex, sort) { | ||
const testFilter = filterRegex instanceof RegExp ? filterRegex : new RegExp(filterRegex ?? ''); | ||
const outputFiles = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
|
||
const generateFiles = (groups, parent = []) => { | ||
Object.keys(groups).forEach(suite => { | ||
if (filterRegex != null && suite.match(testFilter)) { | ||
return; | ||
} | ||
|
||
const group = groups[suite]; | ||
|
||
if (group != null && group.testResults != null) { | ||
const key = parent.concat(suite).filter(k => k).map(p => (0, _kebabCase.default)(p || '')).join('/'); | ||
outputFiles[key] = [`# ${suite}\n`].concat((0, _sortEntries.default)(sort, group.testResults.filter(test => { | ||
if (filterRegex != null && test.title.match(testFilter)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}).map(test => `- ${test.title}`))).join('\n'); | ||
} | ||
|
||
Object.keys(group).filter(k => k !== 'testResults').forEach(k => { | ||
generateFiles({ | ||
[k]: group[k] | ||
}, parent.concat(suite)); | ||
}); | ||
}, {}); | ||
}; | ||
|
||
generateFiles(testResultGroup); | ||
return outputFiles; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = sortEntries; | ||
|
||
function sortEntries(sort, entries) { | ||
if (!Array.isArray(entries)) { | ||
return entries; | ||
} | ||
|
||
if (sort === 'asc') { | ||
return entries.sort(); | ||
} | ||
|
||
if (sort === 'desc') { | ||
return entries.sort().reverse(); | ||
} | ||
|
||
return entries; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = _default; | ||
|
||
var _chalk = _interopRequireDefault(require("chalk")); | ||
|
||
var _fs = _interopRequireDefault(require("fs")); | ||
|
||
var _kebabCase = _interopRequireDefault(require("lodash/kebabCase")); | ||
|
||
var _mkdirp = _interopRequireDefault(require("mkdirp")); | ||
|
||
var _path = _interopRequireDefault(require("path")); | ||
|
||
var _filterEntries = _interopRequireDefault(require("../lib/filterEntries")); | ||
|
||
var _groupResults = _interopRequireDefault(require("../lib/groupResults")); | ||
|
||
var _groupSuites = _interopRequireDefault(require("../lib/groupSuites")); | ||
|
||
var _sortEntries = _interopRequireDefault(require("../lib/sortEntries")); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
async function _default(aggregatedResults, options) { | ||
if (aggregatedResults == null) { | ||
return; | ||
} | ||
|
||
const { | ||
title = 'Docs', | ||
logo, | ||
sort = 'none', | ||
filterRegex | ||
} = options; | ||
|
||
const currentPath = _path.default.resolve(); | ||
|
||
const outputPath = _path.default.resolve(currentPath, options.outputPath ?? './'); | ||
|
||
const testResultGroup = (0, _groupResults.default)(aggregatedResults); | ||
const outputFiles = (0, _groupSuites.default)(testResultGroup, filterRegex, sort); // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
|
||
function writeIndex(groups, parent = []) { | ||
const index = []; | ||
|
||
if (parent.length == 0) { | ||
if (logo != null) { | ||
index.push(`${logo}\n`); | ||
} | ||
|
||
index.push(`# ${title}\n`); | ||
} else { | ||
index.push(`# ${parent[parent.length - 1]}\n`); | ||
} | ||
|
||
(0, _sortEntries.default)(sort, (0, _filterEntries.default)(filterRegex, Object.keys(groups))).forEach(suite => { | ||
if (groups[suite].testResults == null) { | ||
index.push(`- [${suite}](${(0, _kebabCase.default)(suite)}/index.md)\n`); | ||
writeIndex(groups[suite], parent.concat(suite)); | ||
} else { | ||
index.push(`- [${suite}](${(0, _kebabCase.default)(suite)}.md)\n`); | ||
} | ||
}); | ||
|
||
const indexFile = _path.default.resolve(outputPath, parent.map(_kebabCase.default).join('/'), 'index.md'); | ||
|
||
_mkdirp.default.sync(_path.default.dirname(indexFile)); | ||
|
||
_fs.default.writeFileSync(indexFile, index.join('\n')); | ||
} | ||
|
||
writeIndex(testResultGroup); | ||
Object.keys(outputFiles).forEach(key => { | ||
const outputFile = _path.default.resolve(outputPath, `${key}.md`); | ||
|
||
const content = outputFiles[key]; | ||
|
||
_mkdirp.default.sync(_path.default.dirname(outputFile)); | ||
|
||
_fs.default.writeFileSync(outputFile, content); | ||
}); | ||
console.info(_chalk.default.greenBright(`@konecty/jest-doc-reporter >> ${Object.keys(outputFiles).length + 1} Reports generated to (${outputPath})`)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = _default; | ||
|
||
var _chalk = _interopRequireDefault(require("chalk")); | ||
|
||
var _fs = _interopRequireDefault(require("fs")); | ||
|
||
var _mkdirp = _interopRequireDefault(require("mkdirp")); | ||
|
||
var _path = _interopRequireDefault(require("path")); | ||
|
||
var _index = _interopRequireDefault(require("./index")); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
async function _default(aggregatedResults, options) { | ||
if (aggregatedResults == null) { | ||
return; | ||
} | ||
|
||
const result = (0, _index.default)({ | ||
testData: aggregatedResults, | ||
options: options | ||
}); | ||
|
||
const currentPath = _path.default.resolve(); | ||
|
||
const outputPath = _path.default.resolve(currentPath, options.outputPath ?? './'); | ||
|
||
_mkdirp.default.sync(outputPath); | ||
|
||
const outputFile = _path.default.resolve(outputPath, 'index.md'); | ||
|
||
_fs.default.writeFileSync(outputFile, result); | ||
|
||
console.info(_chalk.default.greenBright(`@konecty/jest-doc-reporter >> Report generated (${outputFile})`)); | ||
} |