• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var path = require('path')
3var test = require('tap').test
4var fs = require('fs')
5var Tacks = require('tacks')
6var File = Tacks.File
7var Dir = Tacks.Dir
8var common = require('../common-tap.js')
9
10var basedir = common.pkg
11var testdir = path.join(basedir, 'testdir')
12var cachedir = common.cache
13var globaldir = path.join(basedir, 'global')
14var tmpdir = path.join(basedir, 'tmp')
15
16var conf = {
17  cwd: testdir,
18  env: Object.assign({}, process.env, {
19    npm_config_cache: cachedir,
20    npm_config_tmp: tmpdir,
21    npm_config_prefix: globaldir,
22    npm_config_registry: common.registry,
23    npm_config_loglevel: 'error'
24  })
25}
26
27var fixture = new Tacks(Dir({
28  cache: Dir(),
29  global: Dir(),
30  tmp: Dir(),
31  testdir: Dir({
32    node_modules: Dir({
33      '@npmtest': Dir({
34        example: Dir({
35          'package.json': File({
36            name: '@npmtest/example',
37            version: '1.0.0'
38          })
39        })
40      })
41    }),
42    'package.json': File({
43      name: 'shrinkwrap-default-dev',
44      version: '1.0.0',
45      devDependencies: {
46        '@npmtest/example': '1.0.0'
47      }
48    })
49  })
50}))
51
52var shrinkwrapPath = path.join(testdir, 'npm-shrinkwrap.json')
53var shrinkwrapWithDev = {
54  name: 'shrinkwrap-default-dev',
55  version: '1.0.0',
56  dependencies: {
57    '@npmtest/example': {
58      'version': '1.0.0',
59      'dev': true
60    }
61  }
62}
63
64function setup () {
65  cleanup()
66  fixture.create(basedir)
67}
68
69function cleanup () {
70  fixture.remove(basedir)
71}
72
73test('setup', function (t) {
74  setup()
75  t.done()
76})
77
78test('shrinkwrap-default-dev', function (t) {
79  common.npm(['shrinkwrap'], conf, function (err, code, stdout, stderr) {
80    if (err) throw err
81    t.is(code, 0, 'command ran ok')
82    t.comment(stdout.trim())
83    t.comment(stderr.trim())
84    var swrap = JSON.parse(fs.readFileSync(shrinkwrapPath))
85    t.isDeeply(swrap.dependencies, shrinkwrapWithDev.dependencies, 'Shrinkwrap included dev deps by default')
86    t.done()
87  })
88})
89
90test('cleanup', function (t) {
91  cleanup()
92  t.done()
93})
94