• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var common = require('../common-tap.js')
2var test = require('tap').test
3
4test('cache add', function (t) {
5  setup(function (er, s) {
6    if (er) {
7      throw er
8    }
9    common.npm(
10      [
11        'cache',
12        'add',
13        'superfoo',
14        '--registry=http://localhost:' + common.port + '/'
15      ],
16      {},
17      function (er, c, so, se) {
18        if (er) throw er
19        t.ok(c, 'got non-zero exit code')
20        t.equal(so, '', 'nothing printed to stdout')
21        t.similar(se, /404 Not Found.*superfoo/, 'got expected error')
22        s.close()
23        t.end()
24      }
25    )
26  })
27})
28
29function setup (cb) {
30  var s = require('http').createServer(function (req, res) {
31    res.statusCode = 404
32    res.end('{"error":"not_found"}\n')
33  })
34  s.listen(common.port, function () {
35    cb(null, s)
36  })
37}
38