import { assert, describe, it } from "@effect/vitest" import { execFileSync } from "node:child_process" const stackChains = (source: string) => execFileSync(process.execPath, ["stack-chains.mjs", "ts"], { cwd: import.meta.dirname, input: source, encoding: "utf8" }) describe("stack-chains", () => { it("stacks chains of two or more method calls and leaves the rest as written", () => { const input = `const view = h.div.class("a").children( Button(h, { onPress }).class( BUTTON_CLASS ).children("-"), h.header.children("x") ) const steps = scene.fire(a).emitted(b).expect(c) const joined = h .p .class("b").children("c") expect(x).toBe(y) Effect.gen(f).pipe(g) const commented = h.div.class( // spacing ( "a" ).children("b") const fixed = 1 .toFixed().trim().toString() const noted = x.a() /* .b */ .b().c() const first = model.rows.filter(visible)[0].render() ` const expected = `const view = h.div .class("a") .children( Button(h, { onPress }) .class(BUTTON_CLASS) .children("-"), h.header.children("x") ) const steps = scene.fire(a) .emitted(b) .expect(c) const joined = h.p .class("b") .children("c") expect(x).toBe(y) Effect.gen(f).pipe(g) const commented = h.div .class( // spacing ( "a" ) .children("b") const fixed = 1 .toFixed() .trim() .toString() const noted = x.a() /* .b */ .b() .c() const first = model.rows .filter(visible)[0] .render() ` assert.strictEqual(stackChains(input), expected) }) })