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

> 31 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-build-core-loaders-diagram-loader-test-ts
Source text: https://banes-lab.com/source/testing/test.build/core/loaders/diagram.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/coordination.loader.test.ts](https://banes-lab.com/source/testing/test.build/core/loaders/coordination.loader.test.ts.md) and before [test.build/core/loaders/graph.loader.test.ts](https://banes-lab.com/source/testing/test.build/core/loaders/graph.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 } from "vitest";
import { discoverSources } from "@banes-lab/build-scripts/core/loaders/diagram.loader.ts";

const FIRST = "flowchart LR\n  a --> b";
const SECOND = "flowchart TD\n  c --> d";

const isModule = function isModule<T>(value: unknown): value is T {
    return typeof value === "object" && value !== null;
};

describe("discoverSources", () => {
    it("imports every strings module through the runner and collects each mermaid source once, sorted", async () => {
        const imported: string[] = [];
        const shared = { kind: "mermaid", text: SECOND };
        const runner = {
            import: async <T>(url: string): Promise<T> => {
                await Promise.resolve();
                imported.push(url);
                const module: unknown = {
                    SECTIONS: [{ blocks: [shared, { kind: "mermaid", text: FIRST }, { kind: "prose", text: "x" }] }],
                    SHARED: shared,
                };
                if (!isModule<T>(module)) {
                    throw new TypeError(url);
                }
                return module;
            },
        };
        const sources = await discoverSources(runner);
        expect(imported.length).toBeGreaterThan(0);
        expect(imported.every((url) => url.endsWith(".strings.ts"))).toBe(true);
        expect(sources).toStrictEqual([FIRST, SECOND]);
    });
});
```
