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

dedupe.js « lib « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3e8b2f4c01347f9f974b4e5cda6f57b2af6f7284 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const { test } = require('tap')
const requireInject = require('require-inject')

const npm = (base) => {
  const config = base.config
  return {
    ...base,
    flatOptions: { dryRun: false },
    config: {
      get: (k) => config[k],
    },
  }
}

test('should throw in global mode', (t) => {
  const Dedupe = requireInject('../../lib/dedupe.js')
  const dedupe = new Dedupe(npm({ config: { global: true }}))

  dedupe.exec([], er => {
    t.match(er, { code: 'EDEDUPEGLOBAL' }, 'throws EDEDUPEGLOBAL')
    t.end()
  })
})

test('should remove dupes using Arborist', (t) => {
  const Dedupe = requireInject('../../lib/dedupe.js', {
    '@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')
    },
  })
  const dedupe = new Dedupe(npm({
    prefix: 'foo',
    config: {
      'dry-run': 'true',
    },
  }))
  dedupe.exec([], er => {
    if (er)
      throw er
    t.ok(true, 'callback is called')
    t.end()
  })
})

test('should remove dupes using Arborist - no arguments', (t) => {
  const Dedupe = requireInject('../../lib/dedupe.js', {
    '@npmcli/arborist': function (args) {
      t.ok(args.dryRun, 'gets dryRun from flatOptions')
      this.dedupe = () => {}
    },
    '../../lib/utils/reify-output.js': () => {},
  })
  const dedupe = new Dedupe(npm({
    prefix: 'foo',
    config: {
      'dry-run': true,
    },
  }))
  dedupe.exec(null, () => {
    t.end()
  })
})