fixture-compare
v1.1.0
Published
Compare test fixtures with each other, with strings, and against the results of transforms.
Downloads
8
Maintainers
Readme
fixture-compare
Compare test fixtures with each other, with strings, and against the results of transforms.
Compare a String to a Fixture
import {inputMatchesFile} from 'fixture-compare';
const input = 'some string';
const fixture = 'result.txt'
inputMatchesFile(input, fixture);
Run a Fixture Through a Transform
Loads a fixture, runs it through a transform, then compares the results to a
fixture with the same name, appended with .output
.
import fixtureCompare from 'fixture-compare';
const fixture = 'test-1';
const transform = (text) => text.split('').reverse();
fixtureCompare(fixture, transform);
Run a Fixture Through a Transform, Specify Result Fixture
Same as the previous example, but allows you to specify a different output file.
import fixtureCompare from 'fixture-compare';
const input = 'test-2';
const output = 'test-2.result';
const transform = (text) => text.split('').reverse();
fixtureCompare(input, transform, output);
Specify Fixtures Directory
By default, paths to fixtures are assumed to be relative to {cwd}/test/fixtures
.
To specify another directory...
import {setFixturesDir} from 'fixture-compare';
setFixturesDir(path.join(__dirname, 'somewhere/else'));
Log Differences
To log differences when fixtures do not match, use setLogging
.
import {setLogging} from 'fixture-compare';
setLogging(true);
- expected
+ actual
- \n
"||"
+ \n
snett ik eltt il\n
"++---||++++|----||+++--||"
li ttle ki ttens \n
kickstarted by npm-boom