From 52c90eeb6824525ad7ca696911d9d33b5d5aa9bc Mon Sep 17 00:00:00 2001 From: Gar Date: Tue, 23 Jan 2024 13:10:11 -0800 Subject: [PATCH] feat: display tree diff on `--long` --- lib/utils/reify-output.js | 2 +- .../test/lib/utils/reify-output.js.test.cjs | 11 ++++++- test/lib/utils/reify-output.js | 30 ++++++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/lib/utils/reify-output.js b/lib/utils/reify-output.js index ff63f845e458b..44c913812a8ef 100644 --- a/lib/utils/reify-output.js +++ b/lib/utils/reify-output.js @@ -43,7 +43,7 @@ const reifyOutput = (npm, arb) => { if (diff) { let diffTable - if (npm.config.get('dry-run')) { + if (npm.config.get('dry-run') || npm.config.get('long')) { diffTable = new Table({ chars: { top: '', diff --git a/tap-snapshots/test/lib/utils/reify-output.js.test.cjs b/tap-snapshots/test/lib/utils/reify-output.js.test.cjs index 09307271d6054..5983ac224e26e 100644 --- a/tap-snapshots/test/lib/utils/reify-output.js.test.cjs +++ b/tap-snapshots/test/lib/utils/reify-output.js.test.cjs @@ -1633,7 +1633,16 @@ exports[`test/lib/utils/reify-output.js TAP packages changed message > {"added" } ` -exports[`test/lib/utils/reify-output.js TAP prints dedupe difference > diff table 1`] = ` +exports[`test/lib/utils/reify-output.js TAP prints dedupe difference on dry-run > diff table 1`] = ` + +change bar 1.0.0 -> 2.1.0 +remove bar 1.0.0 +add foo 1.0.0 + +removed 1 package, and changed 1 package in {TIME} +` + +exports[`test/lib/utils/reify-output.js TAP prints dedupe difference on long > diff table 1`] = ` change bar 1.0.0 -> 2.1.0 remove bar 1.0.0 diff --git a/test/lib/utils/reify-output.js b/test/lib/utils/reify-output.js index 732034ed2fb28..fd15e25a74984 100644 --- a/test/lib/utils/reify-output.js +++ b/test/lib/utils/reify-output.js @@ -381,7 +381,7 @@ t.test('added packages should be looked up within returned tree', async t => { }) }) -t.test('prints dedupe difference', async t => { +t.test('prints dedupe difference on dry-run', async t => { const mock = { actualTree: { name: 'foo', @@ -408,3 +408,31 @@ t.test('prints dedupe difference', async t => { t.matchSnapshot(out, 'diff table') }) + +t.test('prints dedupe difference on long', async t => { + const mock = { + actualTree: { + name: 'foo', + inventory: { + has: () => false, + }, + }, + diff: { + children: [ + { action: 'ADD', ideal: { name: 'foo', package: { version: '1.0.0' } } }, + { action: 'REMOVE', actual: { name: 'bar', package: { version: '1.0.0' } } }, + { + action: 'CHANGE', + actual: { name: 'bar', package: { version: '1.0.0' } }, + ideal: { package: { version: '2.1.0' } }, + }, + ], + }, + } + + const out = await mockReify(t, mock, { + long: true, + }) + + t.matchSnapshot(out, 'diff table') +})