1var fs = require('graceful-fs') 2var path = require('path') 3 4var mr = require('npm-registry-mock') 5var test = require('tap').test 6 7var common = require('../common-tap') 8 9var pkg = common.pkg 10 11var EXEC_OPTS = { cwd: pkg } 12 13var json = { 14 name: 'ls-env', 15 version: '0.0.0', 16 dependencies: { 17 'test-package-with-one-dep': '0.0.0', 18 'test-repo-url-ssh': '0.0.1' 19 }, 20 devDependencies: { 21 'test-package-with-one-dep': '0.0.0', 22 'test-repo-url-https': '0.0.1' 23 } 24} 25 26test('setup', function (t) { 27 fs.writeFileSync( 28 path.join(pkg, 'package.json'), 29 JSON.stringify(json, null, 2) 30 ) 31 mr({port: common.port}, function (er, s) { 32 common.npm( 33 [ 34 '--registry', common.registry, 35 'install' 36 ], 37 EXEC_OPTS, 38 function (er, c) { 39 if (er) throw er 40 t.equal(c, 0, 'install ran without issue') 41 s.close() 42 t.end() 43 } 44 ) 45 }) 46}) 47 48test('npm ls --dev', function (t) { 49 common.npm(['ls', '--dev'], EXEC_OPTS, function (er, code, stdout) { 50 if (er) throw er 51 t.equal(code, 0, 'ls --dev ran without issue') 52 t.has( 53 stdout, 54 /test-package-with-one-dep@0\.0\.0/, 55 'output contains test-package-with-one-dep@0.0.0' 56 ) 57 t.has( 58 stdout, 59 /test-repo-url-https@0\.0\.1/, 60 'output contains test-repo-url-https@0.0.1' 61 ) 62 t.doesNotHave( 63 stdout, 64 /test-repo-url-ssh@0\.0\.1/, 65 'output does NOT contain test-repo-url-ssh@0.0.1' 66 ) 67 t.end() 68 }) 69}) 70 71test('npm ls --only=development', function (t) { 72 common.npm(['ls', '--only=development'], EXEC_OPTS, function (er, code, stdout) { 73 if (er) throw er 74 t.equal(code, 0, 'ls --only=development ran without issue') 75 t.has( 76 stdout, 77 /test-package-with-one-dep@0\.0\.0/, 78 'output contains test-package-with-one-dep@0.0.0' 79 ) 80 t.end() 81 }) 82}) 83 84test('npm ls --only=dev', function (t) { 85 common.npm(['ls', '--only=dev'], EXEC_OPTS, function (er, code, stdout) { 86 if (er) throw er 87 t.equal(code, 0, 'ls --only=dev ran without issue') 88 t.has( 89 stdout, 90 /test-package-with-one-dep@0\.0\.0/, 91 'output contains test-package-with-one-dep@0.0.0' 92 ) 93 t.end() 94 }) 95}) 96 97test('npm ls --production', function (t) { 98 common.npm(['ls', '--production'], EXEC_OPTS, function (er, code, stdout) { 99 if (er) throw er 100 t.equal(code, 0, 'ls --production ran without issue') 101 t.has( 102 stdout, 103 /test-package-with-one-dep@0\.0\.0/, 104 'output contains test-package-with-one-dep@0.0.0' 105 ) 106 t.has( 107 stdout, 108 /test-repo-url-ssh@0\.0\.1/, 109 'output contains test-repo-url-ssh@0.0.1' 110 ) 111 t.doesNotHave( 112 stdout, 113 /test-repo-url-https@0\.0\.1/, 114 'output does NOT contain test-repo-url-https@0.0.1' 115 ) 116 t.end() 117 }) 118}) 119 120test('npm ls --prod', function (t) { 121 common.npm(['ls', '--prod'], EXEC_OPTS, function (er, code, stdout) { 122 if (er) throw er 123 t.equal(code, 0, 'ls --prod ran without issue') 124 t.has( 125 stdout, 126 /test-package-with-one-dep@0\.0\.0/, 127 'output contains test-package-with-one-dep@0.0.0' 128 ) 129 t.end() 130 }) 131}) 132 133test('npm ls --only=production', function (t) { 134 common.npm(['ls', '--only=production'], EXEC_OPTS, function (er, code, stdout) { 135 if (er) throw er 136 t.equal(code, 0, 'ls --only=production ran without issue') 137 t.has( 138 stdout, 139 /test-package-with-one-dep@0\.0\.0/, 140 'output contains test-package-with-one-dep@0.0.0' 141 ) 142 t.end() 143 }) 144}) 145 146test('npm ls --only=prod', function (t) { 147 common.npm(['ls', '--only=prod'], EXEC_OPTS, function (er, code, stdout) { 148 if (er) throw er 149 t.equal(code, 0, 'ls --only=prod ran without issue') 150 t.has( 151 stdout, 152 /test-package-with-one-dep@0\.0\.0/, 153 'output contains test-package-with-one-dep@0.0.0' 154 ) 155 t.end() 156 }) 157}) 158