All skills
lexler avatar

/approval-tests

@83aee6a
by Lada Kesselerlexler/skill-factory238 stars
61

Writes approval tests (snapshot/golden master testing) for Python, JavaScript/TypeScript, or Java. Use when verifying complex output, characterization testing legacy code, testing combinations, or working with .approved/.received files.

Use this Skill: https://skilld.dev/gh/lexler/skill-factory/approval-tests

This session only. Nothing lands on disk.

nodejs.md

≈668 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Node.js ApprovalTests

Installation

npm install approvals

Quick Start

Jest

import { verify, verifyAsJson } from 'approvals/lib/Providers/Jest/JestApprovals';

describe('Reports', () => {
  it('generates report', () => {
    const result = generateReport();
    verify(result);
  });
});

Mocha

require('approvals').mocha();

describe('Reports', function() {
  it('generates report', function() {
    this.verify(generateReport());
  });
});

First run: Test fails, .received file created. Review it, approve it (copy to .approved), rerun.

Common Imports

Jest

import { verify, verifyAsJson, verifyAll } from 'approvals/lib/Providers/Jest/JestApprovals';
import { verifyAllCombinations2 } from 'approvals/lib/Providers/Jest/CombinationApprovals';
import { Options } from 'approvals/lib/Core/Options';

Mocha/Other

const approvals = require('approvals');

Core Patterns

verify() - Basic verification

verify(result);
approvals.verify(__dirname, 'test_name', result);

verifyAsJson() - Objects as formatted JSON

verifyAsJson(user);
approvals.verifyAsJSON(__dirname, 'test_name', user);

verifyAll() - Collections with labels

verifyAll('Users', users, (u) => `${u.name}: ${u.email}`);

Scrubbing

approvals.verifyAndScrub(
  __dirname, 'test_name', result,
  (text) => text.replace(/\d{4}-\d{2}-\d{2}/, '<DATE>')
);

State Progressions (Storyboard pattern)

No built-in class, but implement via string building:

let story = '';
story += 'Initial:\n' + game.toString() + '\n\n';
game.advance();
story += 'After move:\n' + game.toString() + '\n\n';
game.pickUp('sword');
story += 'After pickup:\n' + game.toString();
verify(story);

Node.js-Specific Notes

__dirname required - Mocha/raw API needs directory path for file location.

Jest integration - Cleaner API without __dirname, auto-detects test name.

TypeScript - Full type definitions included.

Git Setup

*.received.*

Commit all .approved.* files.

Reference Files

  • api.md - All verify functions, Options, combinations, Namer/Writer interfaces
  • scrubbers.md - GUIDs, dates, regex patterns, combining scrubbers
  • reporters.md - Diff tools, MultiReporter, custom reporters
  • setup.md - Mocha/Jest setup, CI config
  • inline.md - Not supported; alternatives (Jest snapshots, assertions)

Source: SKILL.md on GitHub

1 warning6d4 checks · Risk SAFE
  • Gen Agent Trust Hub6d

    The skill provides instructions and patterns for implementing approval testing (snapshot testing) across multiple programming languages. It includes capabilities for file system operations, command execution for testing CLI tools, and launching external diff reporters, which are consistent with the skill's purpose. The analysis identified an indirect prompt injection surface when verifying external or untrusted data.

  • Socket6d

    No alerts

  • Snyk6d

    Risk: LOW · No issues

  • Runlayer7mo

    25/25 files flagged

Signed by skilld at 83aee6a. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 8 months ago

README badge

README badge for lexler/skill-factory/approval-tests