Skip to content

Commit

Permalink
3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cdlewis committed Jul 14, 2020
1 parent bce755d commit c309809
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
15 changes: 12 additions & 3 deletions dist/snapshotter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ var _jestDiff = _interopRequireDefault(require("jest-diff"));

var _getSnapshotPath = _interopRequireDefault(require("./util/get-snapshot-path"));

var _utils = require("enzyme-to-json/utils.js");

var _path = require("path");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const stringify = object => JSON.stringify(object, (key, value) => {
Expand All @@ -34,6 +38,11 @@ const maybeUpdateSnapshot = (snapshotPath, relativeSnapshotPath, component) => {
const shouldUpdate = _readlineSync.default.question(`\n\x07Write new snapshot to ${relativeSnapshotPath}? (y/n): `);

if (shouldUpdate === 'y') {
// Attempt to create the directory if it doesn't already exist (requires Node 10+)
const parentDirectory = (0, _path.dirname)(snapshotPath);
(0, _fs.mkdirSync)(parentDirectory, {
recursive: true
});
(0, _fs.writeFileSync)(snapshotPath, stringify(component), {
flag: 'w'
});
Expand All @@ -42,16 +51,16 @@ const maybeUpdateSnapshot = (snapshotPath, relativeSnapshotPath, component) => {
};

module.exports = (assert, component, id, outputBuffer = _process.default.stdout) => {
const serialisedComponent = JSON.parse(stringify((0, _enzymeToJson.shallowToJson)(component, {
const serialisedComponent = (0, _utils.isEnzymeWrapper)(component) ? JSON.parse(stringify((0, _enzymeToJson.shallowToJson)(component, {
noKey: true
})));
}))) : component;
const {
snapshotPath,
relativeSnapshotPath
} = (0, _getSnapshotPath.default)(id);

try {
const snapshot = JSON.parse((0, _fs.readFileSync)(snapshotPath));
const snapshot = JSON.parse((0, _fs.readFileSync)(snapshotPath).toString());

if ((0, _lodash.isEqual)(serialisedComponent, snapshot)) {
assert.pass(`Snapshot matches ${id}`);
Expand Down
2 changes: 1 addition & 1 deletion dist/util/get-snapshot-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var _default = id => {
const config = (0, _lodash.get)(JSON.parse((0, _fs.readFileSync)(`${packageRoot}/package.json`)), 'snapshotter', {
snapshotPath: './test/snapshots'
});
(0, _lodash.set)(global, 'snapshotter', _objectSpread({}, config, {
(0, _lodash.set)(global, 'snapshotter', _objectSpread(_objectSpread({}, config), {}, {
packageRoot
}));
return getSnapshotFilePath(packageRoot, config.snapshotPath, id);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "snapshotter",
"version": "3.0.1",
"version": "3.1.0",
"description": "Snapshot testing for Tape",
"main": "dist/snapshotter.js",
"scripts": {
Expand Down

0 comments on commit c309809

Please sign in to comment.