Approvals.NodeJS
Approval Tests implementation in NodeJS
Install / Use
/learn @approvals/Approvals.NodeJSREADME
Approvals (Approval Tests for Node.js)
<!-- toc -->Contents
- Intro
- Badges
- Integrations
- Getting Started
- Documentation
- CLI
- Simple hello world
- Specify diff reporter (great for C.I.)
- Multiple diff reporters
- Reporters
- Supported Diff Tools
- Configuration
- API
- approvals
- approvals.reporters
- approvals~configure(overrideOptions)
- approvals~getConfig(overrideOptions) ⇒ <code>Object</code>
- approvals~mocha(optionalBaseDir)
- approvals~verifyAndScrub(dirName, testName, data, scrubber, optionsOverride)
- approvals~verify(dirName, testName, data, optionsOverride)
- approvals~verifyAsJSON(dirName, testName, data, optionsOverride)
- approvals~verifyAsJSONAndScrub(dirName, testName, data, scrubber, optionsOverride)
- approvals~verifyWithControl(namer, writer, [reporterFactory], [optionsOverride])
- Source Control
- Contributing
- License<!-- endToc -->
Intro
Approval Tests Library - Capturing Human Intelligence
What is an approval test? Check out a brief overview here or learn more about Approvals at approvaltests.com.
<a name="build-details" />Badges
| Service | Status |
| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Package | |
| Github (Linux, Mac, Windows) |
|
Integrations
- Mocha tests, see the getting-started
- Approvals API (
require('approvals').verify(...)) - Command line Utility
Getting Started
Jest Typescript Starter Project
If you want to jump start a new project, clone the Jest Starter Project
Mocha
Below is a simple getting started using Mocha.
-
Create a project (folder)
mkdir MyProject cd MyProject -
Install approvals
npm install --save-dev approvals -
Install Mocha globally to execute our tests
npm install -g mocha -
Create a sample Mocha test file called
SimpleLogger.test.js.require("approvals").mocha(); describe("When running some tests", function () { it("should be able to use Approvals", function () { var data = "Hello World!"; this.verify(data); // or this.verifyAsJSON(data) }); }); -
Test the file with mocha.
mocha SimpleLogger.test.js -
You should be presented with a diff tool. (if not, you may need to install one?)
Documentation
If using Jest, see more documentation here.
<a name="cli">CLI
Approvals.NodeJS has a version that can be run as a command line tool.
You can check out the Examples section of the below CLI help. Or a blog post introducing the tool here: Approval Tests - Command Line Tool (CLI).
Install Approvals CLI
npm install -g approvals
CLI Help
By running approvals --help
# Usage
`approvals testName [options]`
| Arg | Description |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| \*\*[-f | --forceapproveall]\*\* | Skip the approve step and apply the results to the .approved.txt file (good for a first time run) |
| [--reporter difftool] | supports multiple EX: `--reporter opendiff --reporter gitdiff` |
| [--outdir] | dir to place approval file - defaults to current directory |
| [--verbose] | extra debug info |
| TODO: | We need to extend the supported args to include other approval options. (file an [issue](https://github.com/approvals/Approvals.NodeJS/issues) if you need one that's not here) |
# Examples
## Simple hello world
echo 'Hello World!' | approvals helloWorldTest
## Specify diff reporter (great for C.I.)
echo 'Hello World!' | approvals helloWorldTest --reporter gitdiff
## Multiple diff reporters
echo 'Hello World!' | approvals helloWorldTest --reporter gitdiff --reporter p4merge
<!--END-CLI-DOCS-->
<a name="reporters" />
Reporters
Built-In Reporters
Any of the following reporter may suite your needs. Some support images, some only diffing text, some on mac and linux, some only on windows... Feel free to configure the system to automatically choose your favorite.
Supported Diff Tools
| approval name | Program | Windows | Mac/Linux | Notes |
| --------------- | ---------------------------------------------------------------------------------------------------------------- | :------: | :-------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| beyondcompare | Beyond Compare | ✓ | ✓ | |
| copycommand | git diff (console diff) | ✓ | ✓ | Great for C.I. builds runs. |
| diffmerge | DiffMerge | ✓ | ✓ | |
| donothing | | ✓ | ✓ | This one does what it says - nothing.
Related Skills
gh-issues
341.0kFetch GitHub issues, spawn sub-agents to implement fixes and open PRs, then monitor and address PR review comments. Usage: /gh-issues [owner/repo] [--label bug] [--limit 5] [--milestone v1.0] [--assignee @me] [--fork user/repo] [--watch] [--interval 5] [--reviews-only] [--cron] [--dry-run] [--model glm-5] [--notify-channel -1002381931352]
node-connect
341.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Writing Hookify Rules
84.4kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
