= {} as any;
const el = (
{count + 1}
{isActive ? 1 : 0}
{count * 2}
);
`;
await expect(
transformSource(source, { mode: "error", types }),
).rejects.toThrow(/OpaqueRef transformation errors/);
});
});
describe("debug logging", () => {
it("logs transformation details", async () => {
const logs: string[] = [];
const source = `///
import { OpaqueRef, derive, h } from "commontools";
const count: OpaqueRef = {} as any;
const el = {count + 1}
;
`;
await transformSource(source, {
types,
logger: (msg: string) => logs.push(msg),
});
expect(logs.length).toBeGreaterThan(0);
expect(logs.some((log) => log.includes("TEST TRANSFORMER OUTPUT"))).toBe(
true,
);
});
});
describe("checkWouldTransform", () => {
it("returns true when transformation is needed", async () => {
const source = `///
import { OpaqueRef, h } from "commontools";
const count: OpaqueRef = {} as any;
const el = {count + 1}
;
`;
expect(await transformSource.checkWouldTransform(source, types)).toBe(
true,
);
});
it("returns false when no transformation is needed", async () => {
const source = `
const count: number = 5;
const result = count + 1;
`;
expect(await transformSource.checkWouldTransform(source, types)).toBe(
false,
);
});
});
});