Files
upstream-rocketchat/packages/apps/tests/server/runtime/deno/bundleLegacyApp.test.ts
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

108 lines
3.8 KiB
TypeScript

import * as assert from 'node:assert';
import { describe, it } from 'node:test';
import type { AppImplements } from '../../../../src/server/compiler/AppImplements';
import type { IParseAppPackageResult } from '../../../../src/server/compiler/IParseAppPackageResult';
import { bundleLegacyApp } from '../../../../src/server/runtime/base/bundler';
function makeAppPackage(classFile: string, files: { [key: string]: string }): IParseAppPackageResult {
return {
info: {
id: 'test-app',
name: 'Test App',
nameSlug: 'test-app',
version: '0.0.1',
description: 'Test App',
requiredApiVersion: '*',
classFile,
iconFile: 'icon.png',
implements: [],
author: { name: 'Test', homepage: 'https://test.com', support: 'https://test.com' },
},
files,
languageContent: {},
implemented: {} as AppImplements,
};
}
describe('bundleLegacyApp', () => {
it('bundles a single-file app into one output file', async () => {
const appPackage = makeAppPackage('app.js', {
'app.js': 'module.exports = { hello: "world" };',
});
await bundleLegacyApp(appPackage);
// After bundling, files should contain only the single bundled entry
assert.strictEqual(Object.keys(appPackage.files).length, 1);
assert.ok(appPackage.files['app.js'] !== undefined);
assert.strictEqual(typeof appPackage.files['app.js'], 'string');
assert.ok(appPackage.files['app.js'].length > 0);
});
it('includes code from relative imports', async () => {
const appPackage = makeAppPackage('app.js', {
'app.js': 'var utils = require("./utils"); module.exports = utils;',
'utils.js': 'module.exports = { value: 42 };',
});
await bundleLegacyApp(appPackage);
assert.strictEqual(Object.keys(appPackage.files).length, 1);
// The bundled output should contain the inlined value from utils.js
assert.ok(appPackage.files['app.js'].includes('42'));
});
it('resolves directory index imports (require("./dir") → dir/index.js)', async () => {
const appPackage = makeAppPackage('app.js', {
'app.js': 'var lib = require("./lib"); module.exports = lib;',
'lib/index.js': 'module.exports = { fromIndex: true };',
});
await bundleLegacyApp(appPackage);
assert.strictEqual(Object.keys(appPackage.files).length, 1);
assert.ok(appPackage.files['app.js'].includes('fromIndex'));
});
it('marks @rocket.chat/apps-engine/* imports as external', async () => {
const appPackage = makeAppPackage('app.js', {
'app.js': ['var AppInterface = require("@rocket.chat/apps-engine/definition/AppInterface");', 'module.exports = AppInterface;'].join(
'\n',
),
});
await bundleLegacyApp(appPackage);
assert.strictEqual(Object.keys(appPackage.files).length, 1);
// The apps-engine import should remain as an external require, not be inlined
assert.ok(appPackage.files['app.js'].includes('@rocket.chat/apps-engine'));
});
it('handles deeply nested relative imports', async () => {
const appPackage = makeAppPackage('app.js', {
'app.js': 'var a = require("./commands/run"); module.exports = a;',
'commands/run.js': 'var helper = require("../helpers/format"); module.exports = helper;',
'helpers/format.js': 'module.exports = { formatted: true };',
});
await bundleLegacyApp(appPackage);
assert.strictEqual(Object.keys(appPackage.files).length, 1);
assert.ok(appPackage.files['app.js'].includes('formatted'));
});
it('replaces the files record with only the bundled classFile entry', async () => {
const appPackage = makeAppPackage('main.js', {
'main.js': 'var dep = require("./dep"); module.exports = dep;',
'dep.js': 'module.exports = "dep-value";',
'unused.js': 'module.exports = "unused";',
});
await bundleLegacyApp(appPackage);
// Only the classFile key should remain after bundling
assert.deepStrictEqual(Object.keys(appPackage.files), ['main.js']);
});
});