• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// this is a test for fix #2538
2
3// the false_name-test-package has the name property 'test-package' set
4// in the package.json and a dependency named 'test-package' is also a
5// defined dependency of 'test-package-with-one-dep'.
6//
7// this leads to a conflict during installation and the fix is covered
8// by this test
9
10var fs = require('graceful-fs')
11var path = require('path')
12var existsSync = fs.existsSync || path.existsSync
13
14var mr = require('npm-registry-mock')
15var test = require('tap').test
16
17var common = require('../common-tap.js')
18
19var pkg = common.pkg
20var cache = common.cache
21var server
22
23var EXEC_OPTS = { cwd: pkg }
24
25var indexContent = 'module.exports = true\n'
26var json = {
27  name: 'test-package',
28  version: '0.0.0',
29  main: 'index.js',
30  dependencies: {
31    'test-package-with-one-dep': '0.0.0'
32  }
33}
34
35test('setup', function (t) {
36  t.comment('test for https://github.com/npm/npm/issues/2538')
37  setup()
38  mr({ port: common.port }, function (er, s) {
39    server = s
40    t.end()
41  })
42})
43
44test('not every pkg.name can be required', function (t) {
45  common.npm(
46    [
47      'install', '.',
48      '--cache', cache,
49      '--registry', common.registry
50    ],
51    EXEC_OPTS,
52    function (err, code) {
53      t.ifErr(err, 'install finished without error')
54      t.equal(code, 0, 'install exited ok')
55      t.ok(
56        existsSync(path.join(pkg, 'node_modules', 'test-package-with-one-dep')),
57        'test-package-with-one-dep installed OK'
58      )
59      t.ok(
60        existsSync(path.join(pkg, 'node_modules', 'test-package')),
61        'test-package subdep installed OK'
62      )
63      t.end()
64    }
65  )
66})
67
68test('cleanup', function (t) {
69  server.close()
70  t.end()
71})
72
73function setup () {
74  fs.writeFileSync(
75    path.join(pkg, 'package.json'),
76    JSON.stringify(json, null, 2)
77  )
78  fs.writeFileSync(path.join(pkg, 'index.js'), indexContent)
79}
80