• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fs = require('fs')
2var path = require('path')
3
4var mkdirp = require('mkdirp')
5var mr = require('npm-registry-mock')
6var rimraf = require('rimraf')
7var test = require('tap').test
8
9var common = require('../common-tap.js')
10
11var pkg = common.pkg
12
13var opts = {
14  env: common.newEnv().extend({
15    npm_config_cache: common.cache,
16    npm_config_registry: common.registry
17  }),
18  stdio: [0, 1, 2],
19  cwd: pkg
20}
21
22var json = {
23  author: 'Domenic Denicola',
24  name: 'npm-test-shrinkwrap-shared-dev-dependency',
25  version: '0.0.0',
26  dependencies: {
27    'test-package-with-one-dep': '0.0.0'
28  },
29  devDependencies: {
30    'test-package': '0.0.0'
31  }
32}
33
34var server
35test('setup', function (t) {
36  setup()
37  mr({ port: common.port }, function (er, s) {
38    if (er) throw er
39    server = s
40    t.done()
41  })
42})
43
44var desired = {
45  name: 'npm-test-shrinkwrap-shared-dev-dependency',
46  version: '0.0.0',
47  dependencies: {
48    'test-package-with-one-dep': {
49      version: '0.0.0',
50      resolved: common.registry + '/test-package-with-one-dep/-/test-package-with-one-dep-0.0.0.tgz',
51      integrity: 'sha1-JWwVltusKyPRImjatagCuy42Wsg='
52    },
53    'test-package': {
54      version: '0.0.0',
55      resolved: common.registry + '/test-package/-/test-package-0.0.0.tgz',
56      integrity: 'sha1-sNMrbEXCWcV4uiADdisgUTG9+9E='
57    }
58  }
59}
60
61test("shrinkwrap doesn't strip out the shared dependency", function (t) {
62  t.plan(3)
63
64  return common.npm(['install'], opts).spread((code) => {
65    t.is(code, 0, 'install')
66    return common.npm(['shrinkwrap'], opts)
67  }).spread((code) => {
68    t.is(code, 0, 'shrinkwrap')
69    var results = JSON.parse(fs.readFileSync(`${pkg}/npm-shrinkwrap.json`))
70    t.like(results.dependencies, desired.dependencies)
71    t.end()
72  })
73})
74
75test('cleanup', function (t) {
76  server.close()
77  cleanup()
78  t.end()
79})
80
81function setup () {
82  cleanup()
83  mkdirp.sync(pkg)
84  fs.writeFileSync(path.join(pkg, 'package.json'), JSON.stringify(json, null, 2))
85}
86
87function cleanup () {
88  rimraf.sync(pkg)
89}
90