1'use strict' 2var test = require('tap').test 3var Bluebird = require('bluebird') 4var Tacks = require('tacks') 5var File = Tacks.File 6var Dir = Tacks.Dir 7var fs = require('fs') 8var path = require('path') 9var common = require('../common-tap.js') 10 11var testdir = common.pkg 12var modAtgz = path.resolve(testdir, 'modA') + '-1.0.0.tgz' 13var modB1tgz = path.resolve(testdir, 'modB') + '-1.0.0.tgz' 14var modB2tgz = path.resolve(testdir, 'modB') + '-2.0.0.tgz' 15var modCtgz = path.resolve(testdir, 'modC') + '-1.0.0.tgz' 16 17var fixture = new Tacks(Dir({ 18 'package.json': File({ 19 dependencies: { 20 modA: 'file://' + modAtgz, 21 modC: 'file://' + modCtgz 22 } 23 }), 24 'npm-shrinkwrap.json': File({ 25 dependencies: { 26 modA: { 27 version: '1.0.0', 28 resolved: 'file://' + modAtgz 29 }, 30 modB: { 31 version: '1.0.0', 32 resolved: 'file://' + modB1tgz 33 } 34 } 35 }), 36 'modA': Dir({ 37 'package.json': File({ 38 name: 'modA', 39 version: '1.0.0', 40 dependencies: { 41 'modB': 'file://' + modB1tgz 42 } 43 }) 44 }), 45 'modB@1': Dir({ 46 'package.json': File({ 47 name: 'modB', 48 version: '1.0.0' 49 }), 50 'B1': File('') 51 }), 52 'modB@2': Dir({ 53 'package.json': File({ 54 name: 'modB', 55 version: '2.0.0' 56 }), 57 'B2': File('') 58 }), 59 'modC': Dir({ 60 'package.json': File({ 61 name: 'modC', 62 version: '1.0.0', 63 dependencies: { 64 'modB': 'file://' + modB2tgz 65 } 66 }) 67 }) 68})) 69 70var newShrinkwrap = new Tacks(Dir({ 71 'npm-shrinkwrap.json': File({ 72 dependencies: { 73 modA: { 74 version: '1.0.0', 75 resolved: 'file://' + modAtgz 76 }, 77 modB: { 78 version: '1.0.0', 79 resolved: 'file://' + modB1tgz 80 }, 81 modC: { 82 version: '1.0.0', 83 resolved: 'file://' + modCtgz, 84 dependencies: { 85 modB: { 86 version: '1.0.0', 87 resolved: 'file://' + modB1tgz 88 } 89 } 90 } 91 } 92 }), 93 'node_modules': Dir({ 94 'modB@1': Dir({ 95 'package.json': File({ 96 _requested: { 97 name: 'modB', 98 raw: 'modB@file:' + modB1tgz, 99 rawSpec: 'file:' + modB1tgz, 100 scope: null, 101 spec: modB1tgz, 102 type: 'directory' 103 }, 104 dependencies: { }, 105 devDependencies: { }, 106 name: 'modB', 107 optionalDependencies: { }, 108 readme: 'ERROR: No README data found!', 109 version: '1.0.0' 110 }) 111 }) 112 }) 113})) 114 115function setup () { 116 fixture.create(testdir) 117} 118 119function cleanup () { 120 fixture.remove(testdir) 121} 122 123test('setup', function (t) { 124 cleanup() 125 setup() 126 return Bluebird.try(() => { 127 return Bluebird.join( 128 common.npm(['pack', 'file:modB@1'], {cwd: testdir, stdio: [0, 2, 2]}), 129 common.npm(['pack', 'file:modB@2'], {cwd: testdir, stdio: [0, 2, 2]}), 130 function (b1, b2) { 131 t.is(b1[0], 0, 'pack modB@1') 132 t.is(b2[0], 0, 'pack modB@2') 133 }) 134 }).then(() => { 135 return Bluebird.join( 136 common.npm(['pack', 'file:modA'], {cwd: testdir, stdio: [0, 2, 2]}), 137 common.npm(['pack', 'file:modC'], {cwd: testdir, stdio: [0, 2, 2]}), 138 function (a, c) { 139 t.is(a[0], 0, 'pack modA') 140 t.is(c[0], 0, 'pack modC') 141 }) 142 }).then(() => { 143 return common.npm(['install'], {cwd: testdir, stdio: [0, 2, 2]}) 144 }).spread((code) => { 145 t.is(code, 0, 'top level install') 146 t.end() 147 }) 148}) 149 150test('incremental install', function (t) { 151 newShrinkwrap.create(testdir) 152 common.npm(['install'], {cwd: testdir, stdio: [0, 2, 2]}, function (err, code) { 153 if (err) throw err 154 t.is(code, 0, 'npm itself completed ok') 155 fs.stat(path.join(testdir, 'node_modules', 'modC', 'node_modules', 'modB', 'B1'), function (missing) { 156 t.ok(!missing, 'modC got the updated version of modB') 157 t.end() 158 }) 159 }) 160}) 161 162test('cleanup', function (t) { 163 cleanup() 164 t.end() 165}) 166