I have a Cypress project which uses Typescript and I want to include a reporter.
Problem is that the reporter always shows only the compiled Javascript code.
I tried to google but the only thing I found was an unanswered question on stackoverflow. I also tried like 6 reporter, but every reporter used 'mochawesome-report-generator' as dependency or doesn't work at all.
I fixed it for me with a patch of mochawesome
patch-package
./node_modules/mochawesome/src/mochawesome.js
I added at runner.on('end', () => ...)
directly after endCalled = true;
const fileContent = fs.readFileSync(path.resolve(this.runner.suite.file), { encoding: 'utf8' }).split('\n');
const logLineIndices = fileContent.map((lineContent, lineIndex) => lineContent.match(/^\t+(it\\.only|it|only)/) ? lineIndex : undefined).filter(Boolean);
this.runner.suite.suites.forEach(suite => {
suite.tests.forEach(test => {
let testStartIndex = fileContent.findIndex(lineContent => lineContent.includes("'" + test.title + "'"));
while (!logLineIndices.includes(testStartIndex) || testStartIndex < 0) {
testStartIndex--;
}
if (testStartIndex < 0) return;
const endRegex = new RegExp('^\\t{' + fileContent[testStartIndex].search(/\S|$/) + '}}?\\);\\s');
const testEndIndex = fileContent.findIndex((lineContent, lineIndex) => lineIndex > testStartIndex && endRegex.test(lineContent));
if (testEndIndex > testStartIndex) {
test.body = fileContent.slice(testStartIndex, testEndIndex + 1).join('\n');
}
});
});
The regex is not the best, but its working in my cases