@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
81 lines • 4.84 kB
JavaScript
;
// *****************************************************************************
// Copyright (C) 2026 EclipseSource and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const chai_1 = require("chai");
const inversify_1 = require("inversify");
const common_1 = require("../../../common");
const channel_1 = require("../../../common/message-rpc/channel");
const uint8_array_message_buffer_1 = require("../../../common/message-rpc/uint8-array-message-buffer");
const connection_container_module_1 = require("../connection-container-module");
const default_messaging_service_1 = require("../default-messaging-service");
const frontend_connection_service_1 = require("../frontend-connection-service");
const messaging_service_1 = require("../messaging-service");
describe('DefaultMessagingService', () => {
describe('when a frontend connection closes', () => {
it('disposes the connection-scoped child container, invoking @preDestroy on bound singleton services', async () => {
let canaryDisposed = false;
let CanaryConnectionHandler = class CanaryConnectionHandler {
constructor() {
this.path = 'canary';
}
onConnection(_channel) { }
onPreDestroy() {
canaryDisposed = true;
}
};
tslib_1.__decorate([
(0, inversify_1.preDestroy)(),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", []),
tslib_1.__metadata("design:returntype", void 0)
], CanaryConnectionHandler.prototype, "onPreDestroy", null);
CanaryConnectionHandler = tslib_1.__decorate([
(0, inversify_1.injectable)()
], CanaryConnectionHandler);
const canaryModule = connection_container_module_1.ConnectionContainerModule.create(({ bind }) => {
bind(CanaryConnectionHandler).toSelf().inSingletonScope();
bind(common_1.ConnectionHandler).toService(CanaryConnectionHandler);
});
const container = new inversify_1.Container();
container.bind(default_messaging_service_1.MessagingContainer).toConstantValue(container);
container.bind(default_messaging_service_1.DefaultMessagingService).toSelf().inSingletonScope();
container.bind(connection_container_module_1.ConnectionContainerModule).toConstantValue(canaryModule);
(0, common_1.bindContributionProvider)(container, connection_container_module_1.ConnectionContainerModule);
(0, common_1.bindContributionProvider)(container, messaging_service_1.MessagingService.Contribution);
let serviceHandler;
const frontendConnectionService = {
registerConnectionHandler(path, callback) {
if (path === common_1.servicesPath) {
serviceHandler = callback;
}
}
};
container.bind(frontend_connection_service_1.FrontendConnectionService).toConstantValue(frontendConnectionService);
const messagingService = container.get(default_messaging_service_1.DefaultMessagingService);
messagingService.initialize();
(0, chai_1.expect)(serviceHandler, 'connection handler not registered on the services path').to.not.be.undefined;
const mainChannel = new channel_1.BasicChannel(() => new uint8_array_message_buffer_1.Uint8ArrayWriteBuffer());
serviceHandler({}, mainChannel);
(0, chai_1.expect)(canaryDisposed, 'canary should not be disposed before the channel is closed').to.be.false;
mainChannel.onCloseEmitter.fire({ reason: 'frontend connection closed' });
await new Promise(resolve => setImmediate(resolve));
(0, chai_1.expect)(canaryDisposed, 'canary @preDestroy was not invoked').to.be.true;
});
});
});
//# sourceMappingURL=default-messaging-service.spec.js.map