# test.scripts/core/selectors/manifest.selector.test.ts

> 38 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-scripts-core-selectors-manifest-selector-test-ts
Source text: https://banes-lab.com/source/testing/test.scripts/core/selectors/manifest.selector.test.ts.txt

Listed in [test.scripts/core/selectors](https://banes-lab.com/api/source/testing/test.scripts/core/selectors.md), before [test.scripts/core/selectors/rate.selector.test.ts](https://banes-lab.com/source/testing/test.scripts/core/selectors/rate.selector.test.ts.md).

## Contained in

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

## Source

```typescript
import { describe, expect, it } from "vitest";
import { exportPatternsOf, stringAt, stringRecordAt } from "@project/scripts/core/selectors/manifest.selector.ts";
import { join } from "node:path";
import { manifestOf } from "@project/scripts/core/loaders/manifest.loader.ts";
import { mkdtempSync } from "node:fs";
import { tmpdir } from "node:os";
import { writeVerbatim } from "@govlab/canonical-write";

const ZONE = "zone";
const NAME = "@fixture/member";

const MANIFEST = {
    exports: { ".": `./${ZONE}.ts`, "./*": "./*", [`./${ZONE}/*`]: `./lib/${ZONE}/*`, "./skipped": { default: "x" } },
    main: 42,
    name: NAME,
};

describe("stringAt and stringRecordAt", () => {
    it("read a string field, and the string entries of a nested record, with an empty answer otherwise", () => {
        expect(stringAt(MANIFEST, "name")).toBe(NAME);
        expect(stringAt(MANIFEST, "main")).toBe("");
        expect(stringAt(null, "name")).toBe("");
        expect(stringRecordAt(MANIFEST, "exports")["./skipped"]).toBeUndefined();
        expect(stringRecordAt(MANIFEST, "name")).toStrictEqual({});
    });
});

describe("exportPatternsOf", () => {
    it("keeps the wildcard patterns, longest prefix first", () => {
        expect(exportPatternsOf(MANIFEST)).toStrictEqual([
            [`./${ZONE}/`, `./lib/${ZONE}/*`],
            ["./", "./*"],
        ]);
    });
});

describe("manifestOf", () => {
    it("reads the member's package manifest", () => {
        const root = mkdtempSync(join(tmpdir(), "manifest-"));
        writeVerbatim(join(root, "package.json"), JSON.stringify({ name: NAME }));
        expect(stringAt(manifestOf(root), "name")).toBe(NAME);
    });
});
```
