forked from npm/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add failing regression test for npm ls --depth=0
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
1 parent
d4d29d0
commit b553c13
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |