jest-allure2-reporter
Version:
Idiomatic Jest reporter for Allure Framework
50 lines • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractDocblockAbove = extractDocblockAbove;
function extractDocblockAbove(navigator, testLineIndex) {
if (!navigator.jump(testLineIndex))
return '';
if (!navigator.moveUp())
return '';
let currentLine = navigator.readLine();
const docblockEndIndex = getCommentEnd(currentLine);
if (docblockEndIndex === -1)
return '';
if (isSingleLineDocblock(currentLine, docblockEndIndex)) {
return currentLine;
}
const buffer = [];
buffer.unshift(currentLine.slice(0, Math.max(0, docblockEndIndex + 2)));
while (navigator.moveUp()) {
currentLine = navigator.readLine();
buffer.unshift(currentLine);
const start = getCommentStart(currentLine);
if (isDocblockStart(currentLine, start)) {
return buffer.join('\n');
}
if (start >= 0) {
break;
}
}
return '';
}
function isSingleLineDocblock(line, end) {
const start = getCommentStart(line);
if (start < 0)
return false;
return start < end;
}
function getCommentStart(line) {
const start = line.indexOf('/*');
if (start <= 0)
return start;
const whitespace = line.slice(0, start);
return whitespace.trim() ? -1 : start;
}
function getCommentEnd(line) {
return line.lastIndexOf('*/');
}
function isDocblockStart(line, commentIndex) {
return commentIndex >= 0 && line[commentIndex + 2] === '*';
}
//# sourceMappingURL=extractDocblockAbove.js.map