• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1const fs = require('graceful-fs')
2const path = require('path')
3
4const mkdirp = require('mkdirp')
5const t = require('tap')
6
7const common = require('../common-tap.js')
8
9const pkg = common.pkg + '/package'
10
11const EXEC_OPTS = {
12  cwd: pkg,
13  stdio: [0, 1, 2],
14  env: common.newEnv().extend({
15    npm_config_registry: common.registry
16  })
17}
18
19const localDependencyJson = {
20  name: 'local-dependency',
21  version: '0.0.0',
22  dependencies: {
23    'test-package': '0.0.0'
24  }
25}
26
27const dependentJson = {
28  name: 'dependent',
29  version: '0.0.0',
30  dependencies: {
31    'local-dependency': '../local-dependency'
32  }
33}
34
35const target = path.resolve(pkg, '../local-dependency')
36const mr = require('npm-registry-mock')
37let server
38t.teardown(() => {
39  if (server) {
40    server.close()
41  }
42})
43
44t.test('setup', function (t) {
45  mkdirp.sync(target)
46  fs.writeFileSync(
47    path.join(target, 'package.json'),
48    JSON.stringify(localDependencyJson, null, 2)
49  )
50  mkdirp.sync(pkg)
51  fs.writeFileSync(
52    path.join(pkg, 'package.json'),
53    JSON.stringify(dependentJson, null, 2)
54  )
55  mr({ port: common.port }, (er, s) => {
56    if (er) {
57      throw er
58    }
59    server = s
60    t.end()
61  })
62})
63
64t.test('\'npm install\' should install local pkg from sub path', function (t) {
65  common.npm(['install', '--loglevel=silent'], EXEC_OPTS, function (err, code) {
66    if (err) throw err
67    t.equal(code, 0, 'npm install exited with code')
68    t.ok(fs.statSync(path.resolve(pkg, 'node_modules/local-dependency/package.json')).isFile(), 'local dependency package.json exists')
69    t.ok(fs.statSync(path.resolve(pkg, 'node_modules/local-dependency/node_modules/test-package')).isDirectory(), 'transitive dependency installed')
70    t.end()
71  })
72})
73
74t.test('\'npm ci\' should work', function (t) {
75  common.npm(['ci', '--loglevel=silent'], EXEC_OPTS, function (err, code) {
76    if (err) throw err
77    t.equal(code, 0, 'npm install exited with code')
78    t.ok(fs.statSync(path.resolve(pkg, 'node_modules/local-dependency/package.json')).isFile(), 'local dependency package.json exists')
79    t.ok(fs.statSync(path.resolve(pkg, 'node_modules/local-dependency/node_modules/test-package')).isDirectory(), 'transitive dependency installed')
80    t.end()
81  })
82})
83