jest-snapshot
Advanced tools
Comparing version 22.4.0 to 22.4.3
'use strict'; | ||
var _fs = require('fs'); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
var _path = require('path'); | ||
var _path2 = _interopRequireDefault(_path); | ||
var _jestDiff = require('jest-diff'); | ||
var _jestDiff2 = _interopRequireDefault(_jestDiff); | ||
var _jestMatcherUtils = require('jest-matcher-utils'); | ||
var _State = require('./State'); | ||
var _State2 = _interopRequireDefault(_State); | ||
var _plugins = require('./plugins'); | ||
var _utils = require('./utils'); | ||
var _fs = require('fs');var _fs2 = _interopRequireDefault(_fs); | ||
var _path = require('path');var _path2 = _interopRequireDefault(_path); | ||
var _jestDiff = require('jest-diff');var _jestDiff2 = _interopRequireDefault(_jestDiff); | ||
var _jestMatcherUtils = require('jest-matcher-utils'); | ||
var _State = require('./State');var _State2 = _interopRequireDefault(_State); | ||
var _plugins = require('./plugins'); | ||
var _utils = require('./utils');var utils = _interopRequireWildcard(_utils);function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;} else {var newObj = {};if (obj != null) {for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];}}newObj.default = obj;return newObj;}}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/const fileExists = (filePath, hasteFS) => hasteFS.exists(filePath) || _fs2.default.existsSync(filePath);const cleanup = (hasteFS, update) => {const pattern = '\\.' + utils.SNAPSHOT_EXTENSION + '$';const files = hasteFS.matchFiles(pattern); | ||
const filesRemoved = files. | ||
filter( | ||
snapshotFile => | ||
!fileExists( | ||
_path2.default.resolve( | ||
_path2.default.dirname(snapshotFile), | ||
'..', | ||
_path2.default.basename(snapshotFile, '.' + utils.SNAPSHOT_EXTENSION)), | ||
var utils = _interopRequireWildcard(_utils); | ||
hasteFS)). | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
map(snapshotFile => { | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/ | ||
const fileExists = (filePath, hasteFS) => hasteFS.exists(filePath) || _fs2.default.existsSync(filePath); | ||
const cleanup = (hasteFS, update) => { | ||
const pattern = '\\.' + utils.SNAPSHOT_EXTENSION + '$'; | ||
const files = hasteFS.matchFiles(pattern); | ||
const filesRemoved = files.filter(snapshotFile => !fileExists(_path2.default.resolve(_path2.default.dirname(snapshotFile), '..', _path2.default.basename(snapshotFile, '.' + utils.SNAPSHOT_EXTENSION)), hasteFS)).map(snapshotFile => { | ||
if (update === 'all') { | ||
@@ -47,11 +52,14 @@ _fs2.default.unlinkSync(snapshotFile); | ||
return { | ||
filesRemoved }; | ||
filesRemoved | ||
}; | ||
}; | ||
const toMatchSnapshot = function (received, testName) { | ||
this.dontThrow && this.dontThrow();const | ||
this.dontThrow && this.dontThrow(); | ||
currentTestName = this.currentTestName,isNot = this.isNot,snapshotState = this.snapshotState; | ||
const currentTestName = this.currentTestName, | ||
isNot = this.isNot, | ||
snapshotState = this.snapshotState; | ||
if (isNot) { | ||
@@ -65,10 +73,8 @@ throw new Error('Jest: `.not` cannot be used with `.toMatchSnapshot()`.'); | ||
const result = snapshotState.match( | ||
testName && currentTestName ? | ||
`${currentTestName}: ${testName}` : | ||
currentTestName || '', | ||
received);const | ||
const result = snapshotState.match(testName && currentTestName ? `${currentTestName}: ${testName}` : currentTestName || '', received); | ||
const count = result.count, | ||
pass = result.pass; | ||
let actual = result.actual, | ||
expected = result.expected; | ||
count = result.count,pass = result.pass;let | ||
actual = result.actual,expected = result.expected; | ||
@@ -79,9 +85,3 @@ let report; | ||
} else if (!expected) { | ||
report = () => | ||
`New snapshot was ${(0, _jestMatcherUtils.RECEIVED_COLOR)('not written')}. The update flag ` + | ||
`must be explicitly passed to write a new snapshot.\n\n` + | ||
`This is likely because this test is run in a continuous integration ` + | ||
`(CI) environment in which snapshots are not written by default.\n\n` + | ||
`${(0, _jestMatcherUtils.RECEIVED_COLOR)('Received value')} ` + | ||
`${actual}`; | ||
report = () => `New snapshot was ${(0, _jestMatcherUtils.RECEIVED_COLOR)('not written')}. The update flag ` + `must be explicitly passed to write a new snapshot.\n\n` + `This is likely because this test is run in a continuous integration ` + `(CI) environment in which snapshots are not written by default.\n\n` + `${(0, _jestMatcherUtils.RECEIVED_COLOR)('Received value')} ` + `${actual}`; | ||
} else { | ||
@@ -93,12 +93,6 @@ expected = (expected || '').trim(); | ||
bAnnotation: 'Received', | ||
expand: snapshotState.expand }); | ||
expand: snapshotState.expand | ||
}); | ||
report = () => | ||
`${(0, _jestMatcherUtils.RECEIVED_COLOR)('Received value')} does not match ` + | ||
`${(0, _jestMatcherUtils.EXPECTED_COLOR)('stored snapshot ' + count)}.\n\n` + ( | ||
diffMessage || | ||
(0, _jestMatcherUtils.EXPECTED_COLOR)('- ' + (expected || '')) + | ||
'\n' + | ||
(0, _jestMatcherUtils.RECEIVED_COLOR)('+ ' + actual)); | ||
report = () => `${(0, _jestMatcherUtils.RECEIVED_COLOR)('Received value')} does not match ` + `${(0, _jestMatcherUtils.EXPECTED_COLOR)('stored snapshot ' + count)}.\n\n` + (diffMessage || (0, _jestMatcherUtils.EXPECTED_COLOR)('- ' + (expected || '')) + '\n' + (0, _jestMatcherUtils.RECEIVED_COLOR)('+ ' + actual)); | ||
} | ||
@@ -111,23 +105,17 @@ // Passing the the actual and expected objects so that a custom reporter | ||
expected, | ||
message: () => | ||
(0, _jestMatcherUtils.matcherHint)('.toMatchSnapshot', 'value', '') + '\n\n' + report(), | ||
message: () => (0, _jestMatcherUtils.matcherHint)('.toMatchSnapshot', 'value', '') + '\n\n' + report(), | ||
name: 'toMatchSnapshot', | ||
pass: false, | ||
report }; | ||
report | ||
}; | ||
}; | ||
const toThrowErrorMatchingSnapshot = function ( | ||
received, | ||
testName, | ||
fromPromise) | ||
{ | ||
this.dontThrow && this.dontThrow();const | ||
const toThrowErrorMatchingSnapshot = function (received, testName, fromPromise) { | ||
this.dontThrow && this.dontThrow(); | ||
isNot = this.isNot; | ||
const isNot = this.isNot; | ||
if (isNot) { | ||
throw new Error( | ||
'Jest: `.not` cannot be used with `.toThrowErrorMatchingSnapshot()`.'); | ||
throw new Error('Jest: `.not` cannot be used with `.toThrowErrorMatchingSnapshot()`.'); | ||
} | ||
@@ -148,8 +136,3 @@ | ||
if (error === undefined) { | ||
throw new Error( | ||
(0, _jestMatcherUtils.matcherHint)('.toThrowErrorMatchingSnapshot', '() => {}', '') + | ||
'\n\n' + | ||
`Expected the function to throw an error.\n` + | ||
`But it didn't throw anything.`); | ||
throw new Error((0, _jestMatcherUtils.matcherHint)('.toThrowErrorMatchingSnapshot', '() => {}', '') + '\n\n' + `Expected the function to throw an error.\n` + `But it didn't throw anything.`); | ||
} | ||
@@ -168,2 +151,3 @@ | ||
toThrowErrorMatchingSnapshot, | ||
utils }; | ||
utils | ||
}; |
@@ -1,20 +0,7 @@ | ||
'use strict';Object.defineProperty(exports, "__esModule", { value: true }); | ||
'use strict'; | ||
const serialize = exports.serialize = ( | ||
val, | ||
config, | ||
indentation, | ||
depth, | ||
refs, | ||
printer) => | ||
{ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
const serialize = exports.serialize = (val, config, indentation, depth, refs, printer) => { | ||
// Serialize a non-default name, even if config.printFunctionName is false. | ||
@@ -27,12 +14,3 @@ const name = val.getMockName(); | ||
const indentationNext = indentation + config.indent; | ||
callsString = | ||
' {' + | ||
config.spacingOuter + | ||
indentationNext + | ||
'"calls": ' + | ||
printer(val.mock.calls, config, indentationNext, depth, refs) + ( | ||
config.min ? '' : ',') + | ||
config.spacingOuter + | ||
indentation + | ||
'}'; | ||
callsString = ' {' + config.spacingOuter + indentationNext + '"calls": ' + printer(val.mock.calls, config, indentationNext, depth, refs) + (config.min ? '' : ',') + config.spacingOuter + indentation + '}'; | ||
} | ||
@@ -48,2 +26,6 @@ | ||
* | ||
*/const test = exports.test = val => val && !!val._isMockFunction;exports.default = { serialize, test }; | ||
*/ | ||
const test = exports.test = val => val && !!val._isMockFunction; | ||
exports.default = { serialize, test }; |
@@ -1,32 +0,36 @@ | ||
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.getSerializers = exports.addSerializer = undefined; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.getSerializers = exports.addSerializer = undefined; | ||
var _prettyFormat = require('pretty-format'); | ||
var _prettyFormat2 = _interopRequireDefault(_prettyFormat); | ||
var _mock_serializer = require('./mock_serializer'); | ||
var _mock_serializer2 = _interopRequireDefault(_mock_serializer); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _prettyFormat$plugins = _prettyFormat2.default.plugins; /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/ | ||
const DOMCollection = _prettyFormat$plugins.DOMCollection, | ||
DOMElement = _prettyFormat$plugins.DOMElement, | ||
Immutable = _prettyFormat$plugins.Immutable, | ||
ReactElement = _prettyFormat$plugins.ReactElement, | ||
ReactTestComponent = _prettyFormat$plugins.ReactTestComponent; | ||
var _prettyFormat = require('pretty-format');var _prettyFormat2 = _interopRequireDefault(_prettyFormat); | ||
var _mock_serializer = require('./mock_serializer');var _mock_serializer2 = _interopRequireDefault(_mock_serializer);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}var _prettyFormat$plugins = | ||
let PLUGINS = [ReactTestComponent, ReactElement, DOMElement, DOMCollection, Immutable, _mock_serializer2.default]; | ||
_prettyFormat2.default.plugins; /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/const DOMCollection = _prettyFormat$plugins.DOMCollection,DOMElement = _prettyFormat$plugins.DOMElement,Immutable = _prettyFormat$plugins.Immutable,ReactElement = _prettyFormat$plugins.ReactElement,ReactTestComponent = _prettyFormat$plugins.ReactTestComponent;let PLUGINS = [ReactTestComponent, ReactElement, DOMElement, DOMCollection, Immutable, _mock_serializer2.default]; | ||
// Prepend to list so the last added is the first tested. | ||
@@ -33,0 +37,0 @@ const addSerializer = exports.addSerializer = plugin => { |
@@ -1,49 +0,25 @@ | ||
'use strict';Object.defineProperty(exports, "__esModule", { value: true }); | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _fs = require('fs'); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
var _utils = require('./utils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _fs = require('fs');var _fs2 = _interopRequireDefault(_fs); | ||
var _utils = require('./utils');function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} | ||
class SnapshotState { | ||
constructor(testPath, options) { | ||
this._snapshotPath = options.snapshotPath || (0, _utils.getSnapshotPath)(testPath); | ||
var _getSnapshotData = (0, _utils.getSnapshotData)(this._snapshotPath, options.updateSnapshot); | ||
const data = _getSnapshotData.data, | ||
dirty = _getSnapshotData.dirty; | ||
constructor(testPath, options) { | ||
this._snapshotPath = options.snapshotPath || (0, _utils.getSnapshotPath)(testPath);var _getSnapshotData = | ||
(0, _utils.getSnapshotData)( | ||
this._snapshotPath, | ||
options.updateSnapshot);const data = _getSnapshotData.data,dirty = _getSnapshotData.dirty; | ||
this._snapshotData = data; | ||
@@ -79,5 +55,5 @@ this._dirty = dirty; | ||
deleted: false, | ||
saved: false }; | ||
saved: false | ||
}; | ||
if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) { | ||
@@ -144,7 +120,3 @@ (0, _utils.saveSnapshotFile)(this._snapshotData, this._snapshotPath); | ||
// * There's no snapshot file or a file without this snapshot on a CI environment. | ||
if ( | ||
hasSnapshot && this._updateSnapshot === 'all' || | ||
(!hasSnapshot || !_fs2.default.existsSync(this._snapshotPath)) && ( | ||
this._updateSnapshot === 'new' || this._updateSnapshot === 'all')) | ||
{ | ||
if (hasSnapshot && this._updateSnapshot === 'all' || (!hasSnapshot || !_fs2.default.existsSync(this._snapshotPath)) && (this._updateSnapshot === 'new' || this._updateSnapshot === 'all')) { | ||
if (this._updateSnapshot === 'all') { | ||
@@ -170,4 +142,4 @@ if (!pass) { | ||
expected: '', | ||
pass: true }; | ||
pass: true | ||
}; | ||
} else { | ||
@@ -180,4 +152,4 @@ if (!pass) { | ||
expected: expected ? (0, _utils.unescape)(expected) : null, | ||
pass: false }; | ||
pass: false | ||
}; | ||
} else { | ||
@@ -189,13 +161,15 @@ this.matched++; | ||
expected: '', | ||
pass: true }; | ||
pass: true | ||
}; | ||
} | ||
} | ||
}}exports.default = SnapshotState; /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/ | ||
} | ||
} | ||
exports.default = SnapshotState; /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/ |
@@ -1,33 +0,53 @@ | ||
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.saveSnapshotFile = exports.ensureDirectoryExists = exports.unescape = exports.serialize = exports.getSnapshotData = exports.getSnapshotPath = exports.keyToTestName = exports.testNameToKey = exports.SNAPSHOT_VERSION_WARNING = exports.SNAPSHOT_GUIDE_LINK = exports.SNAPSHOT_VERSION = exports.SNAPSHOT_EXTENSION = undefined; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.saveSnapshotFile = exports.ensureDirectoryExists = exports.unescape = exports.serialize = exports.getSnapshotData = exports.getSnapshotPath = exports.keyToTestName = exports.testNameToKey = exports.SNAPSHOT_VERSION_WARNING = exports.SNAPSHOT_GUIDE_LINK = exports.SNAPSHOT_VERSION = exports.SNAPSHOT_EXTENSION = undefined; | ||
var _plugins = require('./plugins'); | ||
var _chalk = require('chalk'); | ||
var _chalk2 = _interopRequireDefault(_chalk); | ||
var _fs = require('fs'); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
var _mkdirp = require('mkdirp'); | ||
var _mkdirp2 = _interopRequireDefault(_mkdirp); | ||
var _naturalCompare = require('natural-compare'); | ||
var _plugins = require('./plugins'); | ||
var _chalk = require('chalk');var _chalk2 = _interopRequireDefault(_chalk); | ||
var _fs = require('fs');var _fs2 = _interopRequireDefault(_fs); | ||
var _mkdirp = require('mkdirp');var _mkdirp2 = _interopRequireDefault(_mkdirp); | ||
var _naturalCompare = require('natural-compare');var _naturalCompare2 = _interopRequireDefault(_naturalCompare); | ||
var _path = require('path');var _path2 = _interopRequireDefault(_path); | ||
var _prettyFormat = require('pretty-format');var _prettyFormat2 = _interopRequireDefault(_prettyFormat);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/const SNAPSHOT_EXTENSION = exports.SNAPSHOT_EXTENSION = 'snap';const SNAPSHOT_VERSION = exports.SNAPSHOT_VERSION = '1';const SNAPSHOT_VERSION_REGEXP = /^\/\/ Jest Snapshot v(.+),/;const SNAPSHOT_GUIDE_LINK = exports.SNAPSHOT_GUIDE_LINK = 'https://goo.gl/fbAQLP';const SNAPSHOT_VERSION_WARNING = exports.SNAPSHOT_VERSION_WARNING = _chalk2.default.yellow(`${_chalk2.default.bold('Warning')}: Before you upgrade snapshots, ` + | ||
`we recommend that you revert any local changes to tests or other code, ` + | ||
`to ensure that you do not store invalid state.`); | ||
var _naturalCompare2 = _interopRequireDefault(_naturalCompare); | ||
var _path = require('path'); | ||
const writeSnapshotVersion = () => | ||
`// Jest Snapshot v${SNAPSHOT_VERSION}, ${SNAPSHOT_GUIDE_LINK}`; | ||
var _path2 = _interopRequireDefault(_path); | ||
var _prettyFormat = require('pretty-format'); | ||
var _prettyFormat2 = _interopRequireDefault(_prettyFormat); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/ | ||
const SNAPSHOT_EXTENSION = exports.SNAPSHOT_EXTENSION = 'snap'; | ||
const SNAPSHOT_VERSION = exports.SNAPSHOT_VERSION = '1'; | ||
const SNAPSHOT_VERSION_REGEXP = /^\/\/ Jest Snapshot v(.+),/; | ||
const SNAPSHOT_GUIDE_LINK = exports.SNAPSHOT_GUIDE_LINK = 'https://goo.gl/fbAQLP'; | ||
const SNAPSHOT_VERSION_WARNING = exports.SNAPSHOT_VERSION_WARNING = _chalk2.default.yellow(`${_chalk2.default.bold('Warning')}: Before you upgrade snapshots, ` + `we recommend that you revert any local changes to tests or other code, ` + `to ensure that you do not store invalid state.`); | ||
const writeSnapshotVersion = () => `// Jest Snapshot v${SNAPSHOT_VERSION}, ${SNAPSHOT_GUIDE_LINK}`; | ||
const validateSnapshotVersion = snapshotContents => { | ||
@@ -38,39 +58,11 @@ const versionTest = SNAPSHOT_VERSION_REGEXP.exec(snapshotContents); | ||
if (!version) { | ||
return new Error( | ||
_chalk2.default.red( | ||
`${_chalk2.default.bold('Outdated snapshot')}: No snapshot header found. ` + | ||
`Jest 19 introduced versioned snapshots to ensure all developers ` + | ||
`on a project are using the same version of Jest. ` + | ||
`Please update all snapshots during this upgrade of Jest.\n\n`) + | ||
SNAPSHOT_VERSION_WARNING); | ||
return new Error(_chalk2.default.red(`${_chalk2.default.bold('Outdated snapshot')}: No snapshot header found. ` + `Jest 19 introduced versioned snapshots to ensure all developers ` + `on a project are using the same version of Jest. ` + `Please update all snapshots during this upgrade of Jest.\n\n`) + SNAPSHOT_VERSION_WARNING); | ||
} | ||
if (version < SNAPSHOT_VERSION) { | ||
return new Error( | ||
_chalk2.default.red( | ||
`${_chalk2.default.red.bold('Outdated snapshot')}: The version of the snapshot ` + | ||
`file associated with this test is outdated. The snapshot file ` + | ||
`version ensures that all developers on a project are using ` + | ||
`the same version of Jest. ` + | ||
`Please update all snapshots during this upgrade of Jest.\n\n`) + | ||
`Expected: v${SNAPSHOT_VERSION}\n` + | ||
`Received: v${version}\n\n` + | ||
SNAPSHOT_VERSION_WARNING); | ||
return new Error(_chalk2.default.red(`${_chalk2.default.red.bold('Outdated snapshot')}: The version of the snapshot ` + `file associated with this test is outdated. The snapshot file ` + `version ensures that all developers on a project are using ` + `the same version of Jest. ` + `Please update all snapshots during this upgrade of Jest.\n\n`) + `Expected: v${SNAPSHOT_VERSION}\n` + `Received: v${version}\n\n` + SNAPSHOT_VERSION_WARNING); | ||
} | ||
if (version > SNAPSHOT_VERSION) { | ||
return new Error( | ||
_chalk2.default.red( | ||
`${_chalk2.default.red.bold('Outdated Jest version')}: The version of this ` + | ||
`snapshot file indicates that this project is meant to be used ` + | ||
`with a newer version of Jest. The snapshot file version ensures ` + | ||
`that all developers on a project are using the same version of ` + | ||
`Jest. Please update your version of Jest and re-run the tests.\n\n`) + | ||
`Expected: v${SNAPSHOT_VERSION}\n` + | ||
`Received: v${version}`); | ||
return new Error(_chalk2.default.red(`${_chalk2.default.red.bold('Outdated Jest version')}: The version of this ` + `snapshot file indicates that this project is meant to be used ` + `with a newer version of Jest. The snapshot file version ensures ` + `that all developers on a project are using the same version of ` + `Jest. Please update your version of Jest and re-run the tests.\n\n`) + `Expected: v${SNAPSHOT_VERSION}\n` + `Received: v${version}`); | ||
} | ||
@@ -81,4 +73,3 @@ | ||
const testNameToKey = exports.testNameToKey = (testName, count) => | ||
testName + ' ' + count; | ||
const testNameToKey = exports.testNameToKey = (testName, count) => testName + ' ' + count; | ||
@@ -93,12 +84,5 @@ const keyToTestName = exports.keyToTestName = key => { | ||
const getSnapshotPath = exports.getSnapshotPath = testPath => | ||
_path2.default.join( | ||
_path2.default.join(_path2.default.dirname(testPath), '__snapshots__'), | ||
_path2.default.basename(testPath) + '.' + SNAPSHOT_EXTENSION); | ||
const getSnapshotPath = exports.getSnapshotPath = testPath => _path2.default.join(_path2.default.join(_path2.default.dirname(testPath), '__snapshots__'), _path2.default.basename(testPath) + '.' + SNAPSHOT_EXTENSION); | ||
const getSnapshotData = exports.getSnapshotData = ( | ||
snapshotPath, | ||
update) => | ||
{ | ||
const getSnapshotData = exports.getSnapshotData = (snapshotPath, update) => { | ||
const data = Object.create(null); | ||
@@ -134,15 +118,10 @@ let snapshotContents = ''; | ||
// to make the content of the snapshot easier to read | ||
const addExtraLineBreaks = string => | ||
string.includes('\n') ? `\n${string}\n` : string; | ||
const addExtraLineBreaks = string => string.includes('\n') ? `\n${string}\n` : string; | ||
const serialize = exports.serialize = data => { | ||
return addExtraLineBreaks( | ||
normalizeNewlines( | ||
(0, _prettyFormat2.default)(data, { | ||
return addExtraLineBreaks(normalizeNewlines((0, _prettyFormat2.default)(data, { | ||
escapeRegex: true, | ||
plugins: (0, _plugins.getSerializers)(), | ||
printFunctionName: false }))); | ||
printFunctionName: false | ||
}))); | ||
}; | ||
@@ -165,22 +144,7 @@ | ||
const saveSnapshotFile = exports.saveSnapshotFile = ( | ||
snapshotData, | ||
snapshotPath) => | ||
{ | ||
const snapshots = Object.keys(snapshotData). | ||
sort(_naturalCompare2.default). | ||
map( | ||
key => | ||
'exports[' + | ||
printBacktickString(key) + | ||
'] = ' + | ||
printBacktickString(normalizeNewlines(snapshotData[key])) + | ||
';'); | ||
const saveSnapshotFile = exports.saveSnapshotFile = (snapshotData, snapshotPath) => { | ||
const snapshots = Object.keys(snapshotData).sort(_naturalCompare2.default).map(key => 'exports[' + printBacktickString(key) + '] = ' + printBacktickString(normalizeNewlines(snapshotData[key])) + ';'); | ||
ensureDirectoryExists(snapshotPath); | ||
_fs2.default.writeFileSync( | ||
snapshotPath, | ||
writeSnapshotVersion() + '\n\n' + snapshots.join('\n\n') + '\n'); | ||
_fs2.default.writeFileSync(snapshotPath, writeSnapshotVersion() + '\n\n' + snapshots.join('\n\n') + '\n'); | ||
}; |
{ | ||
"name": "jest-snapshot", | ||
"version": "22.4.0", | ||
"version": "22.4.3", | ||
"repository": { | ||
@@ -12,8 +12,8 @@ "type": "git", | ||
"chalk": "^2.0.1", | ||
"jest-diff": "^22.4.0", | ||
"jest-matcher-utils": "^22.4.0", | ||
"jest-diff": "^22.4.3", | ||
"jest-matcher-utils": "^22.4.3", | ||
"mkdirp": "^0.5.1", | ||
"natural-compare": "^1.4.0", | ||
"pretty-format": "^22.4.0" | ||
"pretty-format": "^22.4.3" | ||
} | ||
} |
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
19452
413
Updatedjest-diff@^22.4.3
Updatedjest-matcher-utils@^22.4.3
Updatedpretty-format@^22.4.3