From 1aa09e93c7ff3fef38d4b81be79012b38b1a0baf Mon Sep 17 00:00:00 2001 From: nlf Date: Wed, 17 Feb 2021 12:17:47 -0800 Subject: [PATCH] fix: if there are children but the diff itself has an action, make sure to add it to leaves --- lib/diff.js | 2 +- tap-snapshots/test-diff.js-TAP.test.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/diff.js b/lib/diff.js index ada67f816..d7c644090 100644 --- a/lib/diff.js +++ b/lib/diff.js @@ -105,7 +105,7 @@ const getChildren = diff => { diffNode(actual, ideal, children, unchanged, removed) } - if (diff.leaves && !children.length) + if (diff.leaves && !children.length || diff.action && diff.action !== 'REMOVE') diff.leaves.push(diff) return children diff --git a/tap-snapshots/test-diff.js-TAP.test.js b/tap-snapshots/test-diff.js-TAP.test.js index 577c7e595..80d627e38 100644 --- a/tap-snapshots/test-diff.js-TAP.test.js +++ b/tap-snapshots/test-diff.js-TAP.test.js @@ -19,6 +19,7 @@ Diff { "integrity": "sha512-aaa", }, "leaves": Array [ + "/path/to/root/node_modules/b", "/path/to/root/node_modules/b/node_modules/c", "/path/to/root/node_modules/b/node_modules/d/node_modules/e", "/path/to/root/node_modules/x/node_modules/y", @@ -26,6 +27,7 @@ Diff { "/path/to/root/node_modules/bundler/node_modules/not-bundled", "/path/to/root/node_modules/should-have-bins", "/path/to/root/foo/node_modules/baz", + "/path/to/root/node_modules/i", "/path/to/root/node_modules/i/node_modules/j", "/path/to/root/foo/node_modules/boo", ], @@ -91,6 +93,7 @@ Diff { "integrity": "sha512-BBB", }, "leaves": Array [ + "/path/to/root/node_modules/b", "/path/to/root/node_modules/b/node_modules/c", "/path/to/root/node_modules/b/node_modules/d/node_modules/e", ], @@ -168,6 +171,7 @@ Diff { "integrity": "sha512-III", }, "leaves": Array [ + "/path/to/root/node_modules/i", "/path/to/root/node_modules/i/node_modules/j", ], "unchanged": Array [],