Files
upstream-mirror 30810eecd7
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:21:02 +05:00

93 lines
3.3 KiB
TypeScript

import * as assert from 'node:assert';
import { describe, it } from 'node:test';
import type { TestContext } from 'node:test';
import { LogMessageSeverity } from '@rocket.chat/apps-engine/definition/accessors';
import { AppMethod } from '@rocket.chat/apps-engine/definition/metadata';
import type * as stackTrace from 'stack-trace';
import { AppConsole } from '../../../src/server/logging';
describe('AppConsole', () => {
it('basicConsoleMethods', (t: TestContext) => {
t.mock.timers.enable({ apis: ['Date'] });
assert.doesNotThrow(() => new AppConsole(AppMethod._CONSTRUCTOR));
const logger = new AppConsole(AppMethod._CONSTRUCTOR);
const { entries } = logger as any;
assert.doesNotThrow(() => logger.debug('this is a debug'));
assert.strictEqual(entries.length, 1);
assert.strictEqual(entries[0].severity, LogMessageSeverity.DEBUG);
assert.strictEqual(entries[0].args[0], 'this is a debug');
assert.doesNotThrow(() => logger.info('this is an info log'));
assert.strictEqual(entries.length, 2);
assert.strictEqual(entries[1].severity, LogMessageSeverity.INFORMATION);
assert.strictEqual(entries[1].args[0], 'this is an info log');
assert.doesNotThrow(() => logger.log('this is a log'));
assert.strictEqual(entries.length, 3);
assert.strictEqual(entries[2].severity, LogMessageSeverity.LOG);
assert.strictEqual(entries[2].args[0], 'this is a log');
assert.doesNotThrow(() => logger.warn('this is a warn'));
assert.strictEqual(entries.length, 4);
assert.strictEqual(entries[3].severity, LogMessageSeverity.WARNING);
assert.strictEqual(entries[3].args[0], 'this is a warn');
const e = new Error('just a test');
assert.doesNotThrow(() => logger.error(e));
assert.strictEqual(entries.length, 5);
assert.strictEqual(entries[4].severity, LogMessageSeverity.ERROR);
assert.strictEqual(entries[4].args[0], JSON.stringify(e, Object.getOwnPropertyNames(e)));
assert.doesNotThrow(() => logger.success('this is a success'));
assert.strictEqual(entries.length, 6);
assert.strictEqual(entries[5].severity, LogMessageSeverity.SUCCESS);
assert.strictEqual(entries[5].args[0], 'this is a success');
assert.doesNotThrow(() => {
class Item {
constructor() {
logger.debug('inside');
}
}
return new Item();
});
assert.deepStrictEqual(logger.getEntries(), entries);
assert.strictEqual(logger.getMethod(), AppMethod._CONSTRUCTOR);
assert.ok(logger.getStartTime() !== undefined);
assert.ok(logger.getEndTime() !== undefined);
t.mock.timers.tick(1000);
assert.strictEqual(logger.getTotalTime(), 1000);
const getFunc = (logger as any).getFunc.bind(logger);
assert.strictEqual(getFunc([{} as stackTrace.StackFrame]), 'anonymous');
const mockFrames = [];
mockFrames.push({} as stackTrace.StackFrame);
mockFrames.push({
getMethodName() {
return 'testing';
},
getFunctionName() {
return null;
},
} as stackTrace.StackFrame);
assert.strictEqual(getFunc(mockFrames), 'testing');
const entry = AppConsole.toStorageEntry('testing-app', logger);
assert.strictEqual(entry.appId, 'testing-app');
assert.strictEqual(entry.method, AppMethod._CONSTRUCTOR);
assert.deepStrictEqual(entry.entries, logger.getEntries());
assert.ok(entry.startTime instanceof Date);
assert.ok(entry.endTime instanceof Date);
assert.strictEqual(entry.totalTime, 1000);
assert.ok(entry._createdAt instanceof Date);
});
});