1'use strict' 2var test = require('tap').test 3var path = require('path') 4var rimraf = require('rimraf') 5var common = require('../common-tap.js') 6var basepath = common.pkg 7var fixturepath = path.resolve(basepath, 'npm-test-files') 8var pkgpath = path.resolve(fixturepath, 'npm-test-ls') 9var Tacks = require('tacks') 10var File = Tacks.File 11var Dir = Tacks.Dir 12 13test('ls without arg', function (t) { 14 var fixture = new Tacks( 15 Dir({ 16 'npm-test-ls': Dir({ 17 'package.json': File({ 18 name: 'npm-test-ls', 19 version: '1.0.0', 20 dependencies: { 21 'dep': 'file:../dep' 22 } 23 }) 24 }), 25 'dep': Dir({ 26 'package.json': File({ 27 name: 'dep', 28 version: '1.0.0' 29 }) 30 }) 31 }) 32 ) 33 withFixture(t, fixture, function (done) { 34 common.npm([ 35 'ls', '--json' 36 ], { 37 cwd: pkgpath 38 }, function (err, code, stdout, stderr) { 39 t.ifErr(err, 'ls succeeded') 40 t.equal(0, code, 'exit 0 on ls') 41 var pkg = JSON.parse(stdout) 42 var deps = pkg.dependencies 43 t.ok(deps.dep, 'dep present') 44 done() 45 }) 46 }) 47}) 48 49test('ls with filter arg', function (t) { 50 var fixture = new Tacks( 51 Dir({ 52 'npm-test-ls': Dir({ 53 'package.json': File({ 54 name: 'npm-test-ls', 55 version: '1.0.0', 56 dependencies: { 57 'dep': 'file:../dep' 58 } 59 }) 60 }), 61 'dep': Dir({ 62 'package.json': File({ 63 name: 'dep', 64 version: '1.0.0' 65 }) 66 }), 67 'otherdep': Dir({ 68 'package.json': File({ 69 name: 'otherdep', 70 version: '1.0.0' 71 }) 72 }) 73 }) 74 ) 75 withFixture(t, fixture, function (done) { 76 common.npm([ 77 'ls', 'dep', 78 '--json' 79 ], { 80 cwd: path.join(fixturepath, 'npm-test-ls') 81 }, function (err, code, stdout, stderr) { 82 t.ifErr(err, 'ls succeeded') 83 t.equal(0, code, 'exit 0 on ls') 84 var pkg = JSON.parse(stdout) 85 var deps = pkg.dependencies 86 t.ok(deps.dep, 'dep present') 87 t.notOk(deps.otherdep, 'other dep not present') 88 done() 89 }) 90 }) 91}) 92 93test('ls with missing filtered arg', function (t) { 94 var fixture = new Tacks( 95 Dir({ 96 'npm-test-ls': Dir({ 97 'package.json': File({ 98 name: 'npm-test-ls', 99 version: '1.0.0', 100 dependencies: { 101 'dep': 'file:../dep' 102 } 103 }) 104 }), 105 'dep': Dir({ 106 'package.json': File({ 107 name: 'dep', 108 version: '1.0.0' 109 }) 110 }) 111 }) 112 ) 113 withFixture(t, fixture, function (done) { 114 common.npm([ 115 'ls', 'notadep', 116 '--json' 117 ], { 118 cwd: path.join(fixturepath, 'npm-test-ls') 119 }, function (err, code, stdout, stderr) { 120 t.ifErr(err, 'ls succeeded') 121 t.equal(1, code, 'exit 1 on ls') 122 var pkg = JSON.parse(stdout) 123 var deps = pkg.dependencies 124 t.notOk(deps, 'deps missing') 125 t.done() 126 }) 127 }) 128}) 129 130test('ls with prerelease pkg', function (t) { 131 var fixture = new Tacks( 132 Dir({ 133 'npm-test-ls': Dir({ 134 'package.json': File({ 135 name: 'npm-test-ls', 136 version: '1.0.0', 137 dependencies: { 138 'dep': 'file:../dep' 139 } 140 }) 141 }), 142 'dep': Dir({ 143 'package.json': File({ 144 name: 'dep', 145 version: '1.0.0-pre' 146 }) 147 }) 148 }) 149 ) 150 withFixture(t, fixture, function (done) { 151 common.npm([ 152 'ls', 'dep', 153 '--json' 154 ], { 155 cwd: path.join(fixturepath, 'npm-test-ls') 156 }, function (err, code, stdout, stderr) { 157 t.ifErr(err, 'ls succeeded') 158 t.equal(0, code, 'exit 0 on ls') 159 var pkg = JSON.parse(stdout) 160 var deps = pkg.dependencies 161 t.ok(deps.dep, 'dep present') 162 t.done() 163 }) 164 }) 165}) 166 167test('cleanup', function (t) { 168 rimraf.sync(basepath) 169 t.done() 170}) 171 172test('ls parseable long', function (t) { 173 var fixture = new Tacks( 174 Dir({ 175 'npm-test-ls': Dir({ 176 'package.json': File({ 177 name: 'npm-test-ls', 178 version: '1.0.0', 179 dependencies: { 180 'dep': 'file:../dep' 181 } 182 }) 183 }), 184 'dep': Dir({ 185 'package.json': File({ 186 name: 'dep', 187 version: '1.0.0' 188 }) 189 }) 190 }) 191 ) 192 withFixture(t, fixture, function (done) { 193 common.npm([ 194 'ls', '--parseable', '--long' 195 ], { 196 cwd: pkgpath 197 }, function (err, code, stdout, stderr) { 198 t.ifErr(err, 'ls succeeded') 199 t.equal(0, code, 'exit 0 on ls') 200 t.notMatch(stdout, /undefined/, 'must not output undefined for non-symlinked items') 201 done() 202 }) 203 }) 204}) 205 206function withFixture (t, fixture, tester) { 207 fixture.create(fixturepath) 208 common.npm(['install'], { 209 cwd: path.join(fixturepath, 'npm-test-ls') 210 }, checkAndTest) 211 function checkAndTest (err, code) { 212 if (err) throw err 213 t.is(code, 0, 'install went ok') 214 tester(removeAndDone) 215 } 216 function removeAndDone (err) { 217 if (err) throw err 218 fixture.remove(fixturepath) 219 rimraf.sync(basepath) 220 t.done() 221 } 222} 223