# test.build/core/plugins/server.plugin.test.ts

> 34 lines of code and 0 definitions.

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

Listed in [test.build/core/plugins](https://banes-lab.com/api/source/testing/test.build/core/plugins.md), before [test.build/core/plugins/site.plugin.test.ts](https://banes-lab.com/source/testing/test.build/core/plugins/site.plugin.test.ts.md).

## Contained in

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

## Source

```typescript
import { describe, expect, it, vi } from "vitest";
import { devPortPlugin } from "@banes-lab/build-scripts/core/plugins/server.plugin.ts";

const vault = vi.hoisted(() => ({ reads: 0 }));

vi.mock("@ssot/secrets", () => ({
    portOf: () => {
        vault.reads += 1;
        return 4202;
    },
}));

vi.mock("@banes-lab/build-scripts/core/factories/certificate.factory.ts", () => ({
    devCertificate: async () => {
        await Promise.resolve();
        return { cert: "c", key: "k" };
    },
}));

const configOf = async function configOf(command: "build" | "serve"): Promise<unknown> {
    const { config } = devPortPlugin("SITE_DEV_PORT");
    if (typeof config !== "function") {
        throw new TypeError("the plugin declares no config hook");
    }
    const held: unknown = await Reflect.apply(config, undefined, [{}, { command, mode: "development" }]);
    return held;
};

describe("devPortPlugin", () => {
    it("reads the dev port only when a server starts, so a build or a config load never opens the vault", async () => {
        vault.reads = 0;
        await expect(configOf("build")).resolves.toBeNull();
        expect(vault.reads).toBe(0);
        await expect(configOf("serve")).resolves.toStrictEqual({
            server: { https: { cert: "c", key: "k" }, port: 4202, strictPort: true },
        });
        expect(vault.reads).toBe(1);
    });
});
```
