# test.govlab/quality/core/loaders/coverage.loader.test.ts

> 34 lines of code and 0 definitions.

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

Listed in [test.govlab/quality/core/loaders](https://banes-lab.com/api/source/testing/test.govlab/quality/core/loaders.md), after [test.govlab/quality/core/loaders/config.loader.test.ts](https://banes-lab.com/source/testing/test.govlab/quality/core/loaders/config.loader.test.ts.md) and before [test.govlab/quality/core/loaders/dependency.loader.test.ts](https://banes-lab.com/source/testing/test.govlab/quality/core/loaders/dependency.loader.test.ts.md).

## Contained in

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

## Source

```typescript
import { centralIndexFor, packageIndexFor } from "@govlab/quality/core/loaders/coverage.loader.ts";
import { expect, test } from "vitest";
import { mkdirSync, mkdtempSync } from "node:fs";
import { ROOT } from "@ssot/paths/anchor";
import { join } from "node:path";
import { relativePath } from "@ssot/paths";
import { tmpdir } from "node:os";
import { wordIncludes } from "@govlab/quality/core/matchers/word.matcher.ts";
import { writeVerbatim } from "@govlab/canonical-write";

const coordination = join(ROOT, relativePath("app.coordination")).split("\\").join("/");

test("centralIndexFor returns an empty index when the declared test root does not exist", () => {
    expect(centralIndexFor(join(ROOT, "no-such-test-root"), ROOT).size).toBe(0);
});

test("centralIndexFor maps a centralized test root onto the members its tests import", () => {
    const index = centralIndexFor(join(ROOT, relativePath("codebase.testing")), ROOT);
    expect(index.size).toBeGreaterThan(0);
});

test("centralIndexFor credits a test to the nested package its package subpath lands in", () => {
    const index = centralIndexFor(join(ROOT, relativePath("codebase.testing")), ROOT);
    expect(wordIncludes(index.get(`${coordination}/tools`) ?? "", "declaresLead")).toBe(true);
});

test("packageIndexFor credits a package's tests to every nested package they import", () => {
    const outer = mkdtempSync(join(tmpdir(), "coverage-package-")).split("\\").join("/");
    mkdirSync(join(outer, "tools"));
    mkdirSync(join(outer, "spec"));
    writeVerbatim(join(outer, "package.json"), "{}");
    writeVerbatim(join(outer, "tools", "package.json"), "{}");
    writeVerbatim(
        join(outer, "spec", "standing.test.ts"),
        'import { claimStanding } from "../tools/core/standing.ts";\nclaimStanding();\n',
    );
    const credited = packageIndexFor(outer).get(`${outer}/tools`) ?? "";
    expect(wordIncludes(credited, "claimStanding")).toBe(true);
});
```
