• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var test = require('tap').test
3var Tacks = require('tacks')
4var Dir = Tacks.Dir
5var File = Tacks.File
6var common = require('../common-tap.js')
7
8var testdir = common.pkg
9var fixture = new Tacks(Dir({
10  node_modules: Dir({
11    a: Dir({
12      'package.json': File({
13        name: 'a',
14        version: '1.0.0',
15        dependencies: {
16          b: '1.0.0'
17        }
18      }),
19      node_modules: Dir({
20        b: Dir({
21          'package.json': File({
22            name: 'b',
23            version: '1.0.0'
24          })
25        })
26      })
27    })
28  }),
29  'b-src': Dir({
30    'package.json': File({
31      name: 'b',
32      version: '1.0.0'
33    })
34  })
35}))
36
37function setup () {
38  cleanup()
39  fixture.create(testdir)
40}
41
42function cleanup () {
43  fixture.remove(testdir)
44}
45
46test('setup', function (t) {
47  setup()
48  t.end()
49})
50
51test('install-report', function (t) {
52  common.npm(['install', '--no-save', '--json', './b-src'], {cwd: testdir}, function (err, code, stdout, stderr) {
53    if (err) throw err
54    t.is(code, 0, 'installed successfully')
55    t.is(stderr, '', 'no warnings')
56    try {
57      var report = JSON.parse(stdout)
58      t.pass('stdout was json')
59    } catch (ex) {
60      t.fail('stdout was json')
61      console.error(ex)
62      t.skip(2)
63      return t.end()
64    }
65    t.is(report.added.length, 1, 'one dependency reported as installed')
66    t.match(report.added, [{name: 'b'}], 'that dependency was `b`')
67    t.end()
68  })
69})
70
71test('cleanup', function (t) {
72  cleanup()
73  t.end()
74})
75