• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var test = require('tap').test
3var Node = require('../../lib/install/node.js').create
4var npm = require('../../lib/npm.js')
5
6var oldTree = Node({
7  path: '/',
8  location: '/',
9  children: [
10    Node({
11      package: {name: 'one', version: '1.0.0'},
12      path: '/node_modules/one',
13      location: '/one'
14    })
15  ]
16})
17oldTree.children[0].requiredBy.push(oldTree)
18
19var newTree = Node({
20  path: '/',
21  location: '/',
22  children: [
23    Node({
24      package: {name: 'abc', version: '1.0.0'},
25      path: '/node_modules/abc',
26      location: '/abc',
27      children: [
28        Node({
29          package: {name: 'one', version: '1.0.0'},
30          fromBundle: true,
31          path: '/node_modules/abc/node_modules/one',
32          location: '/abc/one'
33        })
34      ]
35    })
36  ]
37})
38newTree.children[0].requiredBy.push(newTree)
39newTree.children[0].children[0].requiredBy.push(newTree.children[0])
40
41test('test', function (t) {
42  npm.load({}, (err) => {
43    if (err) throw err
44    var diffTrees = require('../../lib/install/diff-trees.js')._diffTrees
45    var sortActions = require('../../lib/install/diff-trees.js').sortActions
46    var differences = sortActions(diffTrees(oldTree, newTree)).map(function (diff) { return diff[0] + diff[1].location })
47    t.isDeeply(differences, ['add/abc/one', 'remove/one', 'add/abc'], 'bundled add/remove stays add/remove')
48    t.end()
49  })
50})
51