tapshot v2.2.0
tapshot
Tapshot is a helper module for snapshot testing when you are using tools like tap and tape. Tapshot can be used to test any serializable object.

Install
$ npm install --save-dev tapshotUsage
As of V2, tapshot will not automatically add new snapshots or snapshot files. You'll need to pass the 'update' option to save them. See Updating Snapshots for how to do this.
API
tapshot(tap, object, options)
tapobject or function: A tap class that has theequalandpassmethods. If you're not settingnameinoptions, this also needs to contain a name, which will be provided if you use it within a named subtestobjectany: The object that you want to snapshot. This can be any serializable object. If it is a non-standard object, aserializermust be provided inoptions.optionsobject: The options to run the test with. These are all optional:namestring: The name for the snapshotfilestring: The location of the snapshot file you wish to useserializerstring or function: The serializer for the object provided if it is a non-standard object. If passed as a string, it will call that method on the object, if passed as a function, the funtion will be called with the object as the only argument.updateboolean: If set to true, the snapshot for this test will be updated
tapshot.configure(options)
This will return a tapshot instance that is configured to use the options passed in as defaults. This instance can be used the same as above.
optionsobject: The options to configure the tapshot instance with. These are optional:filestring: The location of the snapshot file you wish to useupdateboolean: If set to true, the snapshots will be updated
Updating Snapshots
If you change the structure of the object being snapshotted, you will need to update your snapshots. There are 3 ways to do this:
update Option
Set the update option when calling tapshot. Like so:
tapshot(t, `console.log('this is a string of text')`, {update: true});This will only update the snapshot for that specific test.
update Configuration Option
Set the update option when calling tapshot.configure(). Like so:
tapshot.configure({update: true});This will update the snapshots for any tests that use that instance.
Examples
const tap = require(`tap`);
const tapshot = require(`tapshot`);
tap.test(`Generated code is as expected`, (t) => {
tapshot(t, `console.log('this is a string of text')`);
t.end();
});const tap = require(`tap`);
const tapshot = require(`tapshot`);
tap.test(`Generated code is as expected`, (t) => {
tapshot(t, `console.log('this is a string of text')`, {name: 'generated-code'});
t.end();
});const tap = require(`tap`);
const tapshot = require(`tapshot`).configure({update: true});
tap.test(`Generated code is as expected`, (t) => {
tapshot(t, `console.log('this is a string of text')`);
t.end();
});License
MIT © Luke Bonaccorsi