diff --git a/.vscode/settings.json b/.vscode/settings.json index 51237d60..b97194b8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { "editor.formatOnSave": true, "standard.enable": true, - "workbench.colorTheme": "Abyss" + "workbench.colorTheme": "Activate SCARLET protocol (beta)" } diff --git a/src/file-system.js b/src/file-system.js index 53fe2743..b2886cd7 100644 --- a/src/file-system.js +++ b/src/file-system.js @@ -161,12 +161,16 @@ function loadSnapshots (specFile, ext, opts = { useRelativePath: false }) { function prepareFragments (snapshots, opts = { sortSnapshots: true }) { la(isSaveOptions(opts), 'expected prepare fragments options', opts) - const names = opts.sortSnapshots - ? Object.keys(snapshots).sort() - : Object.keys(snapshots) + const keys = Object.keys(snapshots) + debug( + 'prepare %s, sorted? %d', + pluralize('snapshot', keys.length, true), + opts.sortSnapshots + ) + const names = opts.sortSnapshots ? keys.sort() : keys const fragments = names.map(testName => { - debug(`snapshot name "${testName}"`) + debug(`snapshot fragment name "${testName}"`) const value = snapshots[testName] const escapedName = escapeQuotes(testName) return is.string(value) @@ -209,6 +213,7 @@ function saveSnapshots ( debug('saving snapshots into %s for %s', filename, specRelativeName) debug('snapshots are') debug(snapshots) + debug('saveSnapshots options %o', opts) return maybeSortAndSave(snapshots, filename, opts) } diff --git a/src/prune.js b/src/prune.js index 4a12de02..c5c3527f 100644 --- a/src/prune.js +++ b/src/prune.js @@ -21,34 +21,37 @@ const pruneSnapshotsInObject = (runtimeSnapshots, snapshots) => { const keys = R.map(R.prop('key'), runtimeSnapshots) debug( - 'have runtime snapshots %s before pruning', - pluralize('name', keys.length, true) + 'have runtime %s before pruning', + pluralize('snapshot name', keys.length, true) ) if (debug.enabled) { - debug(keys.sort()) + // make sure NOT to mutate the list of snapshot names + // otherwise we will save the pruned object with keys + // in the sorted order! + debug(keys) + debug('snapshot file keys in the current order') + debug(R.keys(snapshots)) } - // TODO simplify search, since now it is just an equality id:17 - // - - // Gleb Bahmutov - // gleb.bahmutov@gmail.com const isPresent = (val, key) => { - return R.find(k => key === k)(keys) + return R.includes(key, keys) } const prunedSnapshots = R.pickBy(isPresent, snapshots) debug( - 'after pruning remaining %s', - pluralize('name', R.keys(prunedSnapshots).length, true) + 'after pruning %s remaining', + pluralize('snapshot name', R.keys(prunedSnapshots).length, true) ) if (debug.enabled) { - debug(R.keys(prunedSnapshots).sort()) + debug(R.keys(prunedSnapshots)) } return prunedSnapshots } const pruneSnapshotsInFile = ({ fs, byFilename, ext }, opts) => file => { - const snapshots = fs.loadSnapshots(file, ext, opts) + const snapshots = fs.loadSnapshots(file, ext, { + useRelativePath: opts.useRelativePath || false + }) if (is.empty(snapshots)) { debug('empty snapshots to prune in file', file) return @@ -65,7 +68,10 @@ const pruneSnapshotsInFile = ({ fs, byFilename, ext }, opts) => file => { } debug('saving pruned snapshot file for', file) - fs.saveSnapshots(file, prunedSnapshots, ext, opts) + + const saveOptions = R.pick(['sortSnapshots', 'useRelativePath'], opts) + debug('save options %o', saveOptions) + fs.saveSnapshots(file, prunedSnapshots, ext, saveOptions) } // TODO switch to async id:3 @@ -77,7 +83,10 @@ const pruneSnapshotsInFile = ({ fs, byFilename, ext }, opts) => file => { */ const pruneSnapshots = fs => ( { tests, ext = utils.DEFAULT_EXTENSION }, - opts + opts = { + useRelativePath: false, + sortSnapshots: false + } ) => { la(is.array(tests), 'missing tests', tests) debug('pruning snapshots') @@ -85,7 +94,7 @@ const pruneSnapshots = fs => ( debug(tests) const byFilename = R.groupBy(R.prop('specFile'), tests) - debug('rune time tests by file') + debug('run-time tests by file') debug(byFilename) Object.keys(byFilename).forEach(