Skip to content

Commit

Permalink
Add failing regression test for npm ls --depth=0
Browse files Browse the repository at this point in the history
This test should turn green if read-installed is fixed and should
avoid regressions in the future.

This tests the cli, as it turned out that the programatical version
of npm has a bug where depth=0 is not working
  • Loading branch information
robertkowalski authored and domenic committed Apr 18, 2014
1 parent d4d29d0 commit b553c13
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
83 changes: 83 additions & 0 deletions test/tap/ls-depth-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
var common = require('../common-tap')
, test = require('tap').test
, path = require('path')
, spawn = require('child_process').spawn
, rimraf = require('rimraf')
, mkdirp = require('mkdirp')
, pkg = __dirname + '/ls-depth'
, cache = pkg + '/cache'
, tmp = pkg + '/tmp'
, node = process.execPath
, npm = path.resolve(__dirname, '../../cli.js')
, mr = require('npm-registry-mock')

function run (command, t, cb) {
var c = ''
, child = spawn(node, command, {
cwd: pkg
})

child.stdout.on('data', function (chunk) {
c += chunk
})

child.stdout.on('end', function () {
if (test)
cb(t, c)
else
t.end()
})
}

function cleanup () {
rimraf.sync(pkg + '/cache')
rimraf.sync(pkg + '/tmp')
rimraf.sync(pkg + '/node_modules')
}

test('setup', function (t) {
cleanup()
mkdirp.sync(pkg + '/cache')
mkdirp.sync(pkg + '/tmp')
mr(common.port, function (s) {
run([npm, 'install', '--registry=' + common.registry], t, function (t, c) {
s.close()
t.end()
})
})
})

test('npm ls --depth=0', function (t) {
run([npm, 'ls', '--depth=0'], t, function (t, c) {
t.has(c, /test-package-with-one-dep@0\.0\.0/
, "output contains [email protected]")
t.doesNotHave(c, /test-package@0\.0\.0/
, "output not contains [email protected]")
t.end()
})
})

test('npm ls --depth=1', function (t) {
run([npm, 'ls', '--depth=1'], t, function (t, c) {
t.has(c, /test-package-with-one-dep@0\.0\.0/
, "output contains [email protected]")
t.has(c, /test-package@0\.0\.0/
, "output contains [email protected]")
t.end()
})
})

test('npm ls (no depth defined)', function (t) {
run([npm, 'ls'], t, function (t, c) {
t.has(c, /test-package-with-one-dep@0\.0\.0/
, "output contains [email protected]")
t.has(c, /test-package@0\.0\.0/
, "output contains [email protected]")
t.end()
})
})

test('cleanup', function (t) {
cleanup()
t.end()
})
8 changes: 8 additions & 0 deletions test/tap/ls-depth/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"author": "Rocko Artischocko",
"name": "ls-depth",
"version": "0.0.0",
"dependencies": {
"test-package-with-one-dep": "0.0.0"
}
}

0 comments on commit b553c13

Please sign in to comment.