engine-dependency 1.0.0
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/dist/cjs/index.cjs +9 -0
- package/dist/cjs/services/base.service.cjs +25 -0
- package/dist/cjs/services/test-information.service.cjs +80 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/services/base.service.js +21 -0
- package/dist/esm/services/test-information.service.js +78 -0
- package/package.json +47 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var services_base_service = require('./services/base.service.cjs');
|
|
4
|
+
var services_testInformation_service = require('./services/test-information.service.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
exports.BaseService = services_base_service.default;
|
|
9
|
+
exports.TestInformationService = services_testInformation_service.TestInformationService;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
class BaseService {
|
|
6
|
+
async sendPOSTRequest(url, body, headers = {}) {
|
|
7
|
+
const response = await fetch(url, {
|
|
8
|
+
method: 'POST',
|
|
9
|
+
headers: {
|
|
10
|
+
'Content-Type': 'application/json',
|
|
11
|
+
...headers
|
|
12
|
+
},
|
|
13
|
+
body: JSON.stringify(body)
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const data = await response.json();
|
|
21
|
+
return { data, status: response.status };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.default = BaseService;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var services_base_service = require('./base.service.cjs');
|
|
4
|
+
|
|
5
|
+
class TestInformationService extends services_base_service.default {
|
|
6
|
+
constructor(config = {}) {
|
|
7
|
+
super();
|
|
8
|
+
this.baseUrl = config.baseUrl || process.env.DATA_ENGINE_BASE_URL;
|
|
9
|
+
this.tokenEndpoint = config.tokenEndpoint || process.env.DATA_ENGINE_GENERATE_TOKEN;
|
|
10
|
+
this.testResultsEndpoint = config.testResultsEndpoint || '/api/test-results';
|
|
11
|
+
this.serviceAccount = config.serviceAccount || process.env.DATA_ENGINE_SERVICE_ACCOUNT;
|
|
12
|
+
this.servicePassword = config.servicePassword || process.env.DATA_ENGINE_SERVICE_PASSWORD;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async generateToken() {
|
|
16
|
+
try {
|
|
17
|
+
const response = await this.sendPOSTRequest(`${this.baseUrl}${this.tokenEndpoint}`, {
|
|
18
|
+
email: this.serviceAccount,
|
|
19
|
+
password: this.servicePassword
|
|
20
|
+
});
|
|
21
|
+
return response.data.token;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.log(`Error generando token para test results: ${error?.message || error}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
buildTestPayload(testInfo) {
|
|
28
|
+
return {
|
|
29
|
+
testTitle: testInfo.titlePath?.join(' > ') || testInfo.title,
|
|
30
|
+
testStatus: testInfo.status,
|
|
31
|
+
duration: testInfo.duration,
|
|
32
|
+
testFile: testInfo.file,
|
|
33
|
+
testProject: testInfo.project?.name || null,
|
|
34
|
+
retries: testInfo.retries ?? 0,
|
|
35
|
+
retry: testInfo.retry ?? 0,
|
|
36
|
+
tags: testInfo.tags || [],
|
|
37
|
+
environment: process.env.ENV,
|
|
38
|
+
testInfo: {
|
|
39
|
+
title: testInfo.title,
|
|
40
|
+
expectedStatus: testInfo.expectedStatus,
|
|
41
|
+
annotations: testInfo.annotations || [],
|
|
42
|
+
timeout: testInfo.timeout,
|
|
43
|
+
errors: testInfo.errors || []
|
|
44
|
+
},
|
|
45
|
+
pipelineId: process.env.BUILD_BUILDID || null,
|
|
46
|
+
commitSha: process.env.BUILD_SOURCEVERSION || null,
|
|
47
|
+
branch: process.env.BUILD_SOURCEBRANCH || null,
|
|
48
|
+
runUrl: process.env.BUILD_BUILDID
|
|
49
|
+
? `${process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI}${process.env.SYSTEM_TEAMPROJECT}/_build/results?buildId=${process.env.BUILD_BUILDID}`
|
|
50
|
+
: null,
|
|
51
|
+
provider: process.env.BUILD_BUILDID ? 'azure-devops' : null
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async sendTestResult(testInfo) {
|
|
56
|
+
if (!process.env.CI) return;
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const token = await this.generateToken();
|
|
60
|
+
if (!token) {
|
|
61
|
+
console.log('No se pudo obtener el token, omitiendo envio de resultado de test');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const payload = this.buildTestPayload(testInfo);
|
|
66
|
+
const response = await this.sendPOSTRequest(
|
|
67
|
+
`${this.baseUrl}${this.testResultsEndpoint}`,
|
|
68
|
+
payload,
|
|
69
|
+
{ Authorization: `Bearer ${token}` }
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
console.log(`Resultado de test enviado: ${testInfo.title} - ${testInfo.status}`);
|
|
73
|
+
return response?.data;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.log(`Error enviando resultado de test: ${error?.message || error}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
exports.TestInformationService = TestInformationService;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class BaseService {
|
|
2
|
+
async sendPOSTRequest(url, body, headers = {}) {
|
|
3
|
+
const response = await fetch(url, {
|
|
4
|
+
method: 'POST',
|
|
5
|
+
headers: {
|
|
6
|
+
'Content-Type': 'application/json',
|
|
7
|
+
...headers
|
|
8
|
+
},
|
|
9
|
+
body: JSON.stringify(body)
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
if (!response.ok) {
|
|
13
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const data = await response.json();
|
|
17
|
+
return { data, status: response.status };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { BaseService as default };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import BaseService from './base.service.js';
|
|
2
|
+
|
|
3
|
+
class TestInformationService extends BaseService {
|
|
4
|
+
constructor(config = {}) {
|
|
5
|
+
super();
|
|
6
|
+
this.baseUrl = config.baseUrl || process.env.DATA_ENGINE_BASE_URL;
|
|
7
|
+
this.tokenEndpoint = config.tokenEndpoint || process.env.DATA_ENGINE_GENERATE_TOKEN;
|
|
8
|
+
this.testResultsEndpoint = config.testResultsEndpoint || '/api/test-results';
|
|
9
|
+
this.serviceAccount = config.serviceAccount || process.env.DATA_ENGINE_SERVICE_ACCOUNT;
|
|
10
|
+
this.servicePassword = config.servicePassword || process.env.DATA_ENGINE_SERVICE_PASSWORD;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async generateToken() {
|
|
14
|
+
try {
|
|
15
|
+
const response = await this.sendPOSTRequest(`${this.baseUrl}${this.tokenEndpoint}`, {
|
|
16
|
+
email: this.serviceAccount,
|
|
17
|
+
password: this.servicePassword
|
|
18
|
+
});
|
|
19
|
+
return response.data.token;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.log(`Error generando token para test results: ${error?.message || error}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
buildTestPayload(testInfo) {
|
|
26
|
+
return {
|
|
27
|
+
testTitle: testInfo.titlePath?.join(' > ') || testInfo.title,
|
|
28
|
+
testStatus: testInfo.status,
|
|
29
|
+
duration: testInfo.duration,
|
|
30
|
+
testFile: testInfo.file,
|
|
31
|
+
testProject: testInfo.project?.name || null,
|
|
32
|
+
retries: testInfo.retries ?? 0,
|
|
33
|
+
retry: testInfo.retry ?? 0,
|
|
34
|
+
tags: testInfo.tags || [],
|
|
35
|
+
environment: process.env.ENV,
|
|
36
|
+
testInfo: {
|
|
37
|
+
title: testInfo.title,
|
|
38
|
+
expectedStatus: testInfo.expectedStatus,
|
|
39
|
+
annotations: testInfo.annotations || [],
|
|
40
|
+
timeout: testInfo.timeout,
|
|
41
|
+
errors: testInfo.errors || []
|
|
42
|
+
},
|
|
43
|
+
pipelineId: process.env.BUILD_BUILDID || null,
|
|
44
|
+
commitSha: process.env.BUILD_SOURCEVERSION || null,
|
|
45
|
+
branch: process.env.BUILD_SOURCEBRANCH || null,
|
|
46
|
+
runUrl: process.env.BUILD_BUILDID
|
|
47
|
+
? `${process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI}${process.env.SYSTEM_TEAMPROJECT}/_build/results?buildId=${process.env.BUILD_BUILDID}`
|
|
48
|
+
: null,
|
|
49
|
+
provider: process.env.BUILD_BUILDID ? 'azure-devops' : null
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async sendTestResult(testInfo) {
|
|
54
|
+
if (!process.env.CI) return;
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
const token = await this.generateToken();
|
|
58
|
+
if (!token) {
|
|
59
|
+
console.log('No se pudo obtener el token, omitiendo envio de resultado de test');
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const payload = this.buildTestPayload(testInfo);
|
|
64
|
+
const response = await this.sendPOSTRequest(
|
|
65
|
+
`${this.baseUrl}${this.testResultsEndpoint}`,
|
|
66
|
+
payload,
|
|
67
|
+
{ Authorization: `Bearer ${token}` }
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
console.log(`Resultado de test enviado: ${testInfo.title} - ${testInfo.status}`);
|
|
71
|
+
return response?.data;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.log(`Error enviando resultado de test: ${error?.message || error}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { TestInformationService };
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "engine-dependency",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Dependencia centralizada para envio de datos via API al servicio Data Engine",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/cjs/index.cjs",
|
|
7
|
+
"module": "dist/esm/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/esm/index.js",
|
|
11
|
+
"require": "./dist/cjs/index.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "rollup -c",
|
|
19
|
+
"clean": "node -e \"const fs=require('fs');fs.rmSync('dist',{recursive:true,force:true})\"",
|
|
20
|
+
"prebuild": "npm run clean",
|
|
21
|
+
"lint": "eslint src/",
|
|
22
|
+
"lint:fix": "eslint src/ --fix",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:watch": "vitest",
|
|
25
|
+
"test:coverage": "vitest run --coverage",
|
|
26
|
+
"validate": "npm run lint && npm run test && npm run build",
|
|
27
|
+
"prepublishOnly": "npm run validate",
|
|
28
|
+
"example": "node examples/send-test-result.js"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"data-engine",
|
|
32
|
+
"test-results",
|
|
33
|
+
"api-client"
|
|
34
|
+
],
|
|
35
|
+
"license": "ISC",
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18.0.0"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"dotenv": "^16.4.5"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"eslint": "^10.0.0",
|
|
44
|
+
"rollup": "^4.57.1",
|
|
45
|
+
"vitest": "^4.0.18"
|
|
46
|
+
}
|
|
47
|
+
}
|