• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var fs = require('fs')
3var path = require('path')
4
5var test = require('tap').test
6var mkdirp = require('mkdirp')
7var rimraf = require('rimraf')
8
9var common = require('../common-tap')
10
11var pkg = common.pkg
12var pathModA = path.join(pkg, 'node_modules', 'moduleA')
13var pathModB = path.join(pkg, 'node_modules', 'moduleB')
14
15var modA = {
16  name: 'moduleA',
17  version: '1.0.0',
18  _requiredBy: [ '#USER', '/moduleB' ],
19  dependencies: {
20    moduleB: '1.0.0'
21  }
22}
23var modB = {
24  name: 'moduleB',
25  version: '1.0.0',
26  _requiredBy: [ '/moduleA' ],
27  dependencies: {
28    moduleA: '1.0.0'
29  }
30}
31
32function setup () {
33  mkdirp.sync(pathModA)
34  fs.writeFileSync(
35    path.join(pathModA, 'package.json'),
36    JSON.stringify(modA, null, 2)
37  )
38  mkdirp.sync(pathModB)
39  fs.writeFileSync(
40    path.join(pathModB, 'package.json'),
41    JSON.stringify(modB, null, 2)
42  )
43}
44
45function cleanup () {
46  rimraf.sync(pkg)
47}
48
49test('setup', function (t) {
50  cleanup()
51  setup()
52  t.end()
53})
54
55var expected = pkg + '\n' +
56               '└─┬ moduleA@1.0.0\n' +
57               '  └─┬ moduleB@1.0.0\n' +
58               '    └── moduleA@1.0.0 deduped\n\n'
59
60test('extraneous-dep-cycle', function (t) {
61  common.npm(['ls', '--unicode=true'], {cwd: pkg}, function (er, code, stdout, stderr) {
62    t.ifErr(er, 'install finished successfully')
63    t.is(stdout, expected, 'ls output shows module')
64    t.end()
65  })
66})
67
68test('cleanup', function (t) {
69  cleanup()
70  t.end()
71})
72