mirror of
https://github.com/home-assistant/frontend.git
synced 2025-06-15 06:36:35 +00:00

* Add rspack * Remove TransformAsyncModulesPlugin from rspack * Migrate all webpack usage to rspack * Migrate tests to vitest * Fix test suites * Remove chai dependency * Fix compute_state_display tests * Fix resolveTimeZone * Reduces test pipeline * Revert test ci * optimize chunk filtering * Migrate landing-page to rspack * Update rspack dependencies * Add rsdoctor * Fix prod build bundle size * Use rsdoctor for demo stats * Remove unused webpack configs * Update build-scripts/rspack.cjs Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com> * Fix eslint * Update rspack * Remove unused code --------- Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>
78 lines
1.5 KiB
TypeScript
78 lines
1.5 KiB
TypeScript
import { assert, describe, it, beforeEach } from "vitest";
|
|
|
|
import {
|
|
ExternalMessaging,
|
|
type EMMessage,
|
|
} from "../../src/external_app/external_messaging";
|
|
|
|
// @ts-ignore
|
|
global.__DEV__ = true;
|
|
|
|
class MockExternalMessaging extends ExternalMessaging {
|
|
public mockSent: EMMessage[] = [];
|
|
|
|
protected _sendExternal(msg: EMMessage) {
|
|
this.mockSent.push(msg);
|
|
}
|
|
}
|
|
|
|
describe("ExternalMessaging", () => {
|
|
let bus: MockExternalMessaging;
|
|
|
|
beforeEach(() => {
|
|
bus = new MockExternalMessaging();
|
|
});
|
|
|
|
it("Send success results", async () => {
|
|
const sendMessageProm = bus.sendMessage({
|
|
type: "config/get",
|
|
});
|
|
|
|
assert.equal(bus.mockSent.length, 1);
|
|
assert.deepEqual(bus.mockSent[0], {
|
|
id: 1,
|
|
type: "config/get",
|
|
});
|
|
|
|
bus.receiveMessage({
|
|
id: 1,
|
|
type: "result",
|
|
success: true,
|
|
result: {
|
|
hello: "world",
|
|
},
|
|
});
|
|
|
|
const result = await sendMessageProm;
|
|
assert.deepEqual(result, {
|
|
hello: "world",
|
|
} as any);
|
|
});
|
|
|
|
it("Send fail results", async () => {
|
|
const sendMessageProm = bus.sendMessage({
|
|
type: "config/get",
|
|
});
|
|
|
|
bus.receiveMessage({
|
|
id: 1,
|
|
type: "result",
|
|
success: false,
|
|
error: {
|
|
code: "no_auth",
|
|
message: "There is no authentication.",
|
|
},
|
|
});
|
|
|
|
try {
|
|
await sendMessageProm;
|
|
assert.fail("Should have raised");
|
|
} catch (err: any) {
|
|
assert.deepEqual(err, {
|
|
code: "no_auth",
|
|
message: "There is no authentication.",
|
|
});
|
|
}
|
|
});
|
|
});
|