Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
62 lines
2.2 KiB
TypeScript
62 lines
2.2 KiB
TypeScript
import { describe, expect, it } from "@effect/vitest";
|
|
import { EnvironmentId } from "@t3tools/contracts";
|
|
import * as Effect from "effect/Effect";
|
|
|
|
import {
|
|
loadPreviewWebviewConfig,
|
|
PreviewWebviewBridgeUnavailableError,
|
|
PreviewWebviewConfigLoadError,
|
|
} from "./previewWebviewConfigState";
|
|
|
|
const environmentId = EnvironmentId.make("environment-1");
|
|
|
|
describe("loadPreviewWebviewConfig", () => {
|
|
it.effect("reports a structurally distinct missing-bridge failure", () =>
|
|
Effect.gen(function* () {
|
|
const error = yield* loadPreviewWebviewConfig(environmentId, undefined, null).pipe(
|
|
Effect.flip,
|
|
);
|
|
|
|
expect(error).toBeInstanceOf(PreviewWebviewBridgeUnavailableError);
|
|
expect(error.environmentId).toBe(environmentId);
|
|
expect(error.message).toContain(environmentId);
|
|
expect("cause" in error).toBe(false);
|
|
}),
|
|
);
|
|
|
|
it.effect("preserves the bridge rejection as the load failure cause", () =>
|
|
Effect.gen(function* () {
|
|
const cause = new Error("ipc unavailable");
|
|
const error = yield* loadPreviewWebviewConfig(environmentId, undefined, {
|
|
getPreviewConfig: () => Promise.reject(cause),
|
|
}).pipe(Effect.flip);
|
|
|
|
expect(error).toBeInstanceOf(PreviewWebviewConfigLoadError);
|
|
expect(error.environmentId).toBe(environmentId);
|
|
expect(error.cause).toBe(cause);
|
|
expect(error.message).not.toContain(cause.message);
|
|
}),
|
|
);
|
|
|
|
it.effect("forwards the environment id and profile to the bridge", () =>
|
|
Effect.gen(function* () {
|
|
let requested: { environmentId: EnvironmentId; profileId: string | undefined } | null = null;
|
|
const config = {
|
|
partition: "persist:test-preview",
|
|
webPreferences: "sandbox=yes",
|
|
preloadUrl: null,
|
|
};
|
|
const result = yield* loadPreviewWebviewConfig(environmentId, "work", {
|
|
getPreviewConfig: (requestedEnvironmentId, profileId) => {
|
|
requested = { environmentId: requestedEnvironmentId, profileId };
|
|
return Promise.resolve(config);
|
|
},
|
|
});
|
|
|
|
// The partition is derived in main from both, so both have to arrive.
|
|
expect(requested).toEqual({ environmentId, profileId: "work" });
|
|
expect(result).toEqual(config);
|
|
}),
|
|
);
|
|
});
|