summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/publish-invalid-semver-tag.js
blob: 9c2f40813b06e4bb0ef4a7d8e4316125a10d3f8e (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
var common = require('../common-tap.js')
var test = require('tap').test
var npm = require('../../lib/npm.js')
var mkdirp = require('mkdirp')
var path = require('path')
var fs = require('fs')
var mr = require('npm-registry-mock')

var PKG_DIR = common.pkg
let cacheIteration = 0
let CACHE_DIR

var DEFAULT_PKG = {
  'name': 'examples',
  'version': '1.2.3'
}

const isRoot = process.getuid && process.getuid() === 0
const sudoUID = isRoot ? +process.env.SUDO_UID : null
const sudoGID = isRoot ? +process.env.SUDO_GID : null
const { chownSync } = require('fs')
function resetPackage (options) {
  CACHE_DIR = path.resolve(common.cache, '' + cacheIteration++)
  mkdirp.sync(CACHE_DIR)
  npm.config.set('cache', CACHE_DIR)

  if (isRoot && sudoUID && sudoGID) {
    chownSync(CACHE_DIR, sudoUID, sudoGID)
  }

  fs.writeFileSync(path.resolve(PKG_DIR, 'package.json'), JSON.stringify(DEFAULT_PKG))
}

test('setup', function (t) {
  mkdirp.sync(PKG_DIR)
  process.chdir(PKG_DIR)

  mr({ port: common.port }, function (er, server) {
    if (er) {
      throw er
    }
    t.parent.teardown(() => server.close())
    npm.load({
      cache: common.cache,
      registry: common.registry,
      cwd: PKG_DIR
    }, function (err) {
      if (err) {
        throw err
      }
      t.end()
    })
  })
})

test('attempt publish with semver-like version', function (t) {
  resetPackage({})

  npm.config.set('tag', 'v1.x')
  npm.commands.publish([], function (err) {
    t.notEqual(err, null)
    t.same(err.message, 'Tag name must not be a valid SemVer range: v1.x')
    t.end()
  })
})

test('attempt publish with semver-like version', function (t) {
  resetPackage({})

  npm.config.set('tag', '1.2.3')
  npm.commands.publish([], function (err) {
    t.notEqual(err, null)
    t.same(err.message, 'Tag name must not be a valid SemVer range: 1.2.3')
    t.end()
  })
})