@testomatio/reporter
Version:
Testomatio Reporter Client
67 lines (66 loc) • 2.64 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const adapter_js_1 = __importDefault(require("./adapter.js"));
class CSharpAdapter extends adapter_js_1.default {
formatTest(t) {
// Extract example from title if not already present
if (!t.example) {
const exampleMatch = t.title.match(/\((.*?)\)/);
if (exampleMatch) {
// Extract parameters as object with numeric keys for API
const params = exampleMatch[1]
.split(',')
.map(param => param.trim())
.filter(param => param !== '');
t.example = {};
params.forEach((param, index) => {
t.example[index] = param;
});
}
}
// Remove parameters from title to avoid duplicates in Test Suite
// The example field will be used for grouping on import
t.title = t.title.replace(/\(.*?\)/, '').trim();
const suite = t.suite_title.split('.');
t.suite_title = suite.pop();
t.file = namespaceToFileName(t.file);
return t;
}
getFilePath(t) {
if (!t.file)
return null;
// Normalize path separators for cross-platform compatibility
let filePath = t.file.replace(/\\/g, '/');
// If file already has .cs extension, use it directly
if (filePath.endsWith('.cs')) {
// Make relative path if it's absolute
if (path_1.default.isAbsolute(filePath)) {
// Try to find project-relative path
const cwd = process.cwd().replace(/\\/g, '/');
if (filePath.startsWith(cwd)) {
filePath = path_1.default.relative(cwd, filePath).replace(/\\/g, '/');
}
}
return filePath;
}
// Convert namespace path to file path
const fileName = namespaceToFileName(filePath);
return fileName;
}
}
module.exports = CSharpAdapter;
function namespaceToFileName(fileName) {
if (!fileName)
return '';
// If already a .cs file path, clean it up
if (fileName.endsWith('.cs')) {
return fileName.replace(/\\/g, '/');
}
const fileParts = fileName.split('.');
fileParts[fileParts.length - 1] = fileParts[fileParts.length - 1]?.replace(/\$.*/, '');
return `${fileParts.join('/')}.cs`;
}