# test.govlab/quality/core/adapters/invocation.adapter.test.ts

> 18 lines of code and 0 definitions.

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

Listed in [test.govlab/quality/core/adapters](https://banes-lab.com/api/source/testing/test.govlab/quality/core/adapters.md), after [test.govlab/quality/core/adapters/eslint.adapter.test.ts](https://banes-lab.com/source/testing/test.govlab/quality/core/adapters/eslint.adapter.test.ts.md) and before [test.govlab/quality/core/adapters/remote.adapter.test.ts](https://banes-lab.com/source/testing/test.govlab/quality/core/adapters/remote.adapter.test.ts.md).

## Contained in

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

## Source

```typescript
import { commandOutput, commandVersion, spawnTool } from "@govlab/quality/core/adapters/invocation.adapter.ts";
import { expect, test } from "vitest";
import process from "node:process";
import { signalKilled } from "@govlab/quality/core/predicates/failure.predicate.ts";

test("spawnTool runs a binary synchronously and captures its output", () => {
    const result = spawnTool(process.execPath, ["-e", "process.stdout.write('ok')"], { encoding: "utf8" });
    expect(signalKilled(result.status)).toBe(false);
    expect(result.status).toBe(0);
    expect(result.stdout).toBe("ok");
});

test("commandOutput returns a successful command's stdout and throws on a failed one", () => {
    expect(commandOutput(process.execPath, ["-e", "process.stdout.write('rules')"])).toBe("rules");
    expect(() => commandOutput(process.execPath, ["-e", "process.exit(2)"])).toThrow("failed");
});

test("commandVersion reads the first output line and answers unknown for a failed command", () => {
    expect(commandVersion(process.execPath, ["-e", String.raw`process.stdout.write('1.2.3\nmore')`])).toBe("1.2.3");
    expect(commandVersion(process.execPath, ["-e", "process.exit(1)"])).toBe("unknown");
});
```
