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

installed-shallow.js « completion « utils « lib « test « npm « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1d6369bc782545c7cc83bed374b9c5d7ebcd9190 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const requireInject = require('require-inject')
const flatOptions = { global: false }
const npm = { flatOptions }
const t = require('tap')
const { resolve } = require('path')

const p = '../../../../lib/utils/completion/installed-shallow.js'
const installed = requireInject(p, {
  '../../../../lib/npm.js': npm,
})

t.test('global not set, include globals with -g', t => {
  const dir = t.testdir({
    global: {
      node_modules: {
        x: {},
        '@scope': {
          y: {},
        },
      },
    },
    local: {
      node_modules: {
        a: {},
        '@scope': {
          b: {},
        },
      },
    },
  })
  npm.globalDir = resolve(dir, 'global/node_modules')
  npm.localDir = resolve(dir, 'local/node_modules')
  flatOptions.global = false
  const opt = { conf: { argv: { remain: [] } } }
  installed(opt, (er, res) => {
    if (er)
      throw er

    t.strictSame(res.sort(), [
      '@scope/y -g',
      'x -g',
      'a',
      '@scope/b',
    ].sort())
    t.end()
  })
})

t.test('global set, include globals and not locals', t => {
  const dir = t.testdir({
    global: {
      node_modules: {
        x: {},
        '@scope': {
          y: {},
        },
      },
    },
    local: {
      node_modules: {
        a: {},
        '@scope': {
          b: {},
        },
      },
    },
  })
  npm.globalDir = resolve(dir, 'global/node_modules')
  npm.localDir = resolve(dir, 'local/node_modules')
  flatOptions.global = true
  const opt = { conf: { argv: { remain: [] } } }
  installed(opt, (er, res) => {
    t.strictSame(res.sort(), [
      '@scope/y',
      'x',
    ].sort())
    t.end()
  })
})

t.test('more than 3 items in argv, skip it', t => {
  const dir = t.testdir({
    global: {
      node_modules: {
        x: {},
        '@scope': {
          y: {},
        },
      },
    },
    local: {
      node_modules: {
        a: {},
        '@scope': {
          b: {},
        },
      },
    },
  })
  npm.globalDir = resolve(dir, 'global/node_modules')
  npm.localDir = resolve(dir, 'local/node_modules')
  flatOptions.global = false
  const opt = { conf: { argv: { remain: [1, 2, 3, 4, 5, 6] } } }
  installed(opt, (er, res) => {
    if (er)
      throw er

    t.strictSame(res, null)
    t.end()
  })
})