• 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(pkg)
34  fs.writeFileSync(
35    path.join(pkg, 'package.json'),
36    '{broken json'
37  )
38  mkdirp.sync(pathModA)
39  fs.writeFileSync(
40    path.join(pathModA, 'package.json'),
41    JSON.stringify(modA, null, 2)
42  )
43  mkdirp.sync(pathModB)
44  fs.writeFileSync(
45    path.join(pathModB, 'package.json'),
46    JSON.stringify(modB, null, 2)
47  )
48}
49
50function cleanup () {
51  rimraf.sync(pkg)
52}
53
54test('setup', function (t) {
55  cleanup()
56  setup()
57  t.end()
58})
59
60test('ls-top-errors', function (t) {
61  common.npm(['ls'], {cwd: pkg}, function (er, code, stdout, stderr) {
62    t.ifErr(er, 'install finished successfully')
63    t.match(stderr, /Failed to parse json/)
64    t.end()
65  })
66})
67
68test('cleanup', function (t) {
69  cleanup()
70  t.end()
71})
72