11cb0ef41Sopenharmony_ciconst t = require('tap')
21cb0ef41Sopenharmony_ciconst mockNpm = require('../../fixtures/mock-npm')
31cb0ef41Sopenharmony_ciconst reifyOutput = require('../../../lib/utils/reify-output.js')
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_cit.cleanSnapshot = str => str.replace(/in [0-9]+m?s/g, 'in {TIME}')
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst mockReify = async (t, reify, { command, ...config } = {}) => {
81cb0ef41Sopenharmony_ci  const mock = await mockNpm(t, {
91cb0ef41Sopenharmony_ci    command,
101cb0ef41Sopenharmony_ci    config,
111cb0ef41Sopenharmony_ci    setCmd: true,
121cb0ef41Sopenharmony_ci  })
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci  reifyOutput(mock.npm, reify)
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci  return mock.joinedOutput()
171cb0ef41Sopenharmony_ci}
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cit.test('missing info', async t => {
201cb0ef41Sopenharmony_ci  const out = await mockReify(t, {
211cb0ef41Sopenharmony_ci    actualTree: {
221cb0ef41Sopenharmony_ci      children: [],
231cb0ef41Sopenharmony_ci    },
241cb0ef41Sopenharmony_ci    diff: {
251cb0ef41Sopenharmony_ci      children: [],
261cb0ef41Sopenharmony_ci    },
271cb0ef41Sopenharmony_ci  })
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  t.notMatch(
301cb0ef41Sopenharmony_ci    out,
311cb0ef41Sopenharmony_ci    'looking for funding',
321cb0ef41Sopenharmony_ci    'should not print fund message if missing info'
331cb0ef41Sopenharmony_ci  )
341cb0ef41Sopenharmony_ci})
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_cit.test('even more missing info', async t => {
371cb0ef41Sopenharmony_ci  const out = await mockReify(t, {
381cb0ef41Sopenharmony_ci    actualTree: {
391cb0ef41Sopenharmony_ci      children: [],
401cb0ef41Sopenharmony_ci    },
411cb0ef41Sopenharmony_ci  })
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci  t.notMatch(
441cb0ef41Sopenharmony_ci    out,
451cb0ef41Sopenharmony_ci    'looking for funding',
461cb0ef41Sopenharmony_ci    'should not print fund message if missing info'
471cb0ef41Sopenharmony_ci  )
481cb0ef41Sopenharmony_ci})
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_cit.test('single package', async t => {
511cb0ef41Sopenharmony_ci  const out = await mockReify(t, {
521cb0ef41Sopenharmony_ci    // a report with an error is the same as no report at all, if
531cb0ef41Sopenharmony_ci    // the command is not 'audit'
541cb0ef41Sopenharmony_ci    auditReport: {
551cb0ef41Sopenharmony_ci      error: {
561cb0ef41Sopenharmony_ci        message: 'no audit for youuuuu',
571cb0ef41Sopenharmony_ci      },
581cb0ef41Sopenharmony_ci    },
591cb0ef41Sopenharmony_ci    actualTree: {
601cb0ef41Sopenharmony_ci      name: 'foo',
611cb0ef41Sopenharmony_ci      package: {
621cb0ef41Sopenharmony_ci        name: 'foo',
631cb0ef41Sopenharmony_ci        version: '1.0.0',
641cb0ef41Sopenharmony_ci      },
651cb0ef41Sopenharmony_ci      edgesOut: new Map([
661cb0ef41Sopenharmony_ci        ['bar', {
671cb0ef41Sopenharmony_ci          to: {
681cb0ef41Sopenharmony_ci            name: 'bar',
691cb0ef41Sopenharmony_ci            package: {
701cb0ef41Sopenharmony_ci              name: 'bar',
711cb0ef41Sopenharmony_ci              version: '1.0.0',
721cb0ef41Sopenharmony_ci              funding: { type: 'foo', url: 'http://example.com' },
731cb0ef41Sopenharmony_ci            },
741cb0ef41Sopenharmony_ci          },
751cb0ef41Sopenharmony_ci        }],
761cb0ef41Sopenharmony_ci      ]),
771cb0ef41Sopenharmony_ci    },
781cb0ef41Sopenharmony_ci    diff: {
791cb0ef41Sopenharmony_ci      children: [],
801cb0ef41Sopenharmony_ci    },
811cb0ef41Sopenharmony_ci  })
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci  t.match(
841cb0ef41Sopenharmony_ci    out,
851cb0ef41Sopenharmony_ci    '1 package is looking for funding',
861cb0ef41Sopenharmony_ci    'should print single package message'
871cb0ef41Sopenharmony_ci  )
881cb0ef41Sopenharmony_ci})
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_cit.test('no message when funding config is false', async t => {
911cb0ef41Sopenharmony_ci  const out = await mockReify(t, {
921cb0ef41Sopenharmony_ci    actualTree: {
931cb0ef41Sopenharmony_ci      name: 'foo',
941cb0ef41Sopenharmony_ci      package: {
951cb0ef41Sopenharmony_ci        name: 'foo',
961cb0ef41Sopenharmony_ci        version: '1.0.0',
971cb0ef41Sopenharmony_ci      },
981cb0ef41Sopenharmony_ci      edgesOut: new Map([
991cb0ef41Sopenharmony_ci        ['bar', {
1001cb0ef41Sopenharmony_ci          to: {
1011cb0ef41Sopenharmony_ci            name: 'bar',
1021cb0ef41Sopenharmony_ci            package: {
1031cb0ef41Sopenharmony_ci              name: 'bar',
1041cb0ef41Sopenharmony_ci              version: '1.0.0',
1051cb0ef41Sopenharmony_ci              funding: { type: 'foo', url: 'http://example.com' },
1061cb0ef41Sopenharmony_ci            },
1071cb0ef41Sopenharmony_ci          },
1081cb0ef41Sopenharmony_ci        }],
1091cb0ef41Sopenharmony_ci      ]),
1101cb0ef41Sopenharmony_ci    },
1111cb0ef41Sopenharmony_ci    diff: {
1121cb0ef41Sopenharmony_ci      children: [],
1131cb0ef41Sopenharmony_ci    },
1141cb0ef41Sopenharmony_ci  }, { fund: false })
1151cb0ef41Sopenharmony_ci
1161cb0ef41Sopenharmony_ci  t.notMatch(out, 'looking for funding', 'should not print funding info')
1171cb0ef41Sopenharmony_ci})
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_cit.test('print appropriate message for many packages', async t => {
1201cb0ef41Sopenharmony_ci  const out = await mockReify(t, {
1211cb0ef41Sopenharmony_ci    actualTree: {
1221cb0ef41Sopenharmony_ci      name: 'foo',
1231cb0ef41Sopenharmony_ci      package: {
1241cb0ef41Sopenharmony_ci        name: 'foo',
1251cb0ef41Sopenharmony_ci        version: '1.0.0',
1261cb0ef41Sopenharmony_ci      },
1271cb0ef41Sopenharmony_ci      edgesOut: new Map([
1281cb0ef41Sopenharmony_ci        ['bar', {
1291cb0ef41Sopenharmony_ci          to: {
1301cb0ef41Sopenharmony_ci            name: 'bar',
1311cb0ef41Sopenharmony_ci            package: {
1321cb0ef41Sopenharmony_ci              name: 'bar',
1331cb0ef41Sopenharmony_ci              version: '1.0.0',
1341cb0ef41Sopenharmony_ci              funding: { type: 'foo', url: 'http://example.com' },
1351cb0ef41Sopenharmony_ci            },
1361cb0ef41Sopenharmony_ci          },
1371cb0ef41Sopenharmony_ci        }],
1381cb0ef41Sopenharmony_ci        ['lorem', {
1391cb0ef41Sopenharmony_ci          to: {
1401cb0ef41Sopenharmony_ci            name: 'lorem',
1411cb0ef41Sopenharmony_ci            package: {
1421cb0ef41Sopenharmony_ci              name: 'lorem',
1431cb0ef41Sopenharmony_ci              version: '1.0.0',
1441cb0ef41Sopenharmony_ci              funding: { type: 'foo', url: 'http://example.com' },
1451cb0ef41Sopenharmony_ci            },
1461cb0ef41Sopenharmony_ci          },
1471cb0ef41Sopenharmony_ci        }],
1481cb0ef41Sopenharmony_ci        ['ipsum', {
1491cb0ef41Sopenharmony_ci          to: {
1501cb0ef41Sopenharmony_ci            name: 'ipsum',
1511cb0ef41Sopenharmony_ci            package: {
1521cb0ef41Sopenharmony_ci              name: 'ipsum',
1531cb0ef41Sopenharmony_ci              version: '1.0.0',
1541cb0ef41Sopenharmony_ci              funding: { type: 'foo', url: 'http://example.com' },
1551cb0ef41Sopenharmony_ci            },
1561cb0ef41Sopenharmony_ci          },
1571cb0ef41Sopenharmony_ci        }],
1581cb0ef41Sopenharmony_ci      ]),
1591cb0ef41Sopenharmony_ci    },
1601cb0ef41Sopenharmony_ci    diff: {
1611cb0ef41Sopenharmony_ci      children: [],
1621cb0ef41Sopenharmony_ci    },
1631cb0ef41Sopenharmony_ci  })
1641cb0ef41Sopenharmony_ci
1651cb0ef41Sopenharmony_ci  t.match(
1661cb0ef41Sopenharmony_ci    out,
1671cb0ef41Sopenharmony_ci    '3 packages are looking for funding',
1681cb0ef41Sopenharmony_ci    'should print single package message'
1691cb0ef41Sopenharmony_ci  )
1701cb0ef41Sopenharmony_ci})
1711cb0ef41Sopenharmony_ci
1721cb0ef41Sopenharmony_cit.test('showing and not showing audit report', async t => {
1731cb0ef41Sopenharmony_ci  const auditReport = {
1741cb0ef41Sopenharmony_ci    toJSON: () => auditReport,
1751cb0ef41Sopenharmony_ci    auditReportVersion: 2,
1761cb0ef41Sopenharmony_ci    vulnerabilities: {
1771cb0ef41Sopenharmony_ci      minimist: {
1781cb0ef41Sopenharmony_ci        name: 'minimist',
1791cb0ef41Sopenharmony_ci        severity: 'low',
1801cb0ef41Sopenharmony_ci        via: [
1811cb0ef41Sopenharmony_ci          {
1821cb0ef41Sopenharmony_ci            id: 1179,
1831cb0ef41Sopenharmony_ci            url: 'https://npmjs.com/advisories/1179',
1841cb0ef41Sopenharmony_ci            title: 'Prototype Pollution',
1851cb0ef41Sopenharmony_ci            severity: 'low',
1861cb0ef41Sopenharmony_ci            vulnerable_versions: '<0.2.1 || >=1.0.0 <1.2.3',
1871cb0ef41Sopenharmony_ci          },
1881cb0ef41Sopenharmony_ci        ],
1891cb0ef41Sopenharmony_ci        effects: [],
1901cb0ef41Sopenharmony_ci        range: '<0.2.1 || >=1.0.0 <1.2.3',
1911cb0ef41Sopenharmony_ci        nodes: [
1921cb0ef41Sopenharmony_ci          'node_modules/minimist',
1931cb0ef41Sopenharmony_ci        ],
1941cb0ef41Sopenharmony_ci        fixAvailable: true,
1951cb0ef41Sopenharmony_ci      },
1961cb0ef41Sopenharmony_ci    },
1971cb0ef41Sopenharmony_ci    metadata: {
1981cb0ef41Sopenharmony_ci      vulnerabilities: {
1991cb0ef41Sopenharmony_ci        info: 0,
2001cb0ef41Sopenharmony_ci        low: 1,
2011cb0ef41Sopenharmony_ci        moderate: 0,
2021cb0ef41Sopenharmony_ci        high: 0,
2031cb0ef41Sopenharmony_ci        critical: 0,
2041cb0ef41Sopenharmony_ci        total: 1,
2051cb0ef41Sopenharmony_ci      },
2061cb0ef41Sopenharmony_ci      dependencies: {
2071cb0ef41Sopenharmony_ci        prod: 1,
2081cb0ef41Sopenharmony_ci        dev: 0,
2091cb0ef41Sopenharmony_ci        optional: 0,
2101cb0ef41Sopenharmony_ci        peer: 0,
2111cb0ef41Sopenharmony_ci        peerOptional: 0,
2121cb0ef41Sopenharmony_ci        total: 1,
2131cb0ef41Sopenharmony_ci      },
2141cb0ef41Sopenharmony_ci    },
2151cb0ef41Sopenharmony_ci  }
2161cb0ef41Sopenharmony_ci
2171cb0ef41Sopenharmony_ci  t.test('no output when silent', async t => {
2181cb0ef41Sopenharmony_ci    const out = await mockReify(t, {
2191cb0ef41Sopenharmony_ci      actualTree: { inventory: { size: 999 }, children: [] },
2201cb0ef41Sopenharmony_ci      auditReport,
2211cb0ef41Sopenharmony_ci      diff: {
2221cb0ef41Sopenharmony_ci        children: [
2231cb0ef41Sopenharmony_ci          { action: 'ADD', ideal: { location: 'loc' } },
2241cb0ef41Sopenharmony_ci        ],
2251cb0ef41Sopenharmony_ci      },
2261cb0ef41Sopenharmony_ci    }, { silent: true })
2271cb0ef41Sopenharmony_ci    t.equal(out, '', 'should not get output when silent')
2281cb0ef41Sopenharmony_ci  })
2291cb0ef41Sopenharmony_ci
2301cb0ef41Sopenharmony_ci  t.test('output when not silent', async t => {
2311cb0ef41Sopenharmony_ci    const out = await mockReify(t, {
2321cb0ef41Sopenharmony_ci      actualTree: { inventory: new Map(), children: [] },
2331cb0ef41Sopenharmony_ci      auditReport,
2341cb0ef41Sopenharmony_ci      diff: {
2351cb0ef41Sopenharmony_ci        children: [
2361cb0ef41Sopenharmony_ci          { action: 'ADD', ideal: { location: 'loc' } },
2371cb0ef41Sopenharmony_ci        ],
2381cb0ef41Sopenharmony_ci      },
2391cb0ef41Sopenharmony_ci    })
2401cb0ef41Sopenharmony_ci
2411cb0ef41Sopenharmony_ci    t.match(out, /Run `npm audit` for details\.$/, 'got audit report')
2421cb0ef41Sopenharmony_ci  })
2431cb0ef41Sopenharmony_ci
2441cb0ef41Sopenharmony_ci  for (const json of [true, false]) {
2451cb0ef41Sopenharmony_ci    t.test(`json=${json}`, async t => {
2461cb0ef41Sopenharmony_ci      t.test('set exit code when cmd is audit', async t => {
2471cb0ef41Sopenharmony_ci        await mockReify(t, {
2481cb0ef41Sopenharmony_ci          actualTree: { inventory: new Map(), children: [] },
2491cb0ef41Sopenharmony_ci          auditReport,
2501cb0ef41Sopenharmony_ci          diff: {
2511cb0ef41Sopenharmony_ci            children: [
2521cb0ef41Sopenharmony_ci              { action: 'ADD', ideal: { location: 'loc' } },
2531cb0ef41Sopenharmony_ci            ],
2541cb0ef41Sopenharmony_ci          },
2551cb0ef41Sopenharmony_ci        }, { command: 'audit', 'audit-level': 'low' })
2561cb0ef41Sopenharmony_ci
2571cb0ef41Sopenharmony_ci        t.equal(process.exitCode, 1, 'set exit code')
2581cb0ef41Sopenharmony_ci      })
2591cb0ef41Sopenharmony_ci
2601cb0ef41Sopenharmony_ci      t.test('do not set exit code when cmd is install', async t => {
2611cb0ef41Sopenharmony_ci        await mockReify(t, {
2621cb0ef41Sopenharmony_ci          actualTree: { inventory: new Map(), children: [] },
2631cb0ef41Sopenharmony_ci          auditReport,
2641cb0ef41Sopenharmony_ci          diff: {
2651cb0ef41Sopenharmony_ci            children: [
2661cb0ef41Sopenharmony_ci              { action: 'ADD', ideal: { location: 'loc' } },
2671cb0ef41Sopenharmony_ci            ],
2681cb0ef41Sopenharmony_ci          },
2691cb0ef41Sopenharmony_ci        }, { command: 'install', 'audit-level': 'low' })
2701cb0ef41Sopenharmony_ci
2711cb0ef41Sopenharmony_ci        t.notOk(process.exitCode, 'did not set exit code')
2721cb0ef41Sopenharmony_ci      })
2731cb0ef41Sopenharmony_ci    })
2741cb0ef41Sopenharmony_ci  }
2751cb0ef41Sopenharmony_ci})
2761cb0ef41Sopenharmony_ci
2771cb0ef41Sopenharmony_cit.test('packages changed message', async t => {
2781cb0ef41Sopenharmony_ci  // return a test function that builds up the mock and snapshots output
2791cb0ef41Sopenharmony_ci  const testCase = async (t, added, removed, changed, audited, json, command) => {
2801cb0ef41Sopenharmony_ci    const mock = {
2811cb0ef41Sopenharmony_ci      actualTree: {
2821cb0ef41Sopenharmony_ci        inventory: { size: audited, has: () => true },
2831cb0ef41Sopenharmony_ci        children: [],
2841cb0ef41Sopenharmony_ci      },
2851cb0ef41Sopenharmony_ci      auditReport: audited ? {
2861cb0ef41Sopenharmony_ci        toJSON: () => mock.auditReport,
2871cb0ef41Sopenharmony_ci        vulnerabilities: {},
2881cb0ef41Sopenharmony_ci        metadata: {
2891cb0ef41Sopenharmony_ci          vulnerabilities: {
2901cb0ef41Sopenharmony_ci            total: 0,
2911cb0ef41Sopenharmony_ci          },
2921cb0ef41Sopenharmony_ci        },
2931cb0ef41Sopenharmony_ci      } : null,
2941cb0ef41Sopenharmony_ci      diff: {
2951cb0ef41Sopenharmony_ci        children: [
2961cb0ef41Sopenharmony_ci          { action: 'some random unexpected junk' },
2971cb0ef41Sopenharmony_ci        ],
2981cb0ef41Sopenharmony_ci      },
2991cb0ef41Sopenharmony_ci    }
3001cb0ef41Sopenharmony_ci    for (let i = 0; i < added; i++) {
3011cb0ef41Sopenharmony_ci      mock.diff.children.push({ action: 'ADD', ideal: { location: 'loc' } })
3021cb0ef41Sopenharmony_ci    }
3031cb0ef41Sopenharmony_ci
3041cb0ef41Sopenharmony_ci    for (let i = 0; i < removed; i++) {
3051cb0ef41Sopenharmony_ci      mock.diff.children.push({ action: 'REMOVE', actual: { location: 'loc' } })
3061cb0ef41Sopenharmony_ci    }
3071cb0ef41Sopenharmony_ci
3081cb0ef41Sopenharmony_ci    for (let i = 0; i < changed; i++) {
3091cb0ef41Sopenharmony_ci      const actual = { location: 'loc' }
3101cb0ef41Sopenharmony_ci      const ideal = { location: 'loc' }
3111cb0ef41Sopenharmony_ci      mock.diff.children.push({ action: 'CHANGE', actual, ideal })
3121cb0ef41Sopenharmony_ci    }
3131cb0ef41Sopenharmony_ci
3141cb0ef41Sopenharmony_ci    const out = await mockReify(t, mock, { json, command })
3151cb0ef41Sopenharmony_ci    t.matchSnapshot(out, JSON.stringify({
3161cb0ef41Sopenharmony_ci      added,
3171cb0ef41Sopenharmony_ci      removed,
3181cb0ef41Sopenharmony_ci      changed,
3191cb0ef41Sopenharmony_ci      audited,
3201cb0ef41Sopenharmony_ci      json,
3211cb0ef41Sopenharmony_ci    }))
3221cb0ef41Sopenharmony_ci  }
3231cb0ef41Sopenharmony_ci
3241cb0ef41Sopenharmony_ci  const cases = []
3251cb0ef41Sopenharmony_ci  for (const added of [0, 1, 2]) {
3261cb0ef41Sopenharmony_ci    for (const removed of [0, 1, 2]) {
3271cb0ef41Sopenharmony_ci      for (const changed of [0, 1, 2]) {
3281cb0ef41Sopenharmony_ci        for (const audited of [0, 1, 2]) {
3291cb0ef41Sopenharmony_ci          for (const json of [true, false]) {
3301cb0ef41Sopenharmony_ci            cases.push([added, removed, changed, audited, json, 'install'])
3311cb0ef41Sopenharmony_ci          }
3321cb0ef41Sopenharmony_ci        }
3331cb0ef41Sopenharmony_ci      }
3341cb0ef41Sopenharmony_ci    }
3351cb0ef41Sopenharmony_ci  }
3361cb0ef41Sopenharmony_ci
3371cb0ef41Sopenharmony_ci  // add case for when audit is the command
3381cb0ef41Sopenharmony_ci  cases.push([0, 0, 0, 2, true, 'audit'])
3391cb0ef41Sopenharmony_ci  cases.push([0, 0, 0, 2, false, 'audit'])
3401cb0ef41Sopenharmony_ci
3411cb0ef41Sopenharmony_ci  for (const c of cases) {
3421cb0ef41Sopenharmony_ci    await t.test('', t => testCase(t, ...c))
3431cb0ef41Sopenharmony_ci  }
3441cb0ef41Sopenharmony_ci})
3451cb0ef41Sopenharmony_ci
3461cb0ef41Sopenharmony_cit.test('added packages should be looked up within returned tree', async t => {
3471cb0ef41Sopenharmony_ci  t.test('has added pkg in inventory', async t => {
3481cb0ef41Sopenharmony_ci    const out = await mockReify(t, {
3491cb0ef41Sopenharmony_ci      actualTree: {
3501cb0ef41Sopenharmony_ci        name: 'foo',
3511cb0ef41Sopenharmony_ci        inventory: {
3521cb0ef41Sopenharmony_ci          has: () => true,
3531cb0ef41Sopenharmony_ci        },
3541cb0ef41Sopenharmony_ci      },
3551cb0ef41Sopenharmony_ci      diff: {
3561cb0ef41Sopenharmony_ci        children: [
3571cb0ef41Sopenharmony_ci          { action: 'ADD', ideal: { name: 'baz' } },
3581cb0ef41Sopenharmony_ci        ],
3591cb0ef41Sopenharmony_ci      },
3601cb0ef41Sopenharmony_ci    })
3611cb0ef41Sopenharmony_ci
3621cb0ef41Sopenharmony_ci    t.matchSnapshot(out)
3631cb0ef41Sopenharmony_ci  })
3641cb0ef41Sopenharmony_ci
3651cb0ef41Sopenharmony_ci  t.test('missing added pkg in inventory', async t => {
3661cb0ef41Sopenharmony_ci    const out = await mockReify(t, {
3671cb0ef41Sopenharmony_ci      actualTree: {
3681cb0ef41Sopenharmony_ci        name: 'foo',
3691cb0ef41Sopenharmony_ci        inventory: {
3701cb0ef41Sopenharmony_ci          has: () => false,
3711cb0ef41Sopenharmony_ci        },
3721cb0ef41Sopenharmony_ci      },
3731cb0ef41Sopenharmony_ci      diff: {
3741cb0ef41Sopenharmony_ci        children: [
3751cb0ef41Sopenharmony_ci          { action: 'ADD', ideal: { name: 'baz' } },
3761cb0ef41Sopenharmony_ci        ],
3771cb0ef41Sopenharmony_ci      },
3781cb0ef41Sopenharmony_ci    })
3791cb0ef41Sopenharmony_ci
3801cb0ef41Sopenharmony_ci    t.matchSnapshot(out)
3811cb0ef41Sopenharmony_ci  })
3821cb0ef41Sopenharmony_ci})
3831cb0ef41Sopenharmony_ci
3841cb0ef41Sopenharmony_cit.test('prints dedupe difference on dry-run', async t => {
3851cb0ef41Sopenharmony_ci  const mock = {
3861cb0ef41Sopenharmony_ci    actualTree: {
3871cb0ef41Sopenharmony_ci      name: 'foo',
3881cb0ef41Sopenharmony_ci      inventory: {
3891cb0ef41Sopenharmony_ci        has: () => false,
3901cb0ef41Sopenharmony_ci      },
3911cb0ef41Sopenharmony_ci    },
3921cb0ef41Sopenharmony_ci    diff: {
3931cb0ef41Sopenharmony_ci      children: [
3941cb0ef41Sopenharmony_ci        { action: 'ADD', ideal: { name: 'foo', package: { version: '1.0.0' } } },
3951cb0ef41Sopenharmony_ci        { action: 'REMOVE', actual: { name: 'bar', package: { version: '1.0.0' } } },
3961cb0ef41Sopenharmony_ci        {
3971cb0ef41Sopenharmony_ci          action: 'CHANGE',
3981cb0ef41Sopenharmony_ci          actual: { name: 'bar', package: { version: '1.0.0' } },
3991cb0ef41Sopenharmony_ci          ideal: { package: { version: '2.1.0' } },
4001cb0ef41Sopenharmony_ci        },
4011cb0ef41Sopenharmony_ci      ],
4021cb0ef41Sopenharmony_ci    },
4031cb0ef41Sopenharmony_ci  }
4041cb0ef41Sopenharmony_ci
4051cb0ef41Sopenharmony_ci  const out = await mockReify(t, mock, {
4061cb0ef41Sopenharmony_ci    'dry-run': true,
4071cb0ef41Sopenharmony_ci  })
4081cb0ef41Sopenharmony_ci
4091cb0ef41Sopenharmony_ci  t.matchSnapshot(out, 'diff table')
4101cb0ef41Sopenharmony_ci})
4111cb0ef41Sopenharmony_ci
4121cb0ef41Sopenharmony_cit.test('prints dedupe difference on long', async t => {
4131cb0ef41Sopenharmony_ci  const mock = {
4141cb0ef41Sopenharmony_ci    actualTree: {
4151cb0ef41Sopenharmony_ci      name: 'foo',
4161cb0ef41Sopenharmony_ci      inventory: {
4171cb0ef41Sopenharmony_ci        has: () => false,
4181cb0ef41Sopenharmony_ci      },
4191cb0ef41Sopenharmony_ci    },
4201cb0ef41Sopenharmony_ci    diff: {
4211cb0ef41Sopenharmony_ci      children: [
4221cb0ef41Sopenharmony_ci        { action: 'ADD', ideal: { name: 'foo', package: { version: '1.0.0' } } },
4231cb0ef41Sopenharmony_ci        { action: 'REMOVE', actual: { name: 'bar', package: { version: '1.0.0' } } },
4241cb0ef41Sopenharmony_ci        {
4251cb0ef41Sopenharmony_ci          action: 'CHANGE',
4261cb0ef41Sopenharmony_ci          actual: { name: 'bar', package: { version: '1.0.0' } },
4271cb0ef41Sopenharmony_ci          ideal: { package: { version: '2.1.0' } },
4281cb0ef41Sopenharmony_ci        },
4291cb0ef41Sopenharmony_ci      ],
4301cb0ef41Sopenharmony_ci    },
4311cb0ef41Sopenharmony_ci  }
4321cb0ef41Sopenharmony_ci
4331cb0ef41Sopenharmony_ci  const out = await mockReify(t, mock, {
4341cb0ef41Sopenharmony_ci    long: true,
4351cb0ef41Sopenharmony_ci  })
4361cb0ef41Sopenharmony_ci
4371cb0ef41Sopenharmony_ci  t.matchSnapshot(out, 'diff table')
4381cb0ef41Sopenharmony_ci})
439