Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRobert Kowalski <rok@kowalski.gd>2014-02-22 22:58:07 +0400
committerDomenic Denicola <domenic@domenicdenicola.com>2014-04-18 07:38:33 +0400
commitb553c130ea41014ab8f29a22d9074e97738e86d5 (patch)
tree0d17ef07c0d855e86c214d5565224cf4f4c5609b /test
parentd4d29d079ecf055c0e99023bb5ed265c32b139f2 (diff)
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
Diffstat (limited to 'test')
-rw-r--r--test/tap/ls-depth-cli.js83
-rw-r--r--test/tap/ls-depth/package.json8
2 files changed, 91 insertions, 0 deletions
diff --git a/test/tap/ls-depth-cli.js b/test/tap/ls-depth-cli.js
new file mode 100644
index 000000000..3e0dd0eb9
--- /dev/null
+++ b/test/tap/ls-depth-cli.js
@@ -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 test-package-with-one-dep@0.0.0")
+ t.doesNotHave(c, /test-package@0\.0\.0/
+ , "output not contains test-package@0.0.0")
+ 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 test-package-with-one-dep@0.0.0")
+ t.has(c, /test-package@0\.0\.0/
+ , "output contains test-package@0.0.0")
+ 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 test-package-with-one-dep@0.0.0")
+ t.has(c, /test-package@0\.0\.0/
+ , "output contains test-package@0.0.0")
+ t.end()
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
diff --git a/test/tap/ls-depth/package.json b/test/tap/ls-depth/package.json
new file mode 100644
index 000000000..06f8e48a9
--- /dev/null
+++ b/test/tap/ls-depth/package.json
@@ -0,0 +1,8 @@
+{
+ "author": "Rocko Artischocko",
+ "name": "ls-depth",
+ "version": "0.0.0",
+ "dependencies": {
+ "test-package-with-one-dep": "0.0.0"
+ }
+}