Skip to content

Commit cd6b5ab

Browse files
committed
notificaciones-slack
1 parent 750c9b8 commit cd6b5ab

File tree

5 files changed

+358
-2
lines changed

5 files changed

+358
-2
lines changed

.github/workflows/playwright.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ jobs:
3636
env:
3737
BASE_URL: ${{ secrets.BASE_URL }}
3838
API_TOKEN: ${{ secrets.API_TOKEN }}
39+
40+
- name: 📢 Send Slack notification
41+
if: always() # se ejecuta aunque los tests fallen
42+
run: node notify-slack.js
43+
env:
44+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
3945

4046
- name: 🚀 Deploy to GitHub Pages
4147
if: always()

notify-slack.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// notify-slack.js
2+
require("dotenv").config();
3+
const fs = require("fs");
4+
const axios = require("axios");
5+
6+
const WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL;
7+
const RESULTS_FILE = "test-results/results.json";
8+
9+
(async () => {
10+
try {
11+
if (!WEBHOOK_URL) {
12+
console.error("❌ Falta SLACK_WEBHOOK_URL en el archivo .env");
13+
process.exit(1);
14+
}
15+
16+
if (!fs.existsSync(RESULTS_FILE)) {
17+
console.error(
18+
`❌ No se encontró el archivo de resultados: ${RESULTS_FILE}`
19+
);
20+
process.exit(1);
21+
}
22+
23+
const results = JSON.parse(fs.readFileSync(RESULTS_FILE, "utf-8"));
24+
25+
// Extrae resumen general
26+
const total = results.stats?.total || 0;
27+
const passed = results.stats?.expected || 0;
28+
const failed = results.stats?.unexpected || 0;
29+
const skipped = results.stats?.skipped || 0;
30+
const duration = results.stats?.duration
31+
? (results.stats.duration / 1000).toFixed(1)
32+
: "N/A";
33+
34+
// Determina estado general
35+
const statusEmoji = failed > 0 ? "❌" : "✅";
36+
const statusText = failed > 0 ? "Con fallos" : "Todo correcto";
37+
38+
const message = {
39+
text: `${statusEmoji} *Resultados de pruebas Playwright*`,
40+
attachments: [
41+
{
42+
color: failed > 0 ? "#FF4D4F" : "#36A64F",
43+
fields: [
44+
{ title: "Estado general", value: statusText, short: true },
45+
{ title: "Total de tests", value: `${total}`, short: true },
46+
{ title: "✔️ Pasados", value: `${passed}`, short: true },
47+
{ title: "❌ Fallados", value: `${failed}`, short: true },
48+
{ title: "⏭️ Omitidos", value: `${skipped}`, short: true },
49+
{ title: "🕐 Duración", value: `${duration}s`, short: true },
50+
],
51+
footer: "Playwright QA Bot",
52+
ts: Math.floor(Date.now() / 1000),
53+
},
54+
],
55+
};
56+
57+
await axios.post(WEBHOOK_URL, message);
58+
59+
console.log("✅ Resultados enviados a Slack correctamente");
60+
} catch (error) {
61+
console.error("⚠️ Error al enviar resultados a Slack:", error.message);
62+
process.exit(1);
63+
}
64+
})();

package-lock.json

Lines changed: 280 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)