• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2const path = require('path')
3const test = require('tap').test
4const mr = require('npm-registry-mock')
5const Tacks = require('tacks')
6const File = Tacks.File
7const Symlink = Tacks.Symlink
8const Dir = Tacks.Dir
9const common = require('../common-tap.js')
10
11const basedir = common.pkg
12const testdir = path.join(basedir, 'testdir')
13const cachedir = common.cache
14const globaldir = path.join(basedir, 'global')
15const tmpdir = path.join(basedir, 'tmp')
16
17const conf = {
18  cwd: path.join(testdir, 'main'),
19  env: Object.assign({}, process.env, {
20    npm_config_cache: cachedir,
21    npm_config_tmp: tmpdir,
22    npm_config_prefix: globaldir,
23    npm_config_registry: common.registry,
24    npm_config_loglevel: 'warn'
25  })
26}
27
28let server
29const fixture = new Tacks(Dir({
30  cache: Dir(),
31  global: Dir(),
32  tmp: Dir(),
33  testdir: Dir({
34    broken: Dir({
35      'package.json': File({
36        name: 'broken',
37        version: '1.0.0'
38      })
39    }),
40    main: Dir({
41      node_modules: Dir({
42        unbroken: Symlink('/testdir/unbroken')
43      }),
44      'package-lock.json': File({
45        name: 'main',
46        version: '1.0.0',
47        lockfileVersion: 1,
48        requires: true,
49        dependencies: {
50          broken: {
51            version: 'file:../broken'
52          },
53          unbroken: {
54            version: 'file:../unbroken'
55          }
56        }
57      }),
58      'package.json': File({
59        name: 'main',
60        version: '1.0.0',
61        dependencies: {
62          broken: 'file:../broken',
63          unbroken: 'file:../unbroken'
64        }
65      })
66    }),
67    unbroken: Dir({
68      'package.json': File({
69        name: 'unbroken',
70        version: '1.0.0'
71      })
72    })
73  })
74}))
75
76function setup () {
77  cleanup()
78  fixture.create(basedir)
79}
80
81function cleanup () {
82  fixture.remove(basedir)
83}
84
85test('setup', function (t) {
86  setup()
87  mr({port: common.port, throwOnUnmatched: true}, function (err, s) {
88    if (err) throw err
89    server = s
90    t.done()
91  })
92})
93
94test('outdated sees broken links', function (t) {
95  common.npm(['outdated', '--json'], conf, function (err, code, stdout, stderr) {
96    if (err) throw err
97    t.is(code, 1, 'command ran not ok')
98    t.comment(stderr.trim())
99    t.comment(stdout.trim())
100    t.same(JSON.parse(stdout), {
101      broken: {
102        wanted: 'linked',
103        latest: 'linked',
104        location: ''
105      }
106    })
107    t.done()
108  })
109})
110
111test('outdated with long output sees broken links', function (t) {
112  common.npm(['outdated', '--long', '--json'], conf, function (err, code, stdout, stderr) {
113    if (err) throw err
114    t.is(code, 1, 'command ran not ok')
115    t.comment(stderr.trim())
116    t.comment(stdout.trim())
117    t.same(JSON.parse(stdout), {
118      broken: {
119        wanted: 'linked',
120        latest: 'linked',
121        type: 'dependencies',
122        location: ''
123      }
124    })
125    t.done()
126  })
127})
128
129test('cleanup', function (t) {
130  server.close()
131  cleanup()
132  t.done()
133})
134