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

install-bad-dep-format.js « tap « test « npm « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d01996f15521273fd925e862170b44201c6f9dce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var fs = require('graceful-fs')
var path = require('path')

var mkdirp = require('mkdirp')
var osenv = require('osenv')
var rimraf = require('rimraf')
var test = require('tap').test

var common = require('../common-tap.js')

var json = {
  author: 'John Foo',
  name: 'bad-dep-format',
  version: '0.0.0',
  dependencies: {
    'not-legit': 'bad:not-legit@1.0'
  }
}

test('invalid url format returns appropriate error', function (t) {
  setup(json)
  common.npm(['install'], {}, function (err, code, stdout, stderr) {
    t.ifError(err, 'install ran without error')
    t.equals(code, 1, 'install exited with code 1')
    t.match(stderr,
      /ERR.*Unsupported URL Type/,
      'Error should report that invalid url-style formats are used')
    t.end()
  })
})

test('cleanup', function (t) {
  cleanup()
  t.end()
})

function setup (json) {
  cleanup()
  process.chdir(mkPkg(json))
}

function cleanup () {
  process.chdir(osenv.tmpdir())
  var pkgs = [json]
  pkgs.forEach(function (json) {
    rimraf.sync(path.resolve(common.pkg, json.name))
  })
}

function mkPkg (json) {
  var pkgPath = path.resolve(common.pkg, json.name)
  mkdirp.sync(pkgPath)
  fs.writeFileSync(
    path.join(pkgPath, 'package.json'),
    JSON.stringify(json, null, 2)
  )
  return pkgPath
}