exampleDir

tcmts.cli.test.e2e.examples.exampleDir · #fq4stros · term · runs on the server

uses node:path

An example's files, as the codebase keeps them, written to a directory of their own: its setup script runs from there. By path in the example.

import { tempDir } from "#codebase/tcmts/cli/test/e2e/harness";
import fs from "node:fs";
import path from "node:path";

export function exampleDir(files: Record<string, string | Uint8Array>): string {
  const dir = tempDir("example");
  for (const [rel, text] of Object.entries(files)) {
    const file = path.join(dir, rel);
    fs.mkdirSync(path.dirname(file), { recursive: true });
    fs.writeFileSync(file, text, { mode: rel.endsWith(".sh") ? 0o755 : 0o644 });
  }
  return dir;
}

uses

used by