Skip to content

scalvert/bintastic

Repository files navigation

bintastic

CI Build npm version License

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');
  });
});

Install

npm add bintastic --save-dev

Documentation

Full documentation lives at scalvert.github.io/bintastic:

  • Getting Started — what bintastic is and the quick-start example
  • UsagecreateBintastic options, binPath resolution, writing fixture files, and reading results
  • DebuggingBINTASTIC_DEBUG modes, runBinDebug, and the VS Code launch configuration
  • API Reference — generated type documentation

About

A fantastic way to exercise your binaries in synthetic environments

Resources

License

Stars

Watchers

Forks

Contributors