snap-shot-core
Advanced tools
Comparing version 1.8.0 to 2.0.0
{ | ||
"name": "snap-shot-core", | ||
"description": "Save / load named snapshots, useful for tests", | ||
"version": "1.8.0", | ||
"version": "2.0.0", | ||
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>", | ||
@@ -86,7 +86,7 @@ "bugs": "https://github.com/bahmutov/snap-shot-core/issues", | ||
"dependency-check": "2.9.1", | ||
"deps-ok": "1.2.0", | ||
"deps-ok": "1.2.1", | ||
"dont-crack": "1.2.1", | ||
"git-issues": "1.3.1", | ||
"github-post-release": "1.13.0", | ||
"license-checker": "12.1.0", | ||
"github-post-release": "1.13.1", | ||
"license-checker": "13.0.3", | ||
"mocha": "3.5.0", | ||
@@ -96,10 +96,12 @@ "next-update-travis": "1.7.1", | ||
"pre-git": "3.15.3", | ||
"semantic-release": "^6.3.6", | ||
"semantic-release": "7.0.1", | ||
"simple-commit-message": "3.3.1", | ||
"standard": "8.6.0" | ||
"snap-shot-it": "1.4.0", | ||
"standard": "10.0.3" | ||
}, | ||
"dependencies": { | ||
"check-more-types": "2.24.0", | ||
"debug": "2.6.8", | ||
"debug": "3.0.0", | ||
"escape-quotes": "1.0.2", | ||
"folktale": "2.0.1", | ||
"is-ci": "1.0.10", | ||
@@ -106,0 +108,0 @@ "jsesc": "2.5.1", |
@@ -46,6 +46,3 @@ # snap-shot-core | ||
// value - current original value | ||
const compare = ({expected, value}) => ({ | ||
valid: typeof value === expected, | ||
message: 'check the type' | ||
}) | ||
const compare = ({expected, value}) => // return Result | ||
snapShot({ | ||
@@ -60,25 +57,34 @@ what, | ||
The comparator function needs to compare two values and return an object. | ||
Here is an example | ||
A function to compare expected and actual value should return `Result` | ||
instance, preferably [Folktable.Result][result]. A simple one could be | ||
```js | ||
const compareFn = ({expected, value}) => { | ||
const Result = require('folktale/result') | ||
function compare ({expected, value}) { | ||
const e = JSON.stringify(expected) | ||
const v = JSON.stringify(value) | ||
if (e === v) { | ||
return { | ||
valid: true | ||
} | ||
return Result.Ok() | ||
} | ||
return { | ||
valid: false, | ||
message: `${e} !== ${v}` | ||
} | ||
return Result.Error(`${e} !== ${v}`) | ||
} | ||
``` | ||
The above function will be used by default or you can pass your own function | ||
that expects `({expectd, value})` and returns either `{valid: true}` or | ||
`{valid: false, message: 'to throw as error'}` | ||
Another one, that compares values by type could be even simpler | ||
```js | ||
const sameTypes = (a, b) => | ||
typeof expected === typeof value | ||
const compareTypes = ({expected, value}) => | ||
sameTypes(expected, value) | ||
? Result.Ok() | ||
: Result.Error('types are different') | ||
``` | ||
Note input is an object `{expected, value}` and if there is a difference | ||
you should describe it as a string `Result.Error(<difference string>)` | ||
[result]: http://folktale.origamitower.com/api/v2.0.0/en/folktale.result.html | ||
## Raise function | ||
@@ -105,3 +111,4 @@ | ||
The `snapShotCore` function returns the *expected* value. | ||
If this is the first time, it will be `store(what)` value. Otherwise it will be the loaded `expected` value. | ||
If this is the first time, it will be `store(what)` value. | ||
Otherwise it will be the loaded `expected` value. | ||
@@ -108,0 +115,0 @@ [snap-shot]: https://github.com/bahmutov/snap-shot |
@@ -88,4 +88,3 @@ 'use strict' | ||
const isValidCompareResult = is.schema({ | ||
valid: is.bool, | ||
message: is.maybe.string | ||
orElse: is.fn | ||
}) | ||
@@ -103,8 +102,8 @@ | ||
if (!result.valid) { | ||
result.orElse(message => { | ||
debug('Test "%s" snapshot difference', specName) | ||
la(is.unemptyString(result.message), 'missing result message', result) | ||
console.log(result.message) | ||
throw new Error(result.message) | ||
} | ||
la(is.unemptyString(message), 'missing err string', message) | ||
console.log(message) | ||
throw new Error(message) | ||
}) | ||
} | ||
@@ -111,0 +110,0 @@ |
@@ -5,2 +5,3 @@ 'use strict' | ||
const is = require('check-more-types') | ||
const Result = require('folktale/result') | ||
@@ -35,16 +36,18 @@ // TODO: we should also consider the file spec name + test name | ||
if (e === v) { | ||
return { | ||
valid: true | ||
} | ||
return Result.Ok() | ||
} | ||
return { | ||
valid: false, | ||
message: `${e} !== ${v}` | ||
} | ||
return Result.Error(`${e} !== ${v}`) | ||
} | ||
const sameTypes = (a, b) => typeof expected === typeof value | ||
const compareTypes = ({expected, value}) => | ||
sameTypes(expected, value) ? Result.Ok() : Result.Error('no message') | ||
module.exports = { | ||
snapshotIndex, | ||
strip, | ||
compare | ||
compare, | ||
sameTypes, | ||
compareTypes | ||
} |
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
24726
230
8
15
+ Addedfolktale@2.0.1
+ Addeddebug@3.0.0(transitive)
+ Addedfolktale@2.0.1(transitive)
- Removeddebug@2.6.8(transitive)
Updateddebug@3.0.0