• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var path = require('path')
3var test = require('tap').test
4var mr = require('npm-registry-mock')
5var Tacks = require('tacks')
6var File = Tacks.File
7var Dir = Tacks.Dir
8var common = require('../common-tap.js')
9
10var basedir = path.join(__dirname, path.basename(__filename, '.js'))
11var testdir = path.join(basedir, 'testdir')
12var cachedir = path.join(basedir, 'cache')
13var globaldir = path.join(basedir, 'global')
14var tmpdir = path.join(basedir, 'tmp')
15
16var conf = {
17  cwd: testdir,
18  env: Object.assign({}, process.env, {
19    npm_config_cache: cachedir,
20    npm_config_tmp: tmpdir,
21    npm_config_prefix: globaldir,
22    npm_config_registry: common.registry,
23    npm_config_loglevel: 'warn'
24  })
25}
26
27var expected = {
28  name: 'npm-test-peer-deps-toplevel',
29  version: '0.0.0',
30  problems: [
31    'peer dep missing: mkdirp@*, required by npm-test-peer-deps-toplevel@0.0.0',
32    'peer dep missing: request@0.9.x, required by npm-test-peer-deps@0.0.0'
33  ],
34  dependencies: {
35    'npm-test-peer-deps': {
36      version: '0.0.0',
37      resolved: common.registry + '/npm-test-peer-deps/-/npm-test-peer-deps-0.0.0.tgz',
38      dependencies: {
39        underscore: {
40          version: '1.3.1',
41          resolved: common.registry + '/underscore/-/underscore-1.3.1.tgz'
42        }
43      }
44    },
45    mkdirp: {
46      peerMissing: true,
47      required: {
48        _id: 'mkdirp@*',
49        name: 'mkdirp',
50        version: '*',
51        peerMissing: [
52          {requiredBy: 'npm-test-peer-deps-toplevel@0.0.0', requires: 'mkdirp@*'}
53        ],
54        dependencies: {}
55      }
56    },
57    request: {
58      peerMissing: true,
59      required: {
60        _id: 'request@0.9.x',
61        dependencies: {},
62        name: 'request',
63        peerMissing: [
64          {requiredBy: 'npm-test-peer-deps@0.0.0', requires: 'request@0.9.x'}
65        ],
66        version: '0.9.x'
67      }
68    }
69  }
70}
71
72var server
73var fixture = new Tacks(Dir({
74  cache: Dir(),
75  global: Dir(),
76  tmp: Dir(),
77  testdir: Dir({
78    'package.json': File({
79      name: 'npm-test-peer-deps-toplevel',
80      version: '0.0.0',
81      dependencies: {
82        'npm-test-peer-deps': '*'
83      },
84      peerDependencies: {
85        mkdirp: '*'
86      }
87    })
88  })
89}))
90
91function setup () {
92  cleanup()
93  fixture.create(basedir)
94}
95
96function cleanup () {
97  fixture.remove(basedir)
98}
99
100test('setup', function (t) {
101  setup()
102  mr({port: common.port, throwOnUnmatched: true}, function (err, s) {
103    if (err) throw err
104    server = s
105    t.done()
106  })
107})
108
109test('installs the peer dependency directory structure', function (t) {
110  common.npm(['install'], conf, function (err, code, stdout, stderr) {
111    if (err) throw err
112    t.is(code, 0, 'install ran ok even w/ missing peeer deps')
113    t.comment(stdout.trim())
114    t.comment(stderr.trim())
115
116    common.npm(['ls', '--json'], conf, function (err, code, stdout, stderr) {
117      if (err) throw err
118      t.is(code, 1, 'missing peer deps _are_ an ls error though')
119      t.comment(stderr.trim())
120      var results = JSON.parse(stdout)
121
122      t.deepEqual(results, expected, 'got expected output from ls')
123      t.done()
124    })
125  })
126})
127
128test('cleanup', function (t) {
129  server.close()
130  cleanup()
131  t.done()
132})
133