testFmtKeepsWhatFormattingWouldChange
Fmt: a definition formatting would change (oxfmt breaks JSX text around a {" "}, giving React other children) is
saved as written; the rest of its file, what uses it too, is formatted, with no warning of a tcm bug.
import { okIn, tempDir } from "#codebase/tcmts/cli/test/e2e/harness"; import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; export const testFmtKeepsWhatFormattingWouldChange = () => { const dir = tempDir("fmt jsx"); const tcm = (...args: string[]) => okIn(dir, ...args); tcm("init"); fs.rmSync(path.join(dir, "scratch.ts")); const who = `export const Who = ({ admin }: { admin: boolean }) => <span>signed in as the maintainer of this codebase, the one who merges what is proposed {admin ? <b>yes</b> : null}</span>;`; fs.writeFileSync( path.join(dir, "ui.tsx"), `// tcm: namespace ui\n${who}\nexport const Page = () => <div><Who admin /></div>;\nexport function plain(s:string){return s}\n`, ); const out = tcm("add", "ui.tsx"); assert.doesNotMatch(out, /tcm bug/); assert.match(out, /Who saved as written/); assert.match(tcm("view", "ui.Who"), /merges what is proposed \{admin \?/, "as written"); assert.match( tcm("view", "ui.Page"), /<div>\n {4}<Who admin \/>\n {2}<\/div>/, "what uses it is formatted", ); assert.match(tcm("view", "ui.plain"), /export function plain\(s: string\) \{\n {2}return s;\n\}/); assert.match(tcm("verify"), /rendering and re-hashing is the identity/); }