Skip to content

ptol/casefile-runner

Repository files navigation

casefile-runner

What It Is

casefile-runner helps you test CLI-style behavior using a single .case.yaml file that contains:

  • CLI args
  • Virtual input files
  • Expected stdout and/or stderr

Install

npm install casefile-runner

Quick Example

Case File

args:
  - input/a.txt
input/a.txt: |
  hello
stdout: |
  hello
stderr: |
  warning: demo stderr line

Test

import { executeCasefileFile } from 'casefile-runner';

const result = await executeCasefileFile('example.case.yaml', async (files, args) => {
  const fileMap = new Map(files.map((item) => [item.path, item.content]));
  const content = fileMap.get(args[0] ?? '') ?? '';

  return {
    stdout: content,
    stderr: 'warning: demo stderr line\n',
    exitCode: 0
  };
});

API

  • parseCasefile(source) parses raw YAML fixture text.
  • loadCasefile(path) reads and parses a fixture file from disk.
  • runCasefile(testCase, executor) runs an already-parsed case.
  • executeCasefileFile(path, executor, options) reads, runs, and optionally updates expected output.

Updating Expected Output

Pass updateExpected: true to rewrite stdout/stderr sections from actual output:

await executeCasefileFile(casePath, executor, { updateExpected: true });

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors