| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 1 | const https = require('https'); |
| Marc Kupietz | 2f17a76 | 2025-12-06 11:45:49 +0100 | [diff] [blame] | 2 | |
| Marc Kupietz | 490b053 | 2024-09-05 09:36:21 +0200 | [diff] [blame] | 3 | const puppeteer = require('puppeteer-extra'); |
| 4 | puppeteer.use(require('puppeteer-extra-plugin-user-preferences')({ |
| 5 | userPrefs: { |
| 6 | safebrowsing: { |
| 7 | enabled: false, |
| 8 | enhanced: false |
| 9 | } |
| 10 | } |
| 11 | })); |
| Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 12 | const chai = require('chai'); |
| Marc Kupietz | 4c5a7a5 | 2022-12-04 16:56:30 +0100 | [diff] [blame] | 13 | const { afterEach } = require('mocha'); |
| Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 14 | const assert = chai.assert; |
| 15 | const should = chai.should(); |
| Marc Kupietz | 7f1666a | 2024-07-12 18:35:31 +0200 | [diff] [blame] | 16 | var slack = null; |
| Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 17 | |
| Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 18 | const KORAP_URL = process.env.KORAP_URL || "http://localhost:64543"; |
| Marc Kupietz | bfb2301 | 2025-06-03 15:47:10 +0200 | [diff] [blame] | 19 | const KORAP_LOGIN = 'KORAP_USERNAME' in process.env ? process.env.KORAP_USERNAME : 'KORAP_LOGIN' in process.env ? process.env.KORAP_LOGIN : "user2" |
| 20 | const KORAP_PWD = process.env.KORAP_PWD || process.env.KORAP_PASSWORD || "password2"; |
| Marc Kupietz | 2698238 | 2022-12-04 19:02:57 +0100 | [diff] [blame] | 21 | const KORAP_QUERIES = process.env.KORAP_QUERIES || 'geht, [orth=geht & cmc/pos=VVFIN]' |
| Marc Kupietz | c8ffb2b | 2025-06-12 16:44:23 +0200 | [diff] [blame] | 22 | const KORAP_MIN_TOKENS_IN_CORPUS = parseInt(process.env.KORAP_MIN_TOKENS_IN_CORPUS || "100000", 10); |
| Marc Kupietz | f007969 | 2026-06-14 20:25:54 +0200 | [diff] [blame] | 23 | const KORAP_SEARCH_TIMEOUT = parseInt(process.env.KORAP_SEARCH_TIMEOUT || "60000", 10); |
| Marc Kupietz | 6329cac | 2026-06-15 16:39:55 +0200 | [diff] [blame] | 24 | const KORAP_VC = process.env.KORAP_VC || process.env.VC || ""; |
| Marc Kupietz | bbe6de0 | 2026-02-04 09:39:48 +0100 | [diff] [blame] | 25 | const NOTIFY_ON_SUCCESS = process.env.NOTIFY_ON_SUCCESS === 'true' || process.env.NOTIFY_ON_SUCCESS === '1'; |
| Marc Kupietz | f44c128 | 2026-07-06 16:04:03 +0200 | [diff] [blame^] | 26 | const KORAP_DISABLE_GLIMPSE = process.env.KORAP_DISABLE_GLIMPSE === 'true' || process.env.KORAP_DISABLE_GLIMPSE === '1'; |
| Marc Kupietz | 819a52d | 2026-03-21 09:41:28 +0100 | [diff] [blame] | 27 | const KORAP_HEADLESS = !(process.env.KORAP_HEADLESS === 'false' || process.env.KORAP_HEADLESS === '0'); |
| Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 28 | const korap_rc = require('../lib/korap_rc.js').new(KORAP_URL) |
| Marc Kupietz | 2f17a76 | 2025-12-06 11:45:49 +0100 | [diff] [blame] | 29 | const { sendToNextcloudTalk, ifConditionIt } = require('../lib/utils.js'); |
| Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 30 | |
| Marc Kupietz | 7f1666a | 2024-07-12 18:35:31 +0200 | [diff] [blame] | 31 | const slack_webhook = process.env.SLACK_WEBHOOK_URL; |
| Marc Kupietz | 4d335a3 | 2024-09-04 16:13:48 +0200 | [diff] [blame] | 32 | |
| Marc Kupietz | 7f1666a | 2024-07-12 18:35:31 +0200 | [diff] [blame] | 33 | if (slack_webhook) { |
| 34 | slack = require('slack-notify')(slack_webhook); |
| 35 | } |
| 36 | |
| Marc Kupietz | d0ee97e | 2025-12-04 15:46:14 +0100 | [diff] [blame] | 37 | |
| Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 38 | |
| Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 39 | describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => { |
| Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 40 | |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 41 | let browser; |
| 42 | let page; |
| 43 | |
| 44 | |
| Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 45 | before(async () => { |
| Marc Kupietz | b4d62a8 | 2026-06-04 14:52:28 +0200 | [diff] [blame] | 46 | try { |
| 47 | browser = await puppeteer.launch({ |
| 48 | headless: KORAP_HEADLESS ? "shell" : false, |
| 49 | args: [ |
| 50 | '--no-sandbox', |
| 51 | '--disable-setuid-sandbox', |
| 52 | '--disable-dev-shm-usage', |
| 53 | '--disable-accelerated-2d-canvas', |
| 54 | '--no-first-run', |
| 55 | '--no-zygote', |
| 56 | '--disable-gpu' |
| 57 | ] |
| 58 | }) |
| 59 | page = await browser.newPage() |
| 60 | await page.setViewport({ |
| 61 | width: 1980, |
| 62 | height: 768, |
| 63 | deviceScaleFactor: 1, |
| 64 | }); |
| Marc Kupietz | 5698154 | 2026-06-16 09:09:44 +0200 | [diff] [blame] | 65 | console.log(`Run started ${new Date().toISOString()} on ${KORAP_URL}` + |
| 66 | (KORAP_VC ? ` (virtual corpus: ${KORAP_VC})` : '')); |
| Marc Kupietz | b4d62a8 | 2026-06-04 14:52:28 +0200 | [diff] [blame] | 67 | } catch (error) { |
| 68 | console.error('Failed to initialize Puppeteer browser:', error.message); |
| 69 | |
| 70 | // Send failure notification |
| 71 | const emoji = '🚨'; |
| 72 | const message = `${emoji} Test setup on ${KORAP_URL} failed: **${error.message}**`; |
| 73 | |
| 74 | // Send notification to Slack |
| 75 | if (slack) { |
| 76 | try { |
| 77 | slack.alert({ |
| 78 | text: `${emoji} Test setup on ${KORAP_URL} failed`, |
| 79 | attachments: [{ |
| 80 | color: 'danger', |
| 81 | fields: [{ |
| 82 | title: 'Error Details', |
| 83 | value: error.message, |
| 84 | short: false |
| 85 | }, { |
| 86 | title: 'URL', |
| 87 | value: KORAP_URL, |
| 88 | short: true |
| 89 | }] |
| 90 | }] |
| 91 | }); |
| 92 | } catch (slackError) { |
| 93 | console.error('Failed to send setup error to Slack:', slackError.message); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // Send notification to Nextcloud Talk |
| 98 | try { |
| 99 | await sendToNextcloudTalk(message, false); |
| 100 | } catch (ncError) { |
| 101 | console.error('Failed to send setup error to Nextcloud Talk:', ncError.message); |
| 102 | } |
| 103 | |
| 104 | // Rethrow the error so that the test run is registered as failed |
| 105 | throw error; |
| 106 | } |
| Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 107 | }) |
| 108 | |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 109 | after(async function() { |
| 110 | if (browser && typeof browser.close === 'function') { |
| 111 | await browser.close(); |
| 112 | } |
| Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 113 | }) |
| 114 | |
| Marc Kupietz | 4c5a7a5 | 2022-12-04 16:56:30 +0100 | [diff] [blame] | 115 | afterEach(async function () { |
| Marc Kupietz | bbe6de0 | 2026-02-04 09:39:48 +0100 | [diff] [blame] | 116 | const testPassed = this.currentTest.state === "passed"; |
| 117 | const testFailed = this.currentTest.state === "failed"; |
| 118 | |
| 119 | // Determine if we should send notification based on NOTIFY_ON_SUCCESS setting |
| 120 | const shouldNotify = NOTIFY_ON_SUCCESS ? testPassed : testFailed; |
| 121 | |
| 122 | if (shouldNotify) { |
| Marc Kupietz | 65dea51 | 2025-12-04 17:55:57 +0100 | [diff] [blame] | 123 | // Only take screenshot if it's not one of the initial connectivity/SSL tests |
| 124 | const initialTestTitles = [ |
| 125 | 'should be reachable', |
| 126 | 'should have a valid SSL certificate' |
| 127 | ]; |
| 128 | let screenshotPath = null; |
| 129 | |
| Marc Kupietz | bbe6de0 | 2026-02-04 09:39:48 +0100 | [diff] [blame] | 130 | // Only take screenshots for failures (not for success notifications) |
| 131 | if (testFailed && !initialTestTitles.includes(this.currentTest.title) && page) { |
| Marc Kupietz | 65dea51 | 2025-12-04 17:55:57 +0100 | [diff] [blame] | 132 | screenshotPath = "failed_" + this.currentTest.title.replaceAll(/[ &\/]/g, "_") + '.png'; |
| 133 | await page.screenshot({ path: screenshotPath }); |
| 134 | } |
| 135 | |
| Marc Kupietz | bbe6de0 | 2026-02-04 09:39:48 +0100 | [diff] [blame] | 136 | // Prepare notification content based on success/failure |
| 137 | const emoji = testPassed ? '✅' : '🚨'; |
| 138 | const status = testPassed ? 'passed' : 'failed'; |
| 139 | const color = testPassed ? 'good' : 'danger'; |
| Marc Kupietz | 5698154 | 2026-06-16 09:09:44 +0200 | [diff] [blame] | 140 | const timestamp = new Date().toISOString(); |
| 141 | |
| 142 | // Capture the actual page URL (e.g. the full search results URL with |
| 143 | // query and cq) so issues can be reproduced/traced immediately. Fall |
| 144 | // back to the instance URL for tests that never navigated (about:blank). |
| 145 | let currentUrl = KORAP_URL; |
| 146 | try { |
| 147 | const u = page && typeof page.url === 'function' ? page.url() : ''; |
| 148 | if (/^https?:/.test(u)) currentUrl = u; |
| 149 | } catch (e) { /* keep KORAP_URL */ } |
| 150 | |
| 151 | // Echo the result with its URL to the console log as well. |
| 152 | console.log(`${emoji} [${timestamp}] ${status}: ${this.currentTest.title} — ${currentUrl}`); |
| Marc Kupietz | bbe6de0 | 2026-02-04 09:39:48 +0100 | [diff] [blame] | 153 | |
| Marc Kupietz | 65dea51 | 2025-12-04 17:55:57 +0100 | [diff] [blame] | 154 | // Send notification to Slack |
| Marc Kupietz | 7f1666a | 2024-07-12 18:35:31 +0200 | [diff] [blame] | 155 | if (slack) { |
| Marc Kupietz | 8f7c204 | 2025-06-24 09:55:03 +0200 | [diff] [blame] | 156 | try { |
| Marc Kupietz | 8f7c204 | 2025-06-24 09:55:03 +0200 | [diff] [blame] | 157 | slack.alert({ |
| Marc Kupietz | 5698154 | 2026-06-16 09:09:44 +0200 | [diff] [blame] | 158 | text: `${emoji} [${timestamp}] Test on ${KORAP_URL} ${status}: *${this.currentTest.title}*`, |
| Marc Kupietz | 8f7c204 | 2025-06-24 09:55:03 +0200 | [diff] [blame] | 159 | attachments: [{ |
| Marc Kupietz | bbe6de0 | 2026-02-04 09:39:48 +0100 | [diff] [blame] | 160 | color: color, |
| Marc Kupietz | 8f7c204 | 2025-06-24 09:55:03 +0200 | [diff] [blame] | 161 | fields: [{ |
| Marc Kupietz | bbe6de0 | 2026-02-04 09:39:48 +0100 | [diff] [blame] | 162 | title: testPassed ? 'Passed Test' : 'Failed Test', |
| Marc Kupietz | 8f7c204 | 2025-06-24 09:55:03 +0200 | [diff] [blame] | 163 | value: this.currentTest.title, |
| 164 | short: false |
| 165 | }, { |
| 166 | title: 'URL', |
| Marc Kupietz | 5698154 | 2026-06-16 09:09:44 +0200 | [diff] [blame] | 167 | value: currentUrl, |
| 168 | short: false |
| Marc Kupietz | 8f7c204 | 2025-06-24 09:55:03 +0200 | [diff] [blame] | 169 | }] |
| 170 | }] |
| 171 | }); |
| 172 | } catch (slackError) { |
| 173 | console.error('Failed to send notification to Slack:', slackError.message); |
| 174 | } |
| 175 | } |
| 176 | |
| Marc Kupietz | bbe6de0 | 2026-02-04 09:39:48 +0100 | [diff] [blame] | 177 | // Upload screenshot to Slack if available (only for failures) |
| Marc Kupietz | 65dea51 | 2025-12-04 17:55:57 +0100 | [diff] [blame] | 178 | if (screenshotPath) { |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 179 | const slackToken = process.env.SLACK_TOKEN; |
| 180 | if (slackToken) { |
| 181 | try { |
| 182 | const { WebClient } = require('@slack/web-api'); |
| Marc Kupietz | 65dea51 | 2025-12-04 17:55:57 +0100 | [diff] [blame] | 183 | const fs = require('fs'); |
| 184 | const web = new WebClient(slackToken); |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 185 | const channelId = process.env.SLACK_CHANNEL_ID || 'C07CM4JS48H'; |
| Marc Kupietz | 8f7c204 | 2025-06-24 09:55:03 +0200 | [diff] [blame] | 186 | |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 187 | const result = await web.files.uploadV2({ |
| 188 | channel_id: channelId, |
| 189 | file: fs.createReadStream(screenshotPath), |
| 190 | filename: screenshotPath, |
| 191 | title: `Screenshot: ${this.currentTest.title}`, |
| 192 | initial_comment: `📸 Screenshot of failed test: ${this.currentTest.title} on ${KORAP_URL}` |
| 193 | }); |
| Marc Kupietz | 8f7c204 | 2025-06-24 09:55:03 +0200 | [diff] [blame] | 194 | |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 195 | } catch (uploadError) { |
| 196 | console.error('Failed to upload screenshot to Slack:', uploadError.message); |
| 197 | } |
| Marc Kupietz | 8f7c204 | 2025-06-24 09:55:03 +0200 | [diff] [blame] | 198 | } |
| Marc Kupietz | 7f1666a | 2024-07-12 18:35:31 +0200 | [diff] [blame] | 199 | } |
| Marc Kupietz | 65dea51 | 2025-12-04 17:55:57 +0100 | [diff] [blame] | 200 | |
| Marc Kupietz | bbe6de0 | 2026-02-04 09:39:48 +0100 | [diff] [blame] | 201 | // Send notification to Nextcloud Talk with screenshot (if available) |
| Marc Kupietz | 2f17a76 | 2025-12-06 11:45:49 +0100 | [diff] [blame] | 202 | try { |
| Marc Kupietz | 5698154 | 2026-06-16 09:09:44 +0200 | [diff] [blame] | 203 | const message = `${emoji} [${timestamp}] Test on ${KORAP_URL} ${status}: **${this.currentTest.title}**\n${currentUrl}`; |
| Marc Kupietz | 2f17a76 | 2025-12-06 11:45:49 +0100 | [diff] [blame] | 204 | await sendToNextcloudTalk(message, false, screenshotPath); |
| 205 | } catch (ncError) { |
| 206 | console.error('Failed to send notification to Nextcloud Talk:', ncError.message); |
| Marc Kupietz | 65dea51 | 2025-12-04 17:55:57 +0100 | [diff] [blame] | 207 | } |
| Marc Kupietz | 4c5a7a5 | 2022-12-04 16:56:30 +0100 | [diff] [blame] | 208 | } |
| Marc Kupietz | 964e777 | 2025-06-03 15:02:30 +0200 | [diff] [blame] | 209 | }) |
| Marc Kupietz | 4c5a7a5 | 2022-12-04 16:56:30 +0100 | [diff] [blame] | 210 | |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 211 | it('should be reachable', function (done) { |
| 212 | let doneCalled = false; |
| 213 | const url = new URL(KORAP_URL); |
| 214 | const httpModule = url.protocol === 'https:' ? https : require('http'); |
| Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 215 | |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 216 | const req = httpModule.request({ |
| 217 | method: 'HEAD', |
| 218 | hostname: url.hostname, |
| 219 | port: url.port || (url.protocol === 'https:' ? 443 : 80), |
| 220 | path: url.pathname, |
| 221 | timeout: 5000 |
| 222 | }, res => { |
| 223 | if (!doneCalled) { |
| 224 | doneCalled = true; |
| 225 | if (res.statusCode >= 200 && res.statusCode < 400) { |
| 226 | done(); |
| 227 | } else { |
| 228 | done(new Error(`Server is not reachable. Status code: ${res.statusCode}`)); |
| 229 | } |
| 230 | } |
| 231 | }); |
| 232 | req.on('timeout', () => { |
| 233 | if (!doneCalled) { |
| 234 | doneCalled = true; |
| 235 | req.destroy(); |
| 236 | done(new Error('Request to server timed out.')); |
| 237 | } |
| 238 | }); |
| 239 | req.on('error', err => { |
| 240 | if (!doneCalled) { |
| 241 | doneCalled = true; |
| 242 | done(err); |
| 243 | } |
| 244 | }); |
| 245 | req.end(); |
| 246 | }); |
| Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 247 | |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 248 | it('should have a valid SSL certificate', function (done) { |
| 249 | let doneCalled = false; |
| 250 | const url = new URL(KORAP_URL); |
| 251 | if (url.protocol !== 'https:') { |
| 252 | return this.skip(); |
| 253 | } |
| 254 | const req = https.request({ |
| 255 | method: 'HEAD', |
| 256 | hostname: url.hostname, |
| 257 | port: url.port || 443, |
| 258 | path: url.pathname, |
| 259 | timeout: 5000 |
| 260 | }, res => { |
| 261 | if (!doneCalled) { |
| 262 | doneCalled = true; |
| 263 | const cert = res.socket.getPeerCertificate(); |
| 264 | if (cert && cert.valid_to) { |
| 265 | const validTo = new Date(cert.valid_to); |
| 266 | if (validTo > new Date()) { |
| 267 | done(); |
| 268 | } else { |
| 269 | done(new Error(`SSL certificate expired on ${validTo.toDateString()}`)); |
| 270 | } |
| 271 | } else if (res.socket.isSessionReused()){ |
| 272 | done(); |
| 273 | } |
| 274 | else { |
| 275 | done(new Error('Could not retrieve SSL certificate information.')); |
| 276 | } |
| 277 | } |
| 278 | }); |
| 279 | req.on('timeout', () => { |
| 280 | if (!doneCalled) { |
| 281 | doneCalled = true; |
| 282 | req.destroy(); |
| 283 | done(new Error('Request to server timed out.')); |
| 284 | } |
| 285 | }); |
| 286 | req.on('error', err => { |
| 287 | if (!doneCalled) { |
| 288 | doneCalled = true; |
| 289 | if (err.code === 'CERT_HAS_EXPIRED') { |
| 290 | done(new Error('SSL certificate has expired.')); |
| 291 | } else { |
| 292 | done(err); |
| 293 | } |
| 294 | } |
| 295 | }); |
| 296 | req.end(); |
| 297 | }); |
| Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 298 | |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 299 | describe('UI Tests', function() { |
| Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 300 | |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 301 | before(function() { |
| 302 | // Check the state of the parent suite's tests |
| 303 | const initialTests = this.test.parent.parent.tests; |
| 304 | if (initialTests[0].state === 'failed' || initialTests[1].state === 'failed') { |
| 305 | this.skip(); |
| 306 | } |
| 307 | }); |
| Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 308 | |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 309 | |
| Marc Kupietz | c8ffb2b | 2025-06-12 16:44:23 +0200 | [diff] [blame] | 310 | |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 311 | it('KorAP UI is up and running', async function () { |
| 312 | try { |
| 313 | await page.goto(KORAP_URL, { waitUntil: 'domcontentloaded' }); |
| 314 | await page.waitForSelector("#q-field", { visible: true }); |
| 315 | const query_field = await page.$("#q-field") |
| 316 | assert.isNotNull(query_field, "#q-field not found. Kalamar not running?"); |
| 317 | } catch (error) { |
| 318 | throw new Error(`Failed to load KorAP UI or find query field: ${error.message}`); |
| 319 | } |
| Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 320 | }) |
| Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 321 | |
| Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 322 | |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 323 | ifConditionIt('Login into KorAP with incorrect credentials fails', |
| 324 | KORAP_LOGIN != "", |
| 325 | (async () => { |
| 326 | const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD + "*") |
| 327 | login_result.should.be.false |
| 328 | })) |
| 329 | |
| 330 | ifConditionIt('Login into KorAP with correct credentials succeeds', |
| 331 | KORAP_LOGIN != "", |
| 332 | (async () => { |
| 333 | const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) |
| 334 | login_result.should.be.true |
| 335 | })) |
| 336 | |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 337 | it('Corpus statistics show sufficient tokens', |
| 338 | (async () => { |
| 339 | const tokenCount = await korap_rc.check_corpus_statistics(page, KORAP_MIN_TOKENS_IN_CORPUS); |
| 340 | console.log(`Found ${tokenCount} tokens in corpus, minimum required: ${KORAP_MIN_TOKENS_IN_CORPUS}`); |
| 341 | tokenCount.should.be.above(KORAP_MIN_TOKENS_IN_CORPUS - 1, |
| 342 | `Corpus should have at least ${KORAP_MIN_TOKENS_IN_CORPUS} tokens, but found ${tokenCount}`); |
| 343 | })).timeout(90000) |
| 344 | |
| 345 | describe('Running searches that should have hits', () => { |
| 346 | |
| Marc Kupietz | 6329cac | 2026-06-15 16:39:55 +0200 | [diff] [blame] | 347 | // The searches must run while logged in — most corpora are only |
| 348 | // available after authentication. Re-assert the session here and, |
| 349 | // when a login is required, fail loudly if it didn't take instead |
| 350 | // of silently testing the (tiny) public corpus logged out. |
| 351 | before(async () => { |
| 352 | const logged_in = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) |
| 353 | if (KORAP_LOGIN != "") { |
| 354 | assert.isTrue(logged_in, |
| 355 | "Login is required for the has-hits searches but did not succeed; aborting so we don't test the public corpus while logged out") |
| 356 | } |
| 357 | }) |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 358 | |
| Marc Kupietz | 5698154 | 2026-06-16 09:09:44 +0200 | [diff] [blame] | 359 | const vcLabel = KORAP_VC ? ` in vc "${KORAP_VC}"` : ''; |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 360 | KORAP_QUERIES.split(/[;,] */).forEach((query, i) => { |
| Marc Kupietz | 5698154 | 2026-06-16 09:09:44 +0200 | [diff] [blame] | 361 | it('Search for "' + query + '"' + vcLabel + ' has hits', |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 362 | (async () => { |
| Marc Kupietz | f44c128 | 2026-07-06 16:04:03 +0200 | [diff] [blame^] | 363 | // Leave glimpse (cutoff) on by default to reduce server load; it |
| 364 | // still proves the server is up. Set KORAP_DISABLE_GLIMPSE=true |
| 365 | // to force full (uncapped) result counts if needed. |
| 366 | if (KORAP_DISABLE_GLIMPSE) { |
| 367 | await korap_rc.assure_glimpse_off(page) |
| 368 | } |
| Marc Kupietz | 6329cac | 2026-06-15 16:39:55 +0200 | [diff] [blame] | 369 | const hits = await korap_rc.search(page, query, { timeout: KORAP_SEARCH_TIMEOUT, vc: KORAP_VC }) |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 370 | hits.should.be.above(0) |
| Marc Kupietz | 6329cac | 2026-06-15 16:39:55 +0200 | [diff] [blame] | 371 | })).timeout(KORAP_SEARCH_TIMEOUT + 30000) |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 372 | }) |
| 373 | }) |
| 374 | |
| Marc Kupietz | 6329cac | 2026-06-15 16:39:55 +0200 | [diff] [blame] | 375 | // Logout must be the LAST UI test. Mocha runs a suite's direct it() |
| 376 | // tests before its nested describe() suites, so a top-level "Logout" |
| 377 | // test would otherwise run *before* the searches above and log us out, |
| 378 | // leaving them to query the public corpus. Wrapping it in its own suite |
| 379 | // declared after the searches suite guarantees it runs last. |
| 380 | describe('Logging out', () => { |
| 381 | ifConditionIt('Logout works', |
| 382 | KORAP_LOGIN != "", |
| 383 | (async () => { |
| 384 | const logout_result = await korap_rc.logout(page) |
| 385 | logout_result.should.be.true |
| 386 | })).timeout(15000) |
| 387 | }) |
| Marc Kupietz | 93d7f70 | 2025-06-27 15:41:48 +0200 | [diff] [blame] | 388 | }); |
| 389 | }); |