mirror of
https://github.com/bitwarden/browser
synced 2025-12-21 18:53:29 +00:00
refactor(libs): consolidate messaging-internal into messaging library (#16386)
This change eliminates the circular dependency between messaging and messaging-internal libraries by merging them into a single messaging library. Previously, messaging-internal imported from @bitwarden/messaging while messaging tried to import from @bitwarden/messaging-internal, creating an unresolvable circular dependency. This also violated Nx best practices by using cross-library file includes in tsconfig.lib.json. Changes made: - Moved all messaging-internal code (SubjectMessageSender, helpers, tests) into libs/messaging/src/ - Updated all imports to use relative paths instead of @bitwarden/messaging imports - Removed the entire messaging-internal library and its configuration files - Updated external references in apps/browser to import from @bitwarden/messaging - Fixed libs/messaging/tsconfig.lib.json to use standard src/**/*.ts pattern - Updated libs/common internal.ts to re-export from messaging instead of messaging-internal The messaging library now exports both public APIs and internal implementations, which is a cleaner architecture than maintaining two separate libraries with circular dependencies. Fixes rootDir configuration issues identified in the Nx library systematic fix project.
This commit is contained in:
58
libs/messaging/src/subject-message.sender.spec.ts
Normal file
58
libs/messaging/src/subject-message.sender.spec.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { bufferCount, firstValueFrom, Subject } from "rxjs";
|
||||
|
||||
import { SubjectMessageSender } from "./subject-message.sender";
|
||||
import { CommandDefinition, Message } from "./types";
|
||||
|
||||
describe("SubjectMessageSender", () => {
|
||||
const subject = new Subject<Message<{ test: number }>>();
|
||||
const subjectObservable = subject.asObservable();
|
||||
|
||||
const sut = new SubjectMessageSender(subject);
|
||||
|
||||
describe("send", () => {
|
||||
it("will send message with command from message definition", async () => {
|
||||
const commandDefinition = new CommandDefinition<{ test: number }>("myCommand");
|
||||
|
||||
const emissionsPromise = firstValueFrom(subjectObservable.pipe(bufferCount(1)));
|
||||
|
||||
sut.send(commandDefinition, { test: 1 });
|
||||
|
||||
const emissions = await emissionsPromise;
|
||||
|
||||
expect(emissions[0]).toEqual({ command: "myCommand", test: 1 });
|
||||
});
|
||||
|
||||
it("will send message with command from normal string", async () => {
|
||||
const emissionsPromise = firstValueFrom(subjectObservable.pipe(bufferCount(1)));
|
||||
|
||||
sut.send("myCommand", { test: 1 });
|
||||
|
||||
const emissions = await emissionsPromise;
|
||||
|
||||
expect(emissions[0]).toEqual({ command: "myCommand", test: 1 });
|
||||
});
|
||||
|
||||
it("will send message with object even if payload not given", async () => {
|
||||
const emissionsPromise = firstValueFrom(subjectObservable.pipe(bufferCount(1)));
|
||||
|
||||
sut.send("myCommand");
|
||||
|
||||
const emissions = await emissionsPromise;
|
||||
|
||||
expect(emissions[0]).toEqual({ command: "myCommand" });
|
||||
});
|
||||
|
||||
it.each([null, undefined])(
|
||||
"will send message with object even if payload is null-ish (%s)",
|
||||
async (payloadValue) => {
|
||||
const emissionsPromise = firstValueFrom(subjectObservable.pipe(bufferCount(1)));
|
||||
|
||||
sut.send("myCommand", payloadValue);
|
||||
|
||||
const emissions = await emissionsPromise;
|
||||
|
||||
expect(emissions[0]).toEqual({ command: "myCommand" });
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user