New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jest-qase-reporter

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-qase-reporter - npm Package Compare versions

Comparing version

to
1.3.0-alpha.0

7

dist/index.d.ts
import { Reporter, Test, TestResult } from '@jest/reporters';
interface QaseOptions {
apiToken: string;
basePath?: string;
projectCode: string;

@@ -17,2 +18,3 @@ runId?: string;

private publishedResultsCount;
private preparedTestCases;
constructor(_: Record<string, unknown>, _options: QaseOptions);

@@ -27,7 +29,10 @@ onRunStart(): Promise<void>;

private logTestItem;
private createPreparedForPublishTestsArray;
private publishBulkTestResult;
private checkProject;
private createRunObject;
private createRun;
private checkRun;
private publishCaseResult;
private createResultCasesArray;
}
export = QaseReporter;

221

dist/index.js

@@ -6,2 +6,13 @@ "use strict";

};
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -53,3 +64,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
var models_1 = require("qaseio/dist/src/models");
var src_1 = require("qaseio/dist/src");
var qaseio_1 = require("qaseio");

@@ -61,2 +72,4 @@ var chalk_1 = __importDefault(require("chalk"));

Envs["apiToken"] = "QASE_API_TOKEN";
Envs["basePath"] = "QASE_API_BASE_URL";
Envs["projectCode"] = "QASE_PROJECT_CODE";
Envs["runId"] = "QASE_RUN_ID";

@@ -67,9 +80,10 @@ Envs["runName"] = "QASE_RUN_NAME";

Envs["environmentId"] = "QASE_ENVIRONMENT_ID";
Envs["rootSuite"] = "QASE_ROOT_SUITE_TITLE";
})(Envs || (Envs = {}));
var Statuses = {
passed: models_1.ResultStatus.PASSED,
failed: models_1.ResultStatus.FAILED,
skipped: models_1.ResultStatus.SKIPPED,
pending: models_1.ResultStatus.SKIPPED,
disabled: models_1.ResultStatus.BLOCKED,
passed: src_1.ResultCreateStatusEnum.PASSED,
failed: src_1.ResultCreateStatusEnum.FAILED,
skipped: src_1.ResultCreateStatusEnum.SKIPPED,
pending: src_1.ResultCreateStatusEnum.SKIPPED,
disabled: src_1.ResultCreateStatusEnum.BLOCKED,
};

@@ -82,5 +96,7 @@ var alwaysUndefined = function () { return undefined; };

this.options = _options;
this.options.projectCode = _options.projectCode || this.getEnv(Envs.projectCode) || '';
this.options.runComplete = !!this.getEnv(Envs.runComplete) || this.options.runComplete;
this.api = new qaseio_1.QaseApi(this.getEnv(Envs.apiToken) || this.options.apiToken || '');
this.api = new qaseio_1.QaseApi(this.getEnv(Envs.apiToken) || this.options.apiToken || '', this.getEnv(Envs.basePath) || this.options.basePath);
this.log(chalk_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["{yellow Current PID: ", "}"], ["{yellow Current PID: ", "}"])), process.pid));
this.preparedTestCases = [];
if (!this.getEnv(Envs.report)) {

@@ -124,4 +140,5 @@ this.log(chalk_1.default(templateObject_2 || (templateObject_2 = __makeTemplateObject(["{yellow QASE_REPORT env variable is not set. Reporting to qase.io is disabled.}"], ["{yellow QASE_REPORT env variable is not set. Reporting to qase.io is disabled.}"]))));

return [2 /*return*/, this.createRun(this.getEnv(Envs.runName), this.getEnv(Envs.runDescription), function (created) {
var _a;
if (created) {
_this.runId = created.id;
_this.runId = (_a = created.result) === null || _a === void 0 ? void 0 : _a.id;
process.env.QASE_RUN_ID = _this.runId.toString();

@@ -144,8 +161,14 @@ _this.log(chalk_1.default(templateObject_7 || (templateObject_7 = __makeTemplateObject(["{green Using run ", " to publish test results}"], ["{green Using run ", " to publish test results}"])), _this.runId));

return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
if (this.isDisabled) {
return [2 /*return*/];
switch (_a.label) {
case 0:
if (this.isDisabled) {
return [2 /*return*/];
}
this.preparedTestCases = this.createPreparedForPublishTestsArray(testResult.testResults);
return [4 /*yield*/, this.publishBulkTestResult().then(alwaysUndefined)];
case 1:
_a.sent();
return [2 /*return*/];
}
return [2 /*return*/, Promise.all(testResult.testResults.map(function (value) { return _this.publishCaseResult(value); })).then(alwaysUndefined)];
});

@@ -173,6 +196,4 @@ });

_a.trys.push([1, 3, , 4]);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return [4 /*yield*/, this.api.runs.complete(this.options.projectCode, this.runId)];
return [4 /*yield*/, this.api.runs.completeRun(this.options.projectCode, Number(this.runId))];
case 2:
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
_a.sent();

@@ -225,14 +246,79 @@ this.log(chalk_1.default(templateObject_9 || (templateObject_9 = __makeTemplateObject(["{green Run ", " completed}"], ["{green Run ", " completed}"])), this.runId));

};
QaseReporter.prototype.checkProject = function (projectCode, cb) {
QaseReporter.prototype.createPreparedForPublishTestsArray = function (testResults) {
var _this = this;
return this.api.projects.exists(projectCode)
.then(cb)
.catch(function (err) {
_this.log(err);
_this.isDisabled = true;
var transformedMap = testResults.map(function (result) {
_this.logTestItem(result);
var item = {
path: result.ancestorTitles.join('\t'),
result: result.status,
duration: result.duration,
status: result.status,
title: result.title,
failureMessages: result.failureMessages,
};
var caseIds = _this.getCaseIds(result);
if (caseIds) {
item.caseIds = caseIds;
}
return item;
});
return transformedMap;
};
QaseReporter.prototype.publishBulkTestResult = function () {
return __awaiter(this, void 0, void 0, function () {
var body, res, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
body = {
results: this.createResultCasesArray(),
};
return [4 /*yield*/, this.api.results.createResultBulk(this.options.projectCode, Number(this.runId), body)];
case 1:
res = _a.sent();
if (res.status === 200) {
this.publishedResultsCount++;
}
return [3 /*break*/, 3];
case 2:
error_1 = _a.sent();
this.log(JSON.stringify(error_1));
return [3 /*break*/, 3];
case 3: return [2 /*return*/];
}
});
});
};
QaseReporter.prototype.checkProject = function (projectCode, cb) {
var _a;
return __awaiter(this, void 0, void 0, function () {
var resp, err_2;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 3, , 4]);
return [4 /*yield*/, this.api.projects.getProject(projectCode)];
case 1:
resp = _b.sent();
return [4 /*yield*/, cb(Boolean((_a = resp.data.result) === null || _a === void 0 ? void 0 : _a.code))];
case 2:
_b.sent();
return [3 /*break*/, 4];
case 3:
err_2 = _b.sent();
this.log(err_2);
this.isDisabled = true;
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
});
};
QaseReporter.prototype.createRunObject = function (name, cases, args) {
return __assign({ title: name, cases: cases }, args);
};
QaseReporter.prototype.createRun = function (name, description, cb) {
return __awaiter(this, void 0, void 0, function () {
var environmentId, res, err_2;
var environmentId, runObject, res, err_3;
return __generator(this, function (_a) {

@@ -243,7 +329,8 @@ switch (_a.label) {

environmentId = Number.parseInt(this.getEnv(Envs.environmentId), 10) || this.options.environmentId;
return [4 /*yield*/, this.api.runs.create(this.options.projectCode, new models_1.RunCreate(name || "Automated run " + new Date().toISOString(), [], {
description: description || 'Jest automated run',
environment_id: environmentId,
is_autotest: true,
}))];
runObject = this.createRunObject(name || "Automated run " + new Date().toISOString(), [], {
description: description || 'Jest automated run',
environment_id: environmentId,
is_autotest: true,
});
return [4 /*yield*/, this.api.runs.createRun(this.options.projectCode, runObject)];
case 1:

@@ -254,4 +341,4 @@ res = _a.sent();

case 2:
err_2 = _a.sent();
this.log("Error on creating run " + err_2);
err_3 = _a.sent();
this.log("Error on creating run " + err_3);
this.isDisabled = true;

@@ -272,4 +359,8 @@ return [3 /*break*/, 3];

}
return [2 /*return*/, this.api.runs.exists(this.options.projectCode, runId)
.then(cb)
return [2 /*return*/, this.api.runs.getRun(this.options.projectCode, Number(runId))
.then(function (resp) {
var _a, _b;
_this.log("Get run result on checking run " + ((_a = resp.data.result) === null || _a === void 0 ? void 0 : _a.id));
cb(Boolean((_b = resp.data.result) === null || _b === void 0 ? void 0 : _b.id));
})
.catch(function (err) {

@@ -282,46 +373,26 @@ _this.log("Error on checking run " + err);

};
QaseReporter.prototype.publishCaseResult = function (test) {
return __awaiter(this, void 0, void 0, function () {
var caseIds;
var _this = this;
return __generator(this, function (_a) {
this.logTestItem(test);
caseIds = this.getCaseIds(test);
if (caseIds.length === 0) {
// TODO: autocreate case for result
return [2 /*return*/];
}
return [2 /*return*/, Promise.all(caseIds.map(function (caseId) { return __awaiter(_this, void 0, void 0, function () {
var add, res, err_3;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
add = caseIds.length > 1 ? chalk_1.default(templateObject_16 || (templateObject_16 = __makeTemplateObject([" {white For case ", "}"], [" {white For case ", "}"])), caseId) : '';
this.log(chalk_1.default(templateObject_17 || (templateObject_17 = __makeTemplateObject(["{gray Start publishing: ", "}", ""], ["{gray Start publishing: ", "}", ""])), test.title, add));
test.failureMessages = test.failureMessages.map(function (value) { return value.replace(/\u001b\[.*?m/g, ''); });
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, this.api.results.create(this.options.projectCode,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.runId, new models_1.ResultCreate(caseId, Statuses[test.status], {
// eslint-disable-next-line camelcase, @typescript-eslint/no-non-null-assertion
time_ms: test.duration,
stacktrace: test.failureMessages.join('\n'),
comment: test.failureMessages.length > 0 ? test.failureMessages.map(function (value) { return value.split('\n')[0]; }).join('\n') : undefined,
}))];
case 2:
res = _a.sent();
this.publishedResultsCount++;
this.log(chalk_1.default(templateObject_18 || (templateObject_18 = __makeTemplateObject(["{gray Result published: ", " ", "}", ""], ["{gray Result published: ", " ", "}", ""])), test.title, res.data.hash, add));
return [3 /*break*/, 4];
case 3:
err_3 = _a.sent();
this.log(err_3);
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
}); })).then(alwaysUndefined)];
QaseReporter.prototype.createResultCasesArray = function () {
return this.preparedTestCases.map(function (elem) {
var _a;
var failureMessages = elem.failureMessages.map(function (value) {
return value.replace(/\u001b\[.*?m/g, '');
});
var caseObject = {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
status: Statuses[elem.status] || Statuses.failed,
time_ms: Number(elem.duration),
stacktrace: failureMessages.join('\n'),
comment: failureMessages.length > 0 ? failureMessages.map(function (value) { return value.split('\n')[0]; }).join('\n') : undefined,
};
// Verifies that the user defined the ID through the use of the 'qase' wrapper;
if (elem.caseIds && ((_a = elem.caseIds) === null || _a === void 0 ? void 0 : _a.length) > 0) {
caseObject.case_id = elem.caseIds[0];
}
else {
caseObject.case = {
title: elem.title,
suite_title: elem.path,
};
}
return caseObject;
});

@@ -331,4 +402,4 @@ };

}());
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15, templateObject_16, templateObject_17, templateObject_18;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15;
module.exports = QaseReporter;
//# sourceMappingURL=index.js.map

@@ -5,27 +5,72 @@ const { add, mul, sub, div } = require('./arith');

describe("help", () => {
test('2 + 3 = 5 without qase wrapper', () => {
expect(add(2, 3)).toBe(5);
});
test.skip(qase(1, '2 + 3 = 5'), () => {
test.skip('2 + 3 = 5 skipped', () => {
expect(add(2, 3)).toBe(5);
});
test(qase([2, 3], '3 * 4 = 12'), async () => {
await new Promise((r) => setTimeout(r, 2000));
expect(mul(3, 4)).toBe(12);
test('2 + 3 = 6', () => {
expect(add(2, 3)).toBe(6);
});
describe("me", () => {
describe('Suite for the some nested cases', () => {
test('Nested 1', () => {
expect(add(2, 3)).toBe(5);
});
test(qase([5, 6], '5 - 6 = -1'), () => {
expect(sub(5, 6)).toBe(-2);
test.skip('2 + 3 = 5 skipped', () => {
expect(add(2, 3)).toBe(5);
});
test('5 - 6 = -1', () => {
expect(sub(5, 6)).toBe(-1);
test('2 + 3 = 6 Wrong case', () => {
expect(add(2, 3)).toBe(6);
});
test('Async test case', async () => {
await new Promise((r) => setTimeout(r, 2000));
expect(mul(3, 4)).toBe(12);
});
})
test('8 / 4 = 2', () => {
expect(div(8, 4)).toBe(2);
});
describe("help", () => {
for (let i = 0; i <= 100; i++) {
test(`${i} + ${i} autogenerated case`, () => {
expect(add(i, i)).toBe(i * 2);
});
}
test('2 + 3 = 5 without qase wrapper', () => {
expect(add(2, 3)).toBe(5);
});
test.skip('2 + 3 = 5 skipped', () => {
expect(add(2, 3)).toBe(5);
});
test('2 + 3 = 6', () => {
expect(add(2, 3)).toBe(6);
});
describe('Suite for the some nested cases', () => {
test('Nested 1', () => {
expect(add(2, 3)).toBe(5);
});
test.skip('2 + 3 = 5 skipped', () => {
expect(add(2, 3)).toBe(5);
});
test('2 + 3 = 6 Wrong case', () => {
expect(add(2, 3)).toBe(6);
});
test('Async test case', async () => {
await new Promise((r) => setTimeout(r, 2000));
expect(mul(3, 4)).toBe(12);
});
})
})
})
{
"name": "jest-qase-reporter",
"version": "v1.2.3",
"version": "v1.3.0-alpha.0",
"description": "Qase TMS Jest Reporter",

@@ -33,3 +33,3 @@ "main": "./dist/index.js",

"dependencies": {
"qaseio": "^1.4.0"
"qaseio": "^2.0.0-alpha.0"
},

@@ -36,0 +36,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display