# test.build/core/loaders/graph.loader.test.ts

> 32 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-build-core-loaders-graph-loader-test-ts
Source text: https://banes-lab.com/source/testing/test.build/core/loaders/graph.loader.test.ts.txt

Listed in [test.build/core/loaders](https://banes-lab.com/api/source/testing/test.build/core/loaders.md), after [test.build/core/loaders/diagram.loader.test.ts](https://banes-lab.com/source/testing/test.build/core/loaders/diagram.loader.test.ts.md) and before [test.build/core/loaders/heritage.loader.test.ts](https://banes-lab.com/source/testing/test.build/core/loaders/heritage.loader.test.ts.md).

## Contained in

- [test.build/core/loaders](https://banes-lab.com/anatomy/testing/folder-testing-test-build-core-loaders.md)

## Source

```typescript
import { describe, expect, it, vi } from "vitest";
import { graphReportEmpty, graphReportMissing } from "@banes-lab/build-scripts/configuration/strings/graph.strings.ts";
import { join } from "node:path";
import { mkdtempSync } from "node:fs";
import { readGraphReport } from "@banes-lab/build-scripts/core/loaders/graph.loader.ts";
import { relativePath } from "@ssot/paths";
import { tmpdir } from "node:os";
import { writeVerbatim } from "@govlab/canonical-write";

const report = vi.hoisted(() => ({ file: "" }));

vi.mock("@banes-lab/build-scripts/core/resolvers/catalog.resolver.ts", async (importOriginal) => ({
    ...(await importOriginal<Record<string, unknown>>()),
    graphReport: () => report.file,
}));

const LOCATION = relativePath("govlabHost.reports.content.graph");

const reportAt = function reportAt(text: string | null): void {
    const dir = mkdtempSync(join(tmpdir(), "banes-lab-graph-"));
    const file = join(dir, "graph.report");
    report.file = file;
    if (text !== null) {
        writeVerbatim(file, text);
    }
};

describe("readGraphReport", () => {
    it("refuses a missing report and one that carries no graph, and returns the graph of a whole one", () => {
        reportAt(null);
        expect(() => readGraphReport()).toThrow(graphReportMissing(LOCATION));
        reportAt('{"graph":{"nodes":[]}}');
        expect(() => readGraphReport()).toThrow(graphReportEmpty(LOCATION));
        reportAt('{"graph":{"edges":[],"nodes":[]}}');
        expect(readGraphReport().graph).toStrictEqual({ edges: [], nodes: [] });
    });
});
```
