snap-shot-core
Advanced tools
Comparing version 9.0.0 to 10.0.0
{ | ||
"name": "snap-shot-core", | ||
"description": "Save / load named snapshots, useful for tests", | ||
"version": "9.0.0", | ||
"version": "10.0.0", | ||
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>", | ||
@@ -93,2 +93,3 @@ "bugs": "https://github.com/bahmutov/snap-shot-core/issues", | ||
"devDependencies": { | ||
"@octokit/request-error": "1.0.4", | ||
"ban-sensitive-files": "1.9.2", | ||
@@ -106,7 +107,7 @@ "chdir-promise": "0.6.2", | ||
"pre-git": "3.17.1", | ||
"semantic-release": "15.13.12", | ||
"semantic-release": "15.13.16", | ||
"shelljs": "0.8.3", | ||
"simple-commit-message": "4.0.3", | ||
"sinon": "7.3.2", | ||
"snap-shot-it": "6.3.4", | ||
"snap-shot-it": "6.3.5", | ||
"standard": "12.0.1", | ||
@@ -126,3 +127,3 @@ "stop-only": "2.2.5" | ||
"mkdirp": "0.5.1", | ||
"pluralize": "7.0.0", | ||
"pluralize": "8.0.0", | ||
"quote": "0.4.0", | ||
@@ -129,0 +130,0 @@ "ramda": "0.26.1" |
@@ -39,2 +39,21 @@ [![TODO board](https://imdone.io/api/1.0/projects/5b1adebb4f7fd004e58ef569/badge)](https://imdone.io/app#/board/bahmutov/snap-shot-core) | ||
The returned value contains both the saved value and the snapshot name | ||
```js | ||
let out = snapShot.core({ | ||
what: 42, | ||
exactSpecName: 'my snapshot' | ||
}) | ||
console.log(out) | ||
// {value: 42, key 'my snapshot'} | ||
out = snapShot.core({ | ||
what: 42, | ||
specName: 'my snapshot' | ||
}) | ||
console.log(out) | ||
// auto-increments counter if we are using | ||
// just the spec name | ||
// {value: 42, key 'my snapshot 1'} | ||
``` | ||
## Save folders | ||
@@ -41,0 +60,0 @@ |
@@ -106,2 +106,3 @@ 'use strict' | ||
function fileForSpec (specFile, ext, opts = { useRelativePath: false }) { | ||
la(is.unemptyString(specFile), 'missing spec file', specFile) | ||
la(is.maybe.string(ext), 'invalid extension to find', ext) | ||
@@ -111,2 +112,8 @@ la(isLoadOptions(opts), 'expected fileForSpec options', opts) | ||
const specName = path.basename(specFile) | ||
la( | ||
is.unemptyString(specName), | ||
'could not get spec name from spec file', | ||
specFile | ||
) | ||
const snapshotFolder = getSnapshotsFolder(specFile, opts) | ||
@@ -113,0 +120,0 @@ |
@@ -8,5 +8,8 @@ const R = require('ramda') | ||
/** | ||
* Checks if the snapshot to keep has all information | ||
*/ | ||
const isRunTimeSnapshot = is.schema({ | ||
specName: is.unemptyString, | ||
file: is.unemptyString | ||
specFile: is.unemptyString, | ||
key: is.unemptyString | ||
}) | ||
@@ -20,10 +23,17 @@ | ||
const specNames = R.map(R.prop('specName'), runtimeSnapshots) | ||
debug('have %s before pruning', pluralize('name', specNames.length, true)) | ||
const keys = R.map(R.prop('key'), runtimeSnapshots) | ||
debug( | ||
'have runtime snapshots %s before pruning', | ||
pluralize('name', keys.length, true) | ||
) | ||
if (debug.enabled) { | ||
debug(specNames.sort()) | ||
debug(keys.sort()) | ||
} | ||
// TODO simplify search, since now it is just an equality id:17 | ||
// - <https://github.com/bahmutov/snap-shot-core/issues/267> | ||
// Gleb Bahmutov | ||
// gleb.bahmutov@gmail.com | ||
const isPresent = (val, key) => { | ||
return R.find(specName => key.startsWith(specName))(specNames) | ||
return R.find(k => key === k)(keys) | ||
} | ||
@@ -50,2 +60,5 @@ const prunedSnapshots = R.pickBy(isPresent, snapshots) | ||
const runtimeSnapshots = byFilename[file] | ||
debug('run time snapshots by file') | ||
debug(runtimeSnapshots) | ||
const prunedSnapshots = pruneSnapshotsInObject(runtimeSnapshots, snapshots) | ||
@@ -65,5 +78,10 @@ if (R.equals(prunedSnapshots, snapshots)) { | ||
// https://github.com/bahmutov/snap-shot-core/issues/88 | ||
const pruneSnapshots = (fs) => ({ tests, ext = utils.DEFAULT_EXTENSION }, opts) => { | ||
/** | ||
* Prunes all unused snapshots for given tests. | ||
*/ | ||
const pruneSnapshots = fs => ( | ||
{ tests, ext = utils.DEFAULT_EXTENSION }, | ||
opts | ||
) => { | ||
la(is.array(tests), 'missing tests', tests) | ||
const byFilename = R.groupBy(R.prop('file'), tests) | ||
debug('pruning snapshots') | ||
@@ -73,3 +91,9 @@ debug('run time tests') | ||
Object.keys(byFilename).forEach(pruneSnapshotsInFile({ fs, byFilename, ext }, opts)) | ||
const byFilename = R.groupBy(R.prop('specFile'), tests) | ||
debug('rune time tests by file') | ||
debug(byFilename) | ||
Object.keys(byFilename).forEach( | ||
pruneSnapshotsInFile({ fs, byFilename, ext }, opts) | ||
) | ||
} | ||
@@ -76,0 +100,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44466
969
367
20
+ Addedpluralize@8.0.0(transitive)
- Removedpluralize@7.0.0(transitive)
Updatedpluralize@8.0.0