# test.rules/shared/loaders/index.loader.test.ts

> 16 lines of code and 0 definitions.

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

Listed in [test.rules/shared/loaders](https://banes-lab.com/api/source/testing/test.rules/shared/loaders.md), after [test.rules/shared/loaders/graph.loader.test.ts](https://banes-lab.com/source/testing/test.rules/shared/loaders/graph.loader.test.ts.md) and before [test.rules/shared/loaders/manifest.loader.test.ts](https://banes-lab.com/source/testing/test.rules/shared/loaders/manifest.loader.test.ts.md).

## Contained in

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

## Source

```typescript
import { buildTreeIndex, resolvesAgainst } from "@ssot/govlab/shared/loaders/index.loader.ts";
import { describe, expect, it } from "vitest";
import { relativePath } from "@ssot/paths";

describe("buildTreeIndex and resolvesAgainst", () => {
    const index = buildTreeIndex();

    it("indexes the tree's paths and basenames, the rule host's labels included", () => {
        expect(index.paths.length).toBeGreaterThan(0);
        expect(index.basenames.has("package.json")).toBe(true);
        expect(index.paths.some((p) => p.startsWith("local/"))).toBe(true);
    });

    it("resolves a declared path by prefix and by basename and refuses an absent one", () => {
        expect(resolvesAgainst(index, relativePath("govlabHost.shared"))).toBe(true);
        expect(resolvesAgainst(index, "paths.yaml")).toBe(true);
        expect(resolvesAgainst(index, "nowhere/at/all")).toBe(false);
    });
});
```
