Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dedupe.js « commands « lib « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2e2fae238103ffb471bf2c81c62c2e35e6ad9fd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const t = require('tap')
const { load: loadMockNpm } = require('../../fixtures/mock-npm')

t.test('should throw in global mode', async (t) => {
  const { npm } = await loadMockNpm(t, {
    config: {
      global: true,
    },
  })
  t.rejects(
    npm.exec('dedupe', []),
    { code: 'EDEDUPEGLOBAL' },
    'throws EDEDUPEGLOBALE'
  )
})

t.test('should remove dupes using Arborist', async (t) => {
  t.plan(5)
  const { npm } = await loadMockNpm(t, {
    mocks: {
      '@npmcli/arborist': function (args) {
        t.ok(args, 'gets options object')
        t.ok(args.path, 'gets path option')
        t.ok(args.dryRun, 'gets dryRun from user')
        this.dedupe = () => {
          t.ok(true, 'dedupe is called')
        }
      },
      '../../lib/utils/reify-finish.js': (npm, arb) => {
        t.ok(arb, 'gets arborist tree')
      },
    },
    config: {
      'dry-run': 'true',
    },
  })
  await npm.exec('dedupe', [])
})

t.test('should remove dupes using Arborist - no arguments', async (t) => {
  t.plan(1)
  const { npm } = await loadMockNpm(t, {
    mocks: {
      '@npmcli/arborist': function (args) {
        t.ok(args.dryRun, 'gets dryRun from config')
        this.dedupe = () => {}
      },
      '../../lib/utils/reify-output.js': () => {},
      '../../lib/utils/reify-finish.js': () => {},
    },
    config: {
      'dry-run': true,
    },
  })
  await npm.exec('dedupe', [])
})