• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2const path = require('path')
3const test = require('tap').test
4const Tacks = require('tacks')
5const File = Tacks.File
6const Dir = Tacks.Dir
7const common = require('../common-tap.js')
8
9const basedir = common.pkg
10const testdir = path.join(basedir, 'testdir')
11const cachedir = common.cache
12const globaldir = path.join(basedir, 'global')
13const tmpdir = path.join(basedir, 'tmp')
14
15const conf = {
16  cwd: testdir,
17  env: common.newEnv().extend({
18    npm_config_cache: cachedir,
19    npm_config_tmp: tmpdir,
20    npm_config_prefix: globaldir,
21    npm_config_registry: common.registry,
22    npm_config_loglevel: 'warn'
23  })
24}
25
26const fixture = new Tacks(Dir({
27  cache: Dir(),
28  global: Dir(),
29  tmp: Dir(),
30  testdir: Dir({
31    node_modules: Dir({
32      'foo-http': Dir({
33        'package.json': File({
34          name: 'foo-http',
35          version: '1.0.0'
36        })
37      }),
38      'foo-https': Dir({
39        'package.json': File({
40          name: 'foo-https',
41          version: '1.0.0'
42        })
43      })
44    }),
45    'package.json': File({
46      name: 'outdated-remote',
47      version: '1.0.0',
48      dependencies: {
49        'foo-http': 'http://example.com/foo.tar.gz',
50        'foo-https': 'https://example.com/foo.tar.gz'
51      }
52    })
53  })
54}))
55
56function setup () {
57  fixture.create(basedir)
58}
59
60test('setup', t => {
61  setup()
62  return common.fakeRegistry.listen()
63})
64
65test('discovers new versions in outdated', t => {
66  return common.npm(['outdated', '--json'], conf).then(([code, stdout, stderr]) => {
67    t.is(code, 1, 'npm outdated completed successfully')
68    t.comment(stdout.trim())
69    t.comment(stderr.trim())
70    const data = JSON.parse(stdout)
71    t.same(data['foo-http'], {
72      current: '1.0.0',
73      wanted: 'remote',
74      latest: 'remote',
75      location: ''
76    })
77    t.same(data['foo-https'], {
78      current: '1.0.0',
79      wanted: 'remote',
80      latest: 'remote',
81      location: ''
82    })
83  })
84})
85
86test('cleanup', t => {
87  common.fakeRegistry.close()
88  t.done()
89})
90