// Every chart renders on the server (Next RSC/SSR) and carries the parts the // standard requires: a figure, a caption, a table of the same values, a // link where a point has a source, and nothing that needs a browser to // exist. Rendered to a string: a chart that cannot even render without a // browser breaks every page it is put on. import { test } from "node:test"; import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { createElement as h } from "react"; import { renderToStaticMarkup } from "react-dom/server"; import { BarChart, ColumnChart, DoughnutChart, columnScale, LineChart, Meter, ShareBars, Sparkline, StatTiles, Timeline, } from "../dist/react/index.js"; import { COLUMN_AXIS_WIDTHS } from "../dist/index.js"; const css = readFileSync(new URL("../styles.css", import.meta.url), "utf8"); const points = [ { x: "2025-03-31", y: 29, href: "https://example.com/q1" }, { x: "2025-06-30", y: 29, href: "https://example.com/q2", preliminary: true }, { x: "2025-09-30", y: 33, note: "Converted 7 GW of slots." }, ]; test("LineChart: a figure, a stretched SVG, a point per value as a link, a table behind it", () => { const html = renderToStaticMarkup( h(LineChart, { series: [{ id: "a", label: "Backlog", points }], unit: "GW", caption: "Backlog, GW", }), ); assert.match(html, /