snap-shot-core
Advanced tools
Comparing version 1.7.5 to 1.8.0
{ | ||
"name": "snap-shot-core", | ||
"description": "Save / load named snapshots, useful for tests", | ||
"version": "1.7.5", | ||
"version": "1.8.0", | ||
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/bahmutov/snap-shot-core/issues", |
@@ -165,2 +165,12 @@ # snap-shot-core | ||
You can restore / reset a counter for a particular test | ||
```js | ||
const snapShot = require('snap-shot-core') | ||
snapShot.restore({ | ||
file: __filename, | ||
specName: 'this test' | ||
}) | ||
``` | ||
### Small print | ||
@@ -167,0 +177,0 @@ |
@@ -33,4 +33,13 @@ 'use strict' | ||
function restore () { | ||
snapshotsPerTest = {} | ||
function restore (options) { | ||
if (!options) { | ||
debug('restoring all counters') | ||
snapshotsPerTest = {} | ||
} else { | ||
const {file, specName} = options | ||
la(is.unemptyString(file), 'missing file', options) | ||
la(is.unemptyString(specName), 'missing specName', options) | ||
debug('restoring counter for file "%s" test "%s"', file, specName) | ||
delete snapshotsPerTest[specName] | ||
} | ||
} | ||
@@ -119,3 +128,7 @@ | ||
const setOrCheckValue = any => { | ||
const index = snapshotIndex({specName, counters: snapshotsPerTest}) | ||
const index = snapshotIndex({ | ||
counters: snapshotsPerTest, | ||
file: fileParameter, | ||
specName | ||
}) | ||
la(is.positive(index), 'invalid snapshot index', index, | ||
@@ -122,0 +135,0 @@ 'for\n', specName, '\ncounters', snapshotsPerTest) |
@@ -6,5 +6,9 @@ 'use strict' | ||
function snapshotIndex ({counters, specName}) { | ||
// TODO: we should also consider the file spec name + test name | ||
// not just spec name (which is test name here) | ||
function snapshotIndex ({counters, file, specName}) { | ||
la(is.object(counters), 'expected counters', counters) | ||
la(is.unemptyString(specName), 'expected specName', specName) | ||
la(is.unemptyString(file), 'missing filename', file) | ||
if (!(specName in counters)) { | ||
@@ -11,0 +15,0 @@ counters[specName] = 1 |
24208
467
223