21 lines
740 B
TypeScript
21 lines
740 B
TypeScript
import { mkdir, writeFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
/**
|
|
* Scenario suites record their measured counters as machine-readable JSON when
|
|
* a scale profile run asks for them (`SCALE_ARTIFACT_DIR`, set by
|
|
* scripts/scale/run-scale-profile.ts). Plain test runs write nothing.
|
|
*/
|
|
export async function recordScaleMetrics(
|
|
name: string,
|
|
metrics: Readonly<Record<string, unknown>>,
|
|
): Promise<void> {
|
|
const directory = process.env["SCALE_ARTIFACT_DIR"];
|
|
if (!directory) return;
|
|
await mkdir(directory, { recursive: true });
|
|
await writeFile(
|
|
path.join(directory, `${name}.json`),
|
|
`${JSON.stringify({ schemaVersion: 1, name, recordedAt: new Date().toISOString(), metrics }, null, 2)}\n`,
|
|
);
|
|
}
|