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.

referencesnodejssetup.md

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

Node.js Approvals Setup

Installation

npm install approvals

Mocha Setup

// In your test file or setup file
require('approvals').mocha();

// Or with custom base directory:
require('approvals').mocha('/path/to/approvals');

Mocha Test Example

require('approvals').mocha();

describe('My Feature', function() {
  it('generates correct output', function() {
    const result = generateOutput();
    this.verify(result);
  });

  it('returns correct JSON', function() {
    const data = fetchData();
    this.verifyAsJSON(data);
  });
});

Jest Setup

Import Methods Directly

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

describe('My Feature', () => {
  it('generates correct output', () => {
    verify(generateOutput());
  });

  it('returns correct JSON', () => {
    verifyAsJson(fetchData());
  });
});

Direct API Usage

Without test framework integration:

const approvals = require('approvals');

// Verify a string
approvals.verify(__dirname, 'test_name', 'expected output');

// Verify JSON
approvals.verifyAsJSON(__dirname, 'test_name', { key: 'value' });

Configuration

Global Configuration

const approvals = require('approvals');

approvals.configure({
  reporters: ['vscode', 'p4merge'],
  normalizeLineEndingsTo: '\n',
  appendEOL: true,
});

Home Directory Config

Create ~/.approvalsConfig (YAML or JSON):

reporters:
  - vscode
  - p4merge
normalizeLineEndingsTo: "\n"
appendEOL: true

Per-Test Override

approvals.verify(__dirname, 'test', data, {
  reporters: ['gitdiff'],
  normalizeLineEndingsTo: false
});

Git Configuration

Add to .gitignore:

*.received.*

Add to .gitattributes:

*.approved.* eol=lf

TypeScript Setup

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

// Use directly
verify('Hello World');
verifyAsJson({ key: 'value' });

CI Configuration

For CI environments without diff tools:

approvals.configure({
  reporters: ['copycommand'],  // Just outputs copy command
  // or
  reporters: ['donothing'],    // Silent, just fails
});

Reporters

approvals.configure({
  reporters: ['vscode', 'p4merge', 'gitdiff']
});

For available reporters, MultiReporter, and custom reporters, see reporters.md.

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