1var common = require('../common-tap') 2var test = require('tap').test 3var path = require('path') 4var cwd = path.resolve(__dirname, '..', '..') 5var fs = require('fs') 6 7test('npm ls in npm', function (t) { 8 t.ok(fs.existsSync(cwd), 'ensure that the path we are calling ls within exists') 9 var files = fs.readdirSync(cwd) 10 t.notEqual(files.length, 0, 'ensure there are files in the directory we are to ls') 11 12 var opt = { cwd: cwd, stdio: [ 'ignore', 'pipe', 2 ] } 13 common.npm(['ls', '--json'], opt, function (err, code, stdout) { 14 t.ifError(err, 'error should not exist') 15 t.equal(code, 0, 'npm ls exited with code') 16 const tree = JSON.parse(stdout).dependencies 17 // We need to have a toplevel `node-gyp` available, but we also need to 18 // make sure npm-lifecycle's version is updated in concert. 19 // See https://github.com/npm/npm/issues/20163 20 t.deepEqual( 21 tree['npm-lifecycle'].dependencies['node-gyp'].version, 22 tree['node-gyp'].version, 23 'npm-lifecycle and npm using same version of node-gyp' 24 ) 25 t.end() 26 }) 27}) 28