testit-js-commons 5.0.6 → 5.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/common/types/common.type.d.ts +4 -0
- package/lib/services/attachments/attachments.service.d.ts +1 -0
- package/lib/services/attachments/attachments.service.js +10 -2
- package/lib/services/testresults/testresults.converter.d.ts +5 -4
- package/lib/services/testresults/testresults.converter.js +8 -0
- package/lib/services/testresults/testresults.service.js +18 -1
- package/lib/strategy/base.strategy.js +1 -0
- package/lib/strategy/zero.strategy.js +1 -1
- package/package.json +1 -1
|
@@ -38,6 +38,10 @@ export interface Metadata {
|
|
|
38
38
|
displayName?: string;
|
|
39
39
|
title?: string;
|
|
40
40
|
description?: string;
|
|
41
|
+
workItemId?: string;
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated Use workItemId with a single globalId instead.
|
|
44
|
+
*/
|
|
41
45
|
workItemsIds?: string[];
|
|
42
46
|
links?: Link[];
|
|
43
47
|
labels?: string[];
|
|
@@ -5,6 +5,7 @@ export declare class AttachmentsService extends BaseService implements IAttachme
|
|
|
5
5
|
protected readonly config: AdapterConfig;
|
|
6
6
|
protected _client: any;
|
|
7
7
|
constructor(config: AdapterConfig);
|
|
8
|
+
private safeAttachmentFileName;
|
|
8
9
|
uploadTextAttachment(content: string | Buffer, filename?: string): Promise<Attachment[]>;
|
|
9
10
|
uploadAttachments(paths: string[]): Promise<Attachment[]>;
|
|
10
11
|
}
|
|
@@ -51,6 +51,7 @@ const AdaptersApi = require("../../adapters-api/dist/index");
|
|
|
51
51
|
const common_1 = require("../../common");
|
|
52
52
|
const buffer_1 = require("buffer");
|
|
53
53
|
const fs = __importStar(require("fs"));
|
|
54
|
+
const path_1 = require("path");
|
|
54
55
|
const logger_1 = __importDefault(require("../../logger"));
|
|
55
56
|
const UPLOAD_RETRY_OPTIONS = { maxAttempts: 5, delayMs: 500, backoff: true };
|
|
56
57
|
/** Minimum HTTP timeout for attachment POST (ms); reduces false timeouts on slow TLS. */
|
|
@@ -66,13 +67,20 @@ class AttachmentsService extends common_1.BaseService {
|
|
|
66
67
|
const t = this._client.apiClient.timeout;
|
|
67
68
|
this._client.apiClient.timeout = Math.max(typeof t === "number" ? t : 60000, UPLOAD_CLIENT_TIMEOUT_MS);
|
|
68
69
|
}
|
|
70
|
+
safeAttachmentFileName(filename) {
|
|
71
|
+
if (!filename) {
|
|
72
|
+
return common_1.Utils.generateFileName();
|
|
73
|
+
}
|
|
74
|
+
const lastSegment = filename.replace(/\\/g, "/").split("/").filter(Boolean).pop();
|
|
75
|
+
return lastSegment || common_1.Utils.generateFileName();
|
|
76
|
+
}
|
|
69
77
|
uploadTextAttachment(content, filename) {
|
|
70
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
79
|
const bufferContent = typeof content === "string" ? buffer_1.Buffer.from(content, "utf-8") : content;
|
|
72
|
-
const fileName =
|
|
80
|
+
const fileName = this.safeAttachmentFileName(filename);
|
|
73
81
|
try {
|
|
74
82
|
const tempDir = common_1.Utils.createTempDir();
|
|
75
|
-
const tempFilePath =
|
|
83
|
+
const tempFilePath = (0, path_1.join)(tempDir, fileName);
|
|
76
84
|
try {
|
|
77
85
|
fs.writeFileSync(tempFilePath, bufferContent);
|
|
78
86
|
logger_1.default.debug("[attachments] upload text", { fileName, bytes: bufferContent.length });
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { AdapterConfig, BaseConverter } from "../../common";
|
|
2
|
+
export declare function isValidTestRunId(value: string | undefined | null): value is string;
|
|
2
3
|
export interface ITestResultsConverter {
|
|
3
|
-
getTestResultsFilterApiModel(): any;
|
|
4
|
-
getTestResultsFilterForRun(): any;
|
|
4
|
+
getTestResultsFilterApiModel(): any | null;
|
|
5
|
+
getTestResultsFilterForRun(): any | null;
|
|
5
6
|
}
|
|
6
7
|
export declare class TestResultsConverter extends BaseConverter implements ITestResultsConverter {
|
|
7
8
|
constructor(config: AdapterConfig);
|
|
8
9
|
private buildRunFilter;
|
|
9
|
-
getTestResultsFilterApiModel(): any;
|
|
10
|
-
getTestResultsFilterForRun(): any;
|
|
10
|
+
getTestResultsFilterApiModel(): any | null;
|
|
11
|
+
getTestResultsFilterForRun(): any | null;
|
|
11
12
|
}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TestResultsConverter = void 0;
|
|
4
|
+
exports.isValidTestRunId = isValidTestRunId;
|
|
4
5
|
const common_1 = require("../../common");
|
|
6
|
+
const TEST_RUN_ID_GUID = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
7
|
+
function isValidTestRunId(value) {
|
|
8
|
+
return typeof value === "string" && TEST_RUN_ID_GUID.test(value);
|
|
9
|
+
}
|
|
5
10
|
class TestResultsConverter extends common_1.BaseConverter {
|
|
6
11
|
constructor(config) {
|
|
7
12
|
super(config);
|
|
8
13
|
}
|
|
9
14
|
buildRunFilter(statusTypes) {
|
|
15
|
+
if (!isValidTestRunId(this.config.testRunId)) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
10
18
|
return {
|
|
11
19
|
testRunIds: [this.config.testRunId],
|
|
12
20
|
configurationIds: [this.config.configurationId],
|
|
@@ -8,12 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.TestResultsService = void 0;
|
|
13
16
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
14
17
|
const AdaptersApi = require("../../adapters-api/dist/index");
|
|
15
18
|
const common_1 = require("../../common");
|
|
16
19
|
const utils_1 = require("../../common/utils");
|
|
20
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
17
21
|
const testresults_handler_1 = require("./testresults.handler");
|
|
18
22
|
const testresults_converter_1 = require("./testresults.converter");
|
|
19
23
|
class TestResultsService extends common_1.BaseService {
|
|
@@ -26,9 +30,15 @@ class TestResultsService extends common_1.BaseService {
|
|
|
26
30
|
}
|
|
27
31
|
getExternalIdsForRun() {
|
|
28
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const model = this._converter.getTestResultsFilterApiModel();
|
|
34
|
+
if (!model) {
|
|
35
|
+
logger_1.default.warn("[testresults] skip search: testRunId is empty or not a GUID", {
|
|
36
|
+
testRunId: this.config.testRunId,
|
|
37
|
+
});
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
29
40
|
var skip = 0;
|
|
30
41
|
var externalIds = [];
|
|
31
|
-
const model = this._converter.getTestResultsFilterApiModel();
|
|
32
42
|
while (true) {
|
|
33
43
|
const testResults = yield this.getTestResults(skip, model);
|
|
34
44
|
if (testResults.length != 0) {
|
|
@@ -46,6 +56,13 @@ class TestResultsService extends common_1.BaseService {
|
|
|
46
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
57
|
var _a, _b;
|
|
48
58
|
const model = this._converter.getTestResultsFilterForRun();
|
|
59
|
+
if (!model) {
|
|
60
|
+
logger_1.default.warn("[testresults] skip search by externalId: testRunId is empty or not a GUID", {
|
|
61
|
+
externalId,
|
|
62
|
+
testRunId: this.config.testRunId,
|
|
63
|
+
});
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
49
66
|
let skip = 0;
|
|
50
67
|
while (true) {
|
|
51
68
|
const batch = yield this.getTestResults(skip, model);
|
|
@@ -7,7 +7,7 @@ class ZeroStrategy extends base_strategy_1.BaseStrategy {
|
|
|
7
7
|
super(config);
|
|
8
8
|
if (!config.testRunId)
|
|
9
9
|
throw new Error("testRunId is required when mode is 0");
|
|
10
|
-
this.testsInRun = this.client.testResults.getExternalIdsForRun();
|
|
10
|
+
this.testsInRun = this.testRunId.then(() => this.client.testResults.getExternalIdsForRun());
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
exports.ZeroStrategy = ZeroStrategy;
|