engine-dependency 1.0.0 → 1.0.1
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/README.md +188 -0
- package/package.json +3 -5
package/README.md
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# engine-dependency
|
|
2
|
+
|
|
3
|
+
Dependencia centralizada para el envio de resultados de tests y datos via API al servicio Data Engine.
|
|
4
|
+
|
|
5
|
+
## Requisitos
|
|
6
|
+
|
|
7
|
+
- Node.js >= 18.0.0
|
|
8
|
+
|
|
9
|
+
## Instalacion
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install engine-dependency
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Configuracion
|
|
16
|
+
|
|
17
|
+
Crea un archivo `.env` en la raiz de tu proyecto con las siguientes variables:
|
|
18
|
+
|
|
19
|
+
```env
|
|
20
|
+
DATA_ENGINE_BASE_URL=https://tu-servicio.com
|
|
21
|
+
DATA_ENGINE_GENERATE_TOKEN=/api/auth/login
|
|
22
|
+
DATA_ENGINE_SERVICE_ACCOUNT=cuenta@servicio.com
|
|
23
|
+
DATA_ENGINE_SERVICE_PASSWORD=password
|
|
24
|
+
ENV=qa
|
|
25
|
+
CI=true
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Consulta `.env.example` para referencia.
|
|
29
|
+
|
|
30
|
+
## Uso
|
|
31
|
+
|
|
32
|
+
### ESM (import)
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
import { TestInformationService } from 'engine-dependency';
|
|
36
|
+
|
|
37
|
+
const service = new TestInformationService();
|
|
38
|
+
await service.sendTestResult(testInfo);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### CommonJS (require)
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
const { TestInformationService } = require('engine-dependency');
|
|
45
|
+
|
|
46
|
+
const service = new TestInformationService();
|
|
47
|
+
await service.sendTestResult(testInfo);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Configuracion por parametro
|
|
51
|
+
|
|
52
|
+
En lugar de depender de variables de entorno, puedes pasar la configuracion directamente al constructor:
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
const service = new TestInformationService({
|
|
56
|
+
baseUrl: 'https://tu-servicio.com',
|
|
57
|
+
tokenEndpoint: '/api/auth/login',
|
|
58
|
+
testResultsEndpoint: '/api/test-results',
|
|
59
|
+
serviceAccount: 'cuenta@servicio.com',
|
|
60
|
+
servicePassword: 'password'
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Enviar resultado de test
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
const testInfo = {
|
|
68
|
+
title: 'Login exitoso con credenciales validas',
|
|
69
|
+
titlePath: ['Auth', 'Login', 'Login exitoso con credenciales validas'],
|
|
70
|
+
status: 'passed',
|
|
71
|
+
duration: 3500,
|
|
72
|
+
file: 'tests/auth/login.spec.js',
|
|
73
|
+
project: { name: 'e2e-chrome' },
|
|
74
|
+
retries: 0,
|
|
75
|
+
retry: 0,
|
|
76
|
+
tags: ['@smoke', '@auth'],
|
|
77
|
+
expectedStatus: 'passed',
|
|
78
|
+
annotations: [],
|
|
79
|
+
timeout: 30000,
|
|
80
|
+
errors: []
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const result = await service.sendTestResult(testInfo);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
> `sendTestResult` solo ejecuta el envio cuando la variable de entorno `CI` esta definida. Esto evita envios accidentales en entornos locales.
|
|
87
|
+
|
|
88
|
+
## API
|
|
89
|
+
|
|
90
|
+
### `BaseService`
|
|
91
|
+
|
|
92
|
+
Clase base que provee metodos HTTP reutilizables.
|
|
93
|
+
|
|
94
|
+
| Metodo | Parametros | Retorno | Descripcion |
|
|
95
|
+
|---|---|---|---|
|
|
96
|
+
| `sendPOSTRequest(url, body, headers?)` | `url`: string, `body`: object, `headers`: object (opcional) | `{ data, status }` | Envia una peticion POST con JSON |
|
|
97
|
+
|
|
98
|
+
### `TestInformationService`
|
|
99
|
+
|
|
100
|
+
Extiende `BaseService`. Gestiona autenticacion y envio de resultados de tests.
|
|
101
|
+
|
|
102
|
+
| Metodo | Parametros | Retorno | Descripcion |
|
|
103
|
+
|---|---|---|---|
|
|
104
|
+
| `generateToken()` | - | `string \| undefined` | Obtiene un token JWT del servicio |
|
|
105
|
+
| `buildTestPayload(testInfo)` | `testInfo`: object | `object` | Construye el payload para el API |
|
|
106
|
+
| `sendTestResult(testInfo)` | `testInfo`: object | `object \| undefined` | Autentica y envia el resultado del test |
|
|
107
|
+
|
|
108
|
+
### Payload enviado
|
|
109
|
+
|
|
110
|
+
`sendTestResult` construye y envia el siguiente payload al endpoint `/api/test-results`:
|
|
111
|
+
|
|
112
|
+
| Campo | Origen |
|
|
113
|
+
|---|---|
|
|
114
|
+
| `testTitle` | `titlePath` concatenado o `title` |
|
|
115
|
+
| `testStatus` | `status` del test |
|
|
116
|
+
| `duration` | Duracion en ms |
|
|
117
|
+
| `testFile` | Ruta del archivo de test |
|
|
118
|
+
| `testProject` | Nombre del proyecto |
|
|
119
|
+
| `retries` / `retry` | Intentos configurados y actual |
|
|
120
|
+
| `tags` | Tags del test |
|
|
121
|
+
| `environment` | Variable de entorno `ENV` |
|
|
122
|
+
| `testInfo` | Objeto con `title`, `expectedStatus`, `annotations`, `timeout`, `errors` |
|
|
123
|
+
| `pipelineId` | `BUILD_BUILDID` (Azure DevOps) |
|
|
124
|
+
| `commitSha` | `BUILD_SOURCEVERSION` |
|
|
125
|
+
| `branch` | `BUILD_SOURCEBRANCH` |
|
|
126
|
+
| `runUrl` | URL del build en Azure DevOps |
|
|
127
|
+
| `provider` | `azure-devops` si ejecuta en pipeline |
|
|
128
|
+
|
|
129
|
+
## Scripts
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
npm run build # Genera dist/ con ESM y CJS
|
|
133
|
+
npm run clean # Elimina dist/
|
|
134
|
+
npm run lint # Ejecuta ESLint sobre src/
|
|
135
|
+
npm run lint:fix # Corrige errores de lint automaticamente
|
|
136
|
+
npm test # Ejecuta tests unitarios
|
|
137
|
+
npm run test:watch # Tests en modo watch
|
|
138
|
+
npm run test:coverage # Tests con reporte de cobertura
|
|
139
|
+
npm run validate # lint + test + build (pipeline completo)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Estructura del proyecto
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
engine-dependency/
|
|
146
|
+
├── src/
|
|
147
|
+
│ ├── index.js # Entry point
|
|
148
|
+
│ └── services/
|
|
149
|
+
│ ├── base.service.js # Servicio HTTP base (fetch nativo)
|
|
150
|
+
│ └── test-information.service.js # Servicio de resultados de tests
|
|
151
|
+
├── tests/
|
|
152
|
+
│ ├── base.service.test.js
|
|
153
|
+
│ └── test-information.service.test.js
|
|
154
|
+
├── dist/ # Generado por build
|
|
155
|
+
│ ├── esm/ # Modulos ES
|
|
156
|
+
│ └── cjs/ # CommonJS
|
|
157
|
+
├── examples/
|
|
158
|
+
│ └── send-test-result.js
|
|
159
|
+
├── .env.example
|
|
160
|
+
├── rollup.config.js
|
|
161
|
+
├── eslint.config.js
|
|
162
|
+
└── package.json
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Extender con nuevos servicios
|
|
166
|
+
|
|
167
|
+
1. Crea un nuevo archivo en `src/services/` que extienda `BaseService`.
|
|
168
|
+
2. Exportalo desde `src/index.js`.
|
|
169
|
+
3. Ejecuta `npm run build`.
|
|
170
|
+
|
|
171
|
+
```javascript
|
|
172
|
+
// src/services/mi-servicio.service.js
|
|
173
|
+
import BaseService from './base.service.js';
|
|
174
|
+
|
|
175
|
+
export class MiServicio extends BaseService {
|
|
176
|
+
async enviarDatos(payload) {
|
|
177
|
+
const response = await this.sendPOSTRequest('https://api.com/datos', payload);
|
|
178
|
+
return response.data;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
```javascript
|
|
184
|
+
// src/index.js
|
|
185
|
+
export { default as BaseService } from './services/base.service.js';
|
|
186
|
+
export { TestInformationService } from './services/test-information.service.js';
|
|
187
|
+
export { MiServicio } from './services/mi-servicio.service.js';
|
|
188
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "engine-dependency",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Dependencia centralizada para envio de datos via API al servicio Data Engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/cjs/index.cjs",
|
|
@@ -36,12 +36,10 @@
|
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=18.0.0"
|
|
38
38
|
},
|
|
39
|
-
"dependencies": {
|
|
40
|
-
"dotenv": "^16.4.5"
|
|
41
|
-
},
|
|
42
39
|
"devDependencies": {
|
|
40
|
+
"dotenv": "^16.4.5",
|
|
43
41
|
"eslint": "^10.0.0",
|
|
44
42
|
"rollup": "^4.57.1",
|
|
45
43
|
"vitest": "^4.0.18"
|
|
46
44
|
}
|
|
47
|
-
}
|
|
45
|
+
}
|