Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(tests): Adds debug log for webhooks.

damencho25cbe888a18c
diff --git a/tests/helpers/WebhookProxy.ts b/tests/helpers/WebhookProxy.ts
index 9507a126fe..89e9697689 100644
--- a/tests/helpers/WebhookProxy.ts
+++ b/tests/helpers/WebhookProxy.ts
@@ -1,11 +1,13 @@
+import fs from 'node:fs';
import WebSocket from 'ws';
/**
* Uses the webhook proxy service to proxy events to the testing clients.
*/
export default class WebhookProxy {
- private url;
- private secret;
+ private readonly url;
+ private readonly secret;
+ private logFile;
private ws: WebSocket | undefined;
private cache = new Map();
private listeners = new Map();
@@ -15,10 +17,12 @@ export default class WebhookProxy {
* Initializes the webhook proxy.
* @param url
* @param secret
+ * @param logFile
*/
- constructor(url: string, secret: string) {
+ constructor(url: string, secret: string, logFile: string) {
this.url = url;
this.secret = secret;
+ this.logFile = logFile;
}
/**
@@ -40,6 +44,8 @@ export default class WebhookProxy {
this.ws.on('message', (data: any) => {
const msg = JSON.parse(data.toString());
+ this.logInfo(`${msg.eventType} event: ${JSON.stringify(msg)}`);
+
if (msg.eventType) {
let processed = false;
@@ -85,6 +91,7 @@ export default class WebhookProxy {
* Clear any stored event.
*/
clearCache() {
+ this.logInfo('cache cleared');
this.cache.clear();
}
@@ -98,7 +105,11 @@ export default class WebhookProxy {
const error = new Error(`Timeout waiting for event:${eventType}`);
return new Promise((resolve, reject) => {
- const waiter = setTimeout(() => reject(error), timeout);
+ const waiter = setTimeout(() => {
+ this.logInfo(error.message);
+
+ return reject(error);
+ }, timeout);
this.addConsumer(eventType, event => {
clearTimeout(waiter);
@@ -134,6 +145,22 @@ export default class WebhookProxy {
this.ws.close();
console.log('WebhookProxy disconnected');
this.ws = undefined;
+ this.logInfo('disconnected');
+ }
+ }
+
+ /**
+ * Logs a message in the logfile.
+ *
+ * @param {string} message - The message to add.
+ * @returns {void}
+ */
+ logInfo(message: string) {
+ try {
+ // @ts-ignore
+ fs.appendFileSync(this.logFile, `${new Date().toISOString()} ${message}\n`);
+ } catch (err) {
+ console.error(err);
}
}
}
diff --git a/tests/pageobjects/IframeAPI.ts b/tests/pageobjects/IframeAPI.ts
index faa6428261..e32af45d6c 100644
--- a/tests/pageobjects/IframeAPI.ts
+++ b/tests/pageobjects/IframeAPI.ts
@@ -41,10 +41,10 @@ export default class IframeAPI extends BasePageObject {
addEventListener(eventName: string) {
return this.participant.execute(
(event, prefix) => {
- console.log(`${new Date().toISOString()} ${prefix} Adding listener for event: ${event}`);
+ console.log(`${new Date().toISOString()} ${prefix}iframeAPI - Adding listener for event: ${event}`);
window.jitsiAPI.addListener(event, evt => {
console.log(
- `${new Date().toISOString()} ${prefix} Received ${event} event: ${JSON.stringify(evt)}`);
+ `${new Date().toISOString()} ${prefix}iframeAPI - Received ${event} event: ${JSON.stringify(evt)}`);
window.jitsiAPI.test[event] = evt;
});
}, eventName, LOG_PREFIX);
diff --git a/tests/wdio.conf.ts b/tests/wdio.conf.ts
index 2633ee4742..8e9f1d0ce9 100644
--- a/tests/wdio.conf.ts
+++ b/tests/wdio.conf.ts
@@ -221,6 +221,21 @@ export const config: WebdriverIO.MultiremoteConfig = {
globalAny.ctx.jwtPrivateKeyPath = process.env.JWT_PRIVATE_KEY_PATH;
globalAny.ctx.jwtKid = process.env.JWT_KID;
globalAny.ctx.isJaasAvailable = () => globalAny.ctx.jwtKid?.startsWith('vpaas-magic-cookie-');
+
+ // If we are running the iFrameApi tests, we need to mark it as such and if needed to create the proxy
+ // and connect to it.
+ if (testName.startsWith('iFrameApi')) {
+ globalAny.ctx.iframeAPI = true;
+
+ if (!globalAny.ctx.webhooksProxy
+ && process.env.WEBHOOKS_PROXY_URL && process.env.WEBHOOKS_PROXY_SHARED_SECRET) {
+ globalAny.ctx.webhooksProxy = new WebhookProxy(
+ `${process.env.WEBHOOKS_PROXY_URL}&room=${globalAny.ctx.roomName}`,
+ process.env.WEBHOOKS_PROXY_SHARED_SECRET,
+ `${TEST_RESULTS_DIR}/webhooks-${cid}-${testName}.log`);
+ globalAny.ctx.webhooksProxy.connect();
+ }
+ }
},
after() {
@@ -254,22 +269,6 @@ export const config: WebdriverIO.MultiremoteConfig = {
* @param {Object} suite - Suite details.
*/
beforeSuite(suite) {
- const { ctx }: any = global;
-
- // If we are running the iFrameApi tests, we need to mark it as such and if needed to create the proxy
- // and connect to it.
- if (path.basename(suite.file).startsWith('iFrameApi')) {
- ctx.iframeAPI = true;
-
- if (!ctx.webhooksProxy
- && process.env.WEBHOOKS_PROXY_URL && process.env.WEBHOOKS_PROXY_SHARED_SECRET) {
- ctx.webhooksProxy = new WebhookProxy(
- `${process.env.WEBHOOKS_PROXY_URL}&room=${ctx.roomName}`,
- process.env.WEBHOOKS_PROXY_SHARED_SECRET);
- ctx.webhooksProxy.connect();
- }
- }
-
multiremotebrowser.instances.forEach((instance: string) => {
logInfo(multiremotebrowser.getInstance(instance),
`---=== Begin ${suite.file.substring(suite.file.lastIndexOf('/') + 1)} ===---`);