Note: This package was formerly published as
@scalvert/bin-tester.
Testing a CLI isn't like testing a library—you can't just import functions and call them. You need to spawn your CLI as a subprocess, give it real files to work with, and capture its output. bintastic simplifies this:
import { createBintastic } from 'bintastic';
describe('my-cli', () => {
const { setupProject, teardownProject, runBin } = createBintastic({
importMeta: import.meta,
binPath: './bin/my-cli.js', // resolved relative to this test module
});
let project;
beforeEach(async () => {
project = await setupProject();
});
afterEach(() => {
teardownProject();
});
test('processes files', async () => {
await project.write({ 'input.txt': 'hello' });
const result = await runBin('input.txt');
expect(result.exitCode).toBe(0);
expect(result.stdout).toContain('processed');
});
});npm add bintastic --save-devFull documentation lives at scalvert.github.io/bintastic:
- Getting Started — what bintastic is and the quick-start example
- Usage —
createBintasticoptions,binPathresolution, writing fixture files, and reading results - Debugging —
BINTASTIC_DEBUGmodes,runBinDebug, and the VS Code launch configuration - API Reference — generated type documentation