• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2
3const common = require('../common-tap.js')
4const mr = require('npm-registry-mock')
5const npm = require('../../lib/npm')
6const test = require('tap').test
7
8const testdir = common.pkg
9
10const moduleName = 'xyzzy-wibble'
11const testModule = {
12  name: moduleName,
13  'dist-tags': {
14    latest: '1.3.0-a',
15    other: '1.2.0-a'
16  },
17  versions: {
18    '1.0.0-a': {
19      name: moduleName,
20      version: '1.0.0-a',
21      dist: {
22        shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
23        tarball: 'https://registry.npmjs.org/aproba/-/xyzzy-wibble-1.0.0-a.tgz'
24      }
25    },
26    '1.1.0-a': {
27      name: moduleName,
28      version: '1.1.0-a',
29      dist: {
30        shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
31        tarball: 'https://registry.npmjs.org/aproba/-/xyzzy-wibble-1.1.0-a.tgz'
32      }
33    },
34    '1.2.0-a': {
35      name: moduleName,
36      version: '1.2.0-a',
37      dist: {
38        shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
39        tarball: 'https://registry.npmjs.org/aproba/-/xyzzy-wibble-1.2.0-a.tgz'
40      }
41    },
42    '1.3.0-a': {
43      name: moduleName,
44      version: '1.3.0-a',
45      dist: {
46        shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
47        tarball: 'https://registry.npmjs.org/aproba/-/xyzzy-wibble-1.3.0-a.tgz'
48      }
49    }
50  }
51}
52
53let server
54test('setup', (t) => {
55  mr({port: common.port}, (er, s) => {
56    if (er) throw er
57    t.ok(true, 'mock registry loaded')
58    server = s
59    npm.load({
60      loglevel: 'silent',
61      registry: common.registry,
62      cache: common.cache
63    }, (err) => {
64      if (err) { throw err }
65      t.ok(true, 'npm loaded')
66      t.end()
67    })
68  })
69})
70
71test('splat', (t) => {
72  server.get('/xyzzy-wibble').reply(200, testModule)
73  return npm.commands.cache.add('xyzzy-wibble', '*', testdir).then((pkg) => {
74    throw new Error(`Was not supposed to succeed on ${pkg}`)
75  }).catch((err) => {
76    t.equal(err.code, 'E404', 'got a 404 on the tarball fetch')
77    t.equal(
78      err.uri,
79      testModule.versions['1.3.0-a'].dist.tarball,
80      'tried to get tarball for `latest` tag'
81    )
82    npm.config.set('tag', 'other')
83    return npm.commands.cache.add('xyzzy-wibble', '*', testdir)
84  }).then((pkg) => {
85    throw new Error(`Was not supposed to succeed on ${pkg}`)
86  }).catch((err) => {
87    t.equal(err.code, 'E404', 'got a 404 on the tarball fetch')
88    t.equal(
89      err.uri,
90      testModule.versions['1.2.0-a'].dist.tarball,
91      'tried to get tarball for `other` tag'
92    )
93    server.close()
94  })
95})
96