summaryrefslogtreecommitdiff
path: root/deps/node/deps/npm/test/tap/splat-with-only-prerelease-to-latest.js
blob: cf5aac110bd94a9dc4539dee7f5986a11f96c820 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
'use strict'

const common = require('../common-tap.js')
const mr = require('npm-registry-mock')
const npm = require('../../lib/npm')
const osenv = require('osenv')
const path = require('path')
const rimraf = require('rimraf')
const test = require('tap').test

const testdir = path.join(__dirname, path.basename(__filename, '.js'))

const moduleName = 'xyzzy-wibble'
const testModule = {
  name: moduleName,
  'dist-tags': {
    latest: '1.3.0-a',
    other: '1.2.0-a'
  },
  versions: {
    '1.0.0-a': {
      name: moduleName,
      version: '1.0.0-a',
      dist: {
        shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
        tarball: 'http://registry.npmjs.org/aproba/-/xyzzy-wibble-1.0.0-a.tgz'
      }
    },
    '1.1.0-a': {
      name: moduleName,
      version: '1.1.0-a',
      dist: {
        shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
        tarball: 'http://registry.npmjs.org/aproba/-/xyzzy-wibble-1.1.0-a.tgz'
      }
    },
    '1.2.0-a': {
      name: moduleName,
      version: '1.2.0-a',
      dist: {
        shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
        tarball: 'http://registry.npmjs.org/aproba/-/xyzzy-wibble-1.2.0-a.tgz'
      }
    },
    '1.3.0-a': {
      name: moduleName,
      version: '1.3.0-a',
      dist: {
        shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
        tarball: 'http://registry.npmjs.org/aproba/-/xyzzy-wibble-1.3.0-a.tgz'
      }
    }
  }
}

let server
test('setup', (t) => {
  mr({port: common.port}, (er, s) => {
    if (er) throw er
    t.ok(true, 'mock registry loaded')
    server = s
    npm.load({
      loglevel: 'silent',
      registry: common.registry,
      cache: path.join(testdir, 'cache')
    }, (err) => {
      if (err) { throw err }
      t.ok(true, 'npm loaded')
      t.end()
    })
  })
})

test('splat', (t) => {
  server.get('/xyzzy-wibble').reply(200, testModule)
  return npm.commands.cache.add('xyzzy-wibble', '*', testdir).then((pkg) => {
    throw new Error(`Was not supposed to succeed on ${pkg}`)
  }).catch((err) => {
    t.equal(err.code, 'E404', 'got a 404 on the tarball fetch')
    t.equal(
      err.uri,
      testModule.versions['1.3.0-a'].dist.tarball,
      'tried to get tarball for `latest` tag'
    )
    npm.config.set('tag', 'other')
    return npm.commands.cache.add('xyzzy-wibble', '*', testdir)
  }).then((pkg) => {
    throw new Error(`Was not supposed to succeed on ${pkg}`)
  }).catch((err) => {
    t.equal(err.code, 'E404', 'got a 404 on the tarball fetch')
    t.equal(
      err.uri,
      testModule.versions['1.2.0-a'].dist.tarball,
      'tried to get tarball for `other` tag'
    )
    server.close()
  })
})

test('cleanup', (t) => {
  process.chdir(osenv.tmpdir())
  rimraf(testdir, () => {
    t.ok(true, 'cleaned up test dir')
    t.done()
  })
})