• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var fs = require('fs')
3var test = require('tap').test
4var Tacks = require('tacks')
5var File = Tacks.File
6var Dir = Tacks.Dir
7var common = require('../common-tap.js')
8var testdir = common.pkg
9
10var fixture = new Tacks(
11  Dir({
12    node_modules: Dir({
13      'a': Dir({
14        'package.json': File({
15          _requested: {
16            rawSpec: 'file:///mods/a'
17          },
18          dependencies: {
19            'b': 'file:///mods/b'
20          },
21          name: 'a',
22          version: '1.0.0'
23        })
24      }),
25      'b': Dir({
26        'package.json': File({
27          _requested: {
28            rawSpec: 'file:///mods/b'
29          },
30          dependencies: {
31            'a': 'file:///mods/a'
32          },
33          name: 'b',
34          version: '1.0.0'
35        })
36      })
37    }),
38    'package.json': File({
39      name: 'test',
40      version: '1.0.0',
41      devDependencies: {
42        'a': 'file:///mods/a'
43      }
44    })
45  })
46)
47
48function setup () {
49  cleanup()
50  fixture.create(testdir)
51}
52
53function cleanup () {
54  fixture.remove(testdir)
55}
56
57test('setup', function (t) {
58  setup()
59  t.end()
60})
61
62function readdir (dir) {
63  try {
64    return fs.readdirSync(dir)
65  } catch (ex) {
66    if (ex.code === 'ENOENT') return []
67    throw ex
68  }
69}
70
71test('prune cycle in dev deps', function (t) {
72  common.npm(['prune', '--production', '--json'], {cwd: testdir}, function (err, code, stdout, stderr) {
73    if (err) throw err
74    t.is(code, 0, 'prune finished successfully')
75    t.like(JSON.parse(stdout), {removed: [{name: 'a'}, {name: 'b'}]}, 'removed the right modules')
76    var dirs = readdir(testdir + '/node_modules').sort()
77    t.same(dirs, [])
78    t.end()
79  })
80})
81
82test('cleanup', function (t) {
83  cleanup()
84  t.end()
85})
86