Skip to content

Commit

Permalink
fix(diff-snapshot): JSON.stringify failed due to circular referneces (#…
Browse files Browse the repository at this point in the history
…72)

* fix(diff-snapshot): Fix stringify failure due to circular referneces.

* fix(diff-snapshot): Apply tslint --fix

* Add node v9 to CI build

* DO NOT SUBMIT: Fix pngjs.

* Remove comment.

* Upgrade pngjs to 3.3.3
  • Loading branch information
skywhale authored and 10xLaCroixDrinker committed Apr 24, 2018
1 parent 967d6f8 commit cea6750
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: node_js
node_js:
- "8"
- "6"
- "8"
- "9"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"lodash": "^4.17.4",
"mkdirp": "^0.5.1",
"pixelmatch": "^4.0.2",
"pngjs": "^3.3.0",
"pngjs": "^3.3.3",
"rimraf": "^2.6.2"
},
"peerDependencies": {
Expand Down
5 changes: 4 additions & 1 deletion src/diff-snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,12 @@ function diffImageToSnapshot(options) {
);

const input = { imagePath: diffOutputPath, image: compositeResultImage };
// image._packer property contains a circular reference since node9, causing JSON.stringify to
// fail. Might as well discard all the hidden properties.
const serializedInput = JSON.stringify(input, (name, val) => (name[0] === '_' ? undefined : val));

// writing diff in separate process to avoid perf issues associated with Math in Jest VM (https://github.com/facebook/jest/issues/5163)
const writeDiffProcess = childProcess.spawnSync('node', [`${__dirname}/write-result-diff-image.js`], { input: Buffer.from(JSON.stringify(input)) });
const writeDiffProcess = childProcess.spawnSync('node', [`${__dirname}/write-result-diff-image.js`], { input: Buffer.from(serializedInput) });
// in case of error print to console
if (writeDiffProcess.stderr.toString()) { console.log(writeDiffProcess.stderr.toString()); } // eslint-disable-line no-console, max-len
}
Expand Down

0 comments on commit cea6750

Please sign in to comment.