mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 22:07:09 +01:00
Add support for rspec
This commit is contained in:
parent
7e5f292040
commit
1a3cfe6b48
11 changed files with 450 additions and 0 deletions
118
dist/index.js
generated
vendored
118
dist/index.js
generated
vendored
|
|
@ -265,6 +265,7 @@ const dotnet_trx_parser_1 = __nccwpck_require__(2664);
|
|||
const java_junit_parser_1 = __nccwpck_require__(676);
|
||||
const jest_junit_parser_1 = __nccwpck_require__(1113);
|
||||
const mocha_json_parser_1 = __nccwpck_require__(6043);
|
||||
const rspec_json_parser_1 = __nccwpck_require__(406);
|
||||
const swift_xunit_parser_1 = __nccwpck_require__(5366);
|
||||
const path_utils_1 = __nccwpck_require__(4070);
|
||||
const github_utils_1 = __nccwpck_require__(3522);
|
||||
|
|
@ -434,6 +435,8 @@ class TestReporter {
|
|||
return new jest_junit_parser_1.JestJunitParser(options);
|
||||
case 'mocha-json':
|
||||
return new mocha_json_parser_1.MochaJsonParser(options);
|
||||
case 'rspec-json':
|
||||
return new rspec_json_parser_1.RspecJsonParser(options);
|
||||
case 'swift-xunit':
|
||||
return new swift_xunit_parser_1.SwiftXunitParser(options);
|
||||
default:
|
||||
|
|
@ -1403,6 +1406,121 @@ class MochaJsonParser {
|
|||
exports.MochaJsonParser = MochaJsonParser;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 406:
|
||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.RspecJsonParser = void 0;
|
||||
const test_results_1 = __nccwpck_require__(2768);
|
||||
class RspecJsonParser {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
parse(path, content) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const mocha = this.getRspecJson(path, content);
|
||||
const result = this.getTestRunResult(path, mocha);
|
||||
result.sort(true);
|
||||
return Promise.resolve(result);
|
||||
});
|
||||
}
|
||||
getRspecJson(path, content) {
|
||||
try {
|
||||
return JSON.parse(content);
|
||||
}
|
||||
catch (e) {
|
||||
throw new Error(`Invalid JSON at ${path}\n\n${e}`);
|
||||
}
|
||||
}
|
||||
getTestRunResult(resultsPath, rspec) {
|
||||
const suitesMap = {};
|
||||
const getSuite = (test) => {
|
||||
var _a;
|
||||
const path = test.file_path;
|
||||
return (_a = suitesMap[path]) !== null && _a !== void 0 ? _a : (suitesMap[path] = new test_results_1.TestSuiteResult(path, []));
|
||||
};
|
||||
for (const test of rspec.examples) {
|
||||
const suite = getSuite(test);
|
||||
if (test.status === 'failed') {
|
||||
this.processTest(suite, test, 'failed');
|
||||
}
|
||||
else if (test.status === 'passed') {
|
||||
this.processTest(suite, test, 'success');
|
||||
}
|
||||
else if (test.status === 'pending') {
|
||||
this.processTest(suite, test, 'skipped');
|
||||
}
|
||||
}
|
||||
const suites = Object.values(suitesMap);
|
||||
return new test_results_1.TestRunResult(resultsPath, suites, rspec.summary.duration);
|
||||
}
|
||||
processTest(suite, test, result) {
|
||||
var _a;
|
||||
const groupName = test.full_description !== test.description
|
||||
? test.full_description.substr(0, test.full_description.length - test.description.length).trimEnd()
|
||||
: null;
|
||||
let group = suite.groups.find(grp => grp.name === groupName);
|
||||
if (group === undefined) {
|
||||
group = new test_results_1.TestGroupResult(groupName, []);
|
||||
suite.groups.push(group);
|
||||
}
|
||||
const error = this.getTestCaseError(test);
|
||||
const testCase = new test_results_1.TestCaseResult(test.full_description, result, (_a = test.run_time) !== null && _a !== void 0 ? _a : 0, error);
|
||||
group.tests.push(testCase);
|
||||
}
|
||||
getTestCaseError(test) {
|
||||
var _a, _b;
|
||||
const backtrace = (_a = test.exception) === null || _a === void 0 ? void 0 : _a.backtrace;
|
||||
const message = (_b = test.exception) === null || _b === void 0 ? void 0 : _b.message;
|
||||
if (backtrace === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
let path;
|
||||
let line;
|
||||
const details = backtrace.join('\n');
|
||||
const src = this.getExceptionSource(backtrace);
|
||||
if (src) {
|
||||
path = src.path;
|
||||
line = src.line;
|
||||
}
|
||||
return {
|
||||
path,
|
||||
line,
|
||||
message,
|
||||
details
|
||||
};
|
||||
}
|
||||
getExceptionSource(backtrace) {
|
||||
const re = /^(.*?):(\d+):/;
|
||||
for (const str of backtrace) {
|
||||
const match = str.match(re);
|
||||
if (match !== null) {
|
||||
const [_, path, lineStr] = match;
|
||||
if (path.startsWith('./')) {
|
||||
const line = parseInt(lineStr);
|
||||
return { path, line };
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
exports.RspecJsonParser = RspecJsonParser;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5366:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue