Skip to content

Commit bbe6de0

Browse files
committed
New env switch NOTIFY_ON_SUCCESS to reverse notification logic
Change-Id: Ib236bf91f0ac43abfc2da720783a01dd86635c06
1 parent a10add3 commit bbe6de0

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ KORAP_URL="http://localhost:64543" KORAP_USERNAME="user2" KORAP_PASSWORD="passwo
3737
| `NC_TALK_URL` | `https://cloud.ids-mannheim.de` | Nextcloud instance URL for Talk notifications |
3838
| `NC_TALK_CONVERSATION` | _(none)_ | Nextcloud Talk conversation token for notifications |
3939
| `NC_TALK_SECRET` | _(none)_ | Nextcloud Talk bot secret for authentication |
40+
| `NOTIFY_ON_SUCCESS` | `false` | When `true` or `1`, send notifications when tests **pass** instead of when they fail |
4041
| `LC_ALL` | _(system default)_ | Locale setting (recommended: `C` for consistent results) |
4142

4243
### Usage Notes

test/korap-ui.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const KORAP_LOGIN = 'KORAP_USERNAME' in process.env ? process.env.KORAP_USERNAME
2020
const KORAP_PWD = process.env.KORAP_PWD || process.env.KORAP_PASSWORD || "password2";
2121
const KORAP_QUERIES = process.env.KORAP_QUERIES || 'geht, [orth=geht & cmc/pos=VVFIN]'
2222
const KORAP_MIN_TOKENS_IN_CORPUS = parseInt(process.env.KORAP_MIN_TOKENS_IN_CORPUS || "100000", 10);
23+
const NOTIFY_ON_SUCCESS = process.env.NOTIFY_ON_SUCCESS === 'true' || process.env.NOTIFY_ON_SUCCESS === '1';
2324
const korap_rc = require('../lib/korap_rc.js').new(KORAP_URL)
2425
const { sendToNextcloudTalk, ifConditionIt } = require('../lib/utils.js');
2526

@@ -66,28 +67,40 @@ describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => {
6667
})
6768

6869
afterEach(async function () {
69-
if (this.currentTest.state == "failed") {
70+
const testPassed = this.currentTest.state === "passed";
71+
const testFailed = this.currentTest.state === "failed";
72+
73+
// Determine if we should send notification based on NOTIFY_ON_SUCCESS setting
74+
const shouldNotify = NOTIFY_ON_SUCCESS ? testPassed : testFailed;
75+
76+
if (shouldNotify) {
7077
// Only take screenshot if it's not one of the initial connectivity/SSL tests
7178
const initialTestTitles = [
7279
'should be reachable',
7380
'should have a valid SSL certificate'
7481
];
7582
let screenshotPath = null;
7683

77-
if (!initialTestTitles.includes(this.currentTest.title) && page) {
84+
// Only take screenshots for failures (not for success notifications)
85+
if (testFailed && !initialTestTitles.includes(this.currentTest.title) && page) {
7886
screenshotPath = "failed_" + this.currentTest.title.replaceAll(/[ &\/]/g, "_") + '.png';
7987
await page.screenshot({ path: screenshotPath });
8088
}
8189

90+
// Prepare notification content based on success/failure
91+
const emoji = testPassed ? '✅' : '🚨';
92+
const status = testPassed ? 'passed' : 'failed';
93+
const color = testPassed ? 'good' : 'danger';
94+
8295
// Send notification to Slack
8396
if (slack) {
8497
try {
8598
slack.alert({
86-
text: `🚨 Test on ${KORAP_URL} failed: *${this.currentTest.title}*`,
99+
text: `${emoji} Test on ${KORAP_URL} ${status}: *${this.currentTest.title}*`,
87100
attachments: [{
88-
color: 'danger',
101+
color: color,
89102
fields: [{
90-
title: 'Failed Test',
103+
title: testPassed ? 'Passed Test' : 'Failed Test',
91104
value: this.currentTest.title,
92105
short: false
93106
}, {
@@ -102,7 +115,7 @@ describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => {
102115
}
103116
}
104117

105-
// Upload screenshot to Slack if available
118+
// Upload screenshot to Slack if available (only for failures)
106119
if (screenshotPath) {
107120
const slackToken = process.env.SLACK_TOKEN;
108121
if (slackToken) {
@@ -126,9 +139,9 @@ describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => {
126139
}
127140
}
128141

129-
// Send notification to Nextcloud Talk with screenshot
142+
// Send notification to Nextcloud Talk with screenshot (if available)
130143
try {
131-
const message = `🚨 Test on ${KORAP_URL} failed: **${this.currentTest.title}**`;
144+
const message = `${emoji} Test on ${KORAP_URL} ${status}: **${this.currentTest.title}**`;
132145
await sendToNextcloudTalk(message, false, screenshotPath);
133146
} catch (ncError) {
134147
console.error('Failed to send notification to Nextcloud Talk:', ncError.message);

0 commit comments

Comments
 (0)