• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fs = require('graceful-fs')
2var path = require('path')
3
4var mr = require('npm-registry-mock')
5var test = require('tap').test
6
7var common = require('../common-tap.js')
8
9var pkg = common.pkg
10
11var EXEC_OPTS = { cwd: pkg, stdio: [0, 'pipe', 2] }
12
13var json = {
14  name: 'uninstall-package',
15  version: '0.0.0',
16  dependencies: {
17    underscore: '~1.3.1',
18    request: '~0.9.0',
19    '@isaacs/namespace-test': '1.x'
20  }
21}
22
23test('setup', function (t) {
24  fs.writeFileSync(
25    path.join(pkg, 'package.json'),
26    JSON.stringify(json, null, 2)
27  )
28  t.end()
29})
30
31test('returns a list of removed items', function (t) {
32  mr({ port: common.port }, function (er, s) {
33    common.npm(
34      [
35        '--registry', common.registry,
36        '--loglevel', 'error',
37        'install', '.'
38      ],
39      EXEC_OPTS,
40      function (err, code, stdout, stderr) {
41        if (err) throw err
42        t.notOk(code, 'install ran without raising error code')
43        common.npm(
44          [
45            '--registry', common.registry,
46            '--loglevel', 'error',
47            '--parseable',
48            'uninstall', 'underscore', 'request', 'lala'
49          ],
50          EXEC_OPTS,
51          function (err, code, stdout, stderr) {
52            if (err) throw err
53            t.notOk(code, 'uninstall ran without raising error code')
54            t.has(stdout, /^remove\tunderscore\t1.3.3\t/m, 'underscore uninstalled')
55            t.has(stdout, /^remove\trequest\t0.9.5\t/m, 'request uninstalled')
56
57            s.close()
58            t.end()
59          }
60        )
61      }
62    )
63  })
64})
65
66test('does not fail if installed package lacks a name somehow', function (t) {
67  const scope = path.resolve(pkg, 'node_modules/@isaacs')
68  const scopePkg = path.resolve(scope, 'namespace-test')
69  const pj = path.resolve(scopePkg, 'package.json')
70  fs.writeFileSync(pj, JSON.stringify({
71    lol: 'yolo',
72    name: 99
73  }))
74  common.npm(
75    ['uninstall', '@isaacs/namespace-test'],
76    EXEC_OPTS,
77    function (err, code, stdout, stderr) {
78      if (err) throw err
79      t.equal(code, 0, 'should exit successfully')
80      t.has(stdout, /removed 1 package in/)
81      t.notOk(fs.existsSync(scope), 'scoped package removed')
82      t.end()
83    }
84  )
85})
86