|
| 1 | +'use strict' |
| 2 | +const path = require('path') |
| 3 | +const test = require('tap').test |
| 4 | +const Tacks = require('tacks') |
| 5 | +const File = Tacks.File |
| 6 | +const Dir = Tacks.Dir |
| 7 | +const common = require('../common-tap.js') |
| 8 | + |
| 9 | +const basedir = path.join(__dirname, path.basename(__filename, '.js')) |
| 10 | +const testdir = path.join(basedir, 'testdir') |
| 11 | +const cachedir = path.join(basedir, 'cache') |
| 12 | +const globaldir = path.join(basedir, 'global') |
| 13 | +const tmpdir = path.join(basedir, 'tmp') |
| 14 | + |
| 15 | +const 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 | + |
| 26 | +const 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 | + |
| 56 | +function setup () { |
| 57 | + cleanup() |
| 58 | + fixture.create(basedir) |
| 59 | +} |
| 60 | + |
| 61 | +function cleanup () { |
| 62 | + fixture.remove(basedir) |
| 63 | +} |
| 64 | + |
| 65 | +test('setup', t => { |
| 66 | + setup() |
| 67 | + return common.fakeRegistry.listen() |
| 68 | +}) |
| 69 | + |
| 70 | +test('discovers new versions in outdated', t => { |
| 71 | + return common.npm(['outdated', '--json'], conf).then(([code, stdout, stderr]) => { |
| 72 | + t.is(code, 1, 'npm outdated completed successfully') |
| 73 | + t.comment(stdout.trim()) |
| 74 | + t.comment(stderr.trim()) |
| 75 | + const data = JSON.parse(stdout) |
| 76 | + t.same(data['foo-http'], { |
| 77 | + current: '1.0.0', |
| 78 | + wanted: 'remote', |
| 79 | + latest: 'remote', |
| 80 | + location: '' |
| 81 | + }) |
| 82 | + t.same(data['foo-https'], { |
| 83 | + current: '1.0.0', |
| 84 | + wanted: 'remote', |
| 85 | + latest: 'remote', |
| 86 | + location: '' |
| 87 | + }) |
| 88 | + }) |
| 89 | +}) |
| 90 | + |
| 91 | +test('cleanup', t => { |
| 92 | + common.fakeRegistry.close() |
| 93 | + cleanup() |
| 94 | + t.done() |
| 95 | +}) |
0 commit comments