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
diff options
context:
space:
mode:
authorKat Marchán <kzm@sykosomatic.org>2016-05-13 05:27:01 +0300
committerKat Marchán <kzm@sykosomatic.org>2016-05-20 00:34:13 +0300
commitc698ae666afc92fbc0fcba3c082cfa9b34a4420d (patch)
treecc2c6a1b82b403c386c96327211a05d3cdc8d5a5
parent5ed4b58409eeb134bca1c96252682fd7600d9906 (diff)
test: adding some basic npm ls tests
Credit: @zkat PR-URL: https://github.com/npm/npm/pull/12685 Reviewed-By: @othiym23
-rw-r--r--test/tap/ls.js151
1 files changed, 151 insertions, 0 deletions
diff --git a/test/tap/ls.js b/test/tap/ls.js
new file mode 100644
index 000000000..f75811ec8
--- /dev/null
+++ b/test/tap/ls.js
@@ -0,0 +1,151 @@
+'use strict'
+var test = require('tap').test
+var path = require('path')
+var rimraf = require('rimraf')
+var common = require('../common-tap.js')
+var basepath = path.resolve(__dirname, path.basename(__filename, '.js'))
+var fixturepath = path.resolve(basepath, 'npm-test-files')
+var pkgpath = path.resolve(fixturepath, 'npm-test-ls')
+var Tacks = require('tacks')
+var File = Tacks.File
+var Dir = Tacks.Dir
+
+test('ls without arg', function (t) {
+ var fixture = new Tacks(
+ Dir({
+ 'npm-test-ls': Dir({
+ 'package.json': File({
+ name: 'npm-test-ls',
+ version: '1.0.0',
+ dependencies: {
+ 'dep': 'file:../dep'
+ }
+ })
+ }),
+ 'dep': Dir({
+ 'package.json': File({
+ name: 'dep',
+ version: '1.0.0'
+ })
+ })
+ })
+ )
+ withFixture(t, fixture, function (done) {
+ common.npm([
+ 'ls', '--json'
+ ], {
+ cwd: pkgpath
+ }, function (err, code, stdout, stderr) {
+ t.ifErr(err, 'ls succeeded')
+ t.equal(0, code, 'exit 0 on ls')
+ var pkg = JSON.parse(stdout)
+ var deps = pkg.dependencies
+ t.ok(deps.dep, 'dep present')
+ done()
+ })
+ })
+})
+
+test('ls with filter arg', function (t) {
+ var fixture = new Tacks(
+ Dir({
+ 'npm-test-ls': Dir({
+ 'package.json': File({
+ name: 'npm-test-ls',
+ version: '1.0.0',
+ dependencies: {
+ 'dep': 'file:../dep'
+ }
+ })
+ }),
+ 'dep': Dir({
+ 'package.json': File({
+ name: 'dep',
+ version: '1.0.0'
+ })
+ }),
+ 'otherdep': Dir({
+ 'package.json': File({
+ name: 'otherdep',
+ version: '1.0.0'
+ })
+ })
+ })
+ )
+ withFixture(t, fixture, function (done) {
+ common.npm([
+ 'ls', 'dep',
+ '--json'
+ ], {
+ cwd: path.join(fixturepath, 'npm-test-ls')
+ }, function (err, code, stdout, stderr) {
+ t.ifErr(err, 'ls succeeded')
+ t.equal(0, code, 'exit 0 on ls')
+ var pkg = JSON.parse(stdout)
+ var deps = pkg.dependencies
+ t.ok(deps.dep, 'dep present')
+ t.notOk(deps.otherdep, 'other dep not present')
+ done()
+ })
+ })
+})
+
+test('ls with missing filtered arg', function (t) {
+ var fixture = new Tacks(
+ Dir({
+ 'npm-test-ls': Dir({
+ 'package.json': File({
+ name: 'npm-test-ls',
+ version: '1.0.0',
+ dependencies: {
+ 'dep': 'file:../dep'
+ }
+ })
+ }),
+ 'dep': Dir({
+ 'package.json': File({
+ name: 'dep',
+ version: '1.0.0'
+ })
+ })
+ })
+ )
+ withFixture(t, fixture, function (done) {
+ common.npm([
+ 'ls', 'notadep',
+ '--json'
+ ], {
+ cwd: path.join(fixturepath, 'npm-test-ls')
+ }, function (err, code, stdout, stderr) {
+ t.ifErr(err, 'ls succeeded')
+ t.equal(1, code, 'exit 1 on ls')
+ var pkg = JSON.parse(stdout)
+ var deps = pkg.dependencies
+ t.notOk(deps, 'deps missing')
+ t.done()
+ })
+ })
+})
+
+test('cleanup', function (t) {
+ rimraf.sync(basepath)
+ t.done()
+})
+
+function withFixture (t, fixture, tester) {
+ fixture.create(fixturepath)
+ common.npm(['install'], {
+ cwd: path.join(fixturepath, 'npm-test-ls')
+ }, checkAndTest)
+ function checkAndTest (err, code) {
+ if (err) throw err
+ t.is(code, 0, 'install went ok')
+ tester(removeAndDone)
+ }
+ function removeAndDone (err) {
+ if (err) throw err
+ fixture.remove(fixturepath)
+ rimraf.sync(basepath)
+ t.done()
+ }
+}