# test.govlab/docs/core/analyzers/machine.analyzer.test.ts

> 31 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-govlab-docs-core-analyzers-machine-analyzer-test-ts
Source text: https://banes-lab.com/source/testing/test.govlab/docs/core/analyzers/machine.analyzer.test.ts.txt

Listed in [test.govlab/docs/core/analyzers](https://banes-lab.com/api/source/testing/test.govlab/docs/core/analyzers.md), after [test.govlab/docs/core/analyzers/location.analyzer.test.ts](https://banes-lab.com/source/testing/test.govlab/docs/core/analyzers/location.analyzer.test.ts.md) and before [test.govlab/docs/core/analyzers/markdown.analyzer.test.ts](https://banes-lab.com/source/testing/test.govlab/docs/core/analyzers/markdown.analyzer.test.ts.md).

## Contained in

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

## Source

```typescript
import { afterAll, describe, expect, it } from "vitest";
import { detectState } from "@govlab/docs/core/analyzers/machine.analyzer.ts";
import { programFor } from "./program.fixture.ts";

const fixture = programFor({
    "machine.ts": [
        'export type Kind = "a" | "b" | "c";',
        'export type JobStatus = "idle" | "running" | "done";',
        'export const NEXT = { idle: "running", running: "done", done: "missing" };',
        'export const AGAIN = { idle: "running" };',
    ].join("\n"),
});
const empty = programFor({ "plain.ts": "export const x = 1;\n" });

afterAll(() => {
    fixture.dispose();
    empty.dispose();
});

describe("detectState", () => {
    it("prefers the status-named union and reads each transition once", () => {
        expect(detectState(fixture.analysis)).toStrictEqual({
            initial: "idle",
            states: ["idle", "running", "done"],
            transitions: [
                { from: "idle", to: "running" },
                { from: "running", to: "done" },
            ],
        });
    });

    it("finds no state machine in a module without a string union", () => {
        expect(detectState(empty.analysis)).toBeNull();
    });
});
```
