summaryrefslogtreecommitdiff
path: root/deps/node/deps/npm/test/tap/bundled-no-add-to-move.js
blob: f9146c0e01201709555e7fbcba80fe5198f972aa (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
'use strict'
var test = require('tap').test
var Node = require('../../lib/install/node.js').create
var npm = require('../../lib/npm.js')

var oldTree = Node({
  path: '/',
  location: '/',
  children: [
    Node({
      package: {name: 'one', version: '1.0.0'},
      path: '/node_modules/one',
      location: '/one'
    })
  ]
})
oldTree.children[0].requiredBy.push(oldTree)

var newTree = Node({
  path: '/',
  location: '/',
  children: [
    Node({
      package: {name: 'abc', version: '1.0.0'},
      path: '/node_modules/abc',
      location: '/abc',
      children: [
        Node({
          package: {name: 'one', version: '1.0.0'},
          fromBundle: true,
          path: '/node_modules/abc/node_modules/one',
          location: '/abc/one'
        })
      ]
    })
  ]
})
newTree.children[0].requiredBy.push(newTree)
newTree.children[0].children[0].requiredBy.push(newTree.children[0])

test('test', function (t) {
  npm.load({}, (err) => {
    if (err) throw err
    var diffTrees = require('../../lib/install/diff-trees.js')._diffTrees
    var sortActions = require('../../lib/install/diff-trees.js').sortActions
    var differences = sortActions(diffTrees(oldTree, newTree)).map(function (diff) { return diff[0] + diff[1].location })
    t.isDeeply(differences, ['add/abc/one', 'remove/one', 'add/abc'], 'bundled add/remove stays add/remove')
    t.end()
  })
})