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

version-no-tags.js « tap « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e731c31544337e43bcf5a3cc6f59523585209faa (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
var common = require('../common-tap.js')
var test = require('tap').test
var npm = require('../../')
var npmc = require.resolve('../../')
var osenv = require('osenv')
var path = require('path')
var fs = require('fs')
var rimraf = require('rimraf')
var mkdirp = require('mkdirp')
var which = require('which')
var util = require('util')
var spawn = require('child_process').spawn
var args = [ npmc
           , 'version'
           , 'patch'
           , '--no-git-tag-version'
           ]
var pkg = __dirname + '/version-no-tags'

test("npm version <semver> without git tag", function (t) {
  setup()
  npm.load({ cache: pkg + '/cache', registry: common.registry}, function () {
    which('git', function(err, git) {
      function tagExists(tag, _cb) {
        var child = spawn(git, ['tag', '-l', tag])
        var out = ''
        child.stdout.on('data', function(d) {
          out += data.toString()
        })
        child.on('exit', function() {
          return _cb(null, Boolean(~out.indexOf(tag)))
        })
      }

      var child = spawn(git, ['init'])
      child.stdout.pipe(process.stdout)
      child.on('exit', function() {
        npm.config.set('git-tag-version', false)
        npm.commands.version(['patch'], function(err) {
          if (err) return t.fail('Error perform version patch')
          var testPkg = require(pkg+'/package')
          if (testPkg.version !== '0.0.1') t.fail(testPkg.version+' !== \'0.0.1\'')
          t.ok('0.0.1' === testPkg.version)
          tagExists('v0.0.1', function(err, exists) {
            t.equal(exists, false, 'git tag DOES exist')
            t.pass('git tag does not exist')
            t.end()
          })
        })
      })
    })
  })
})

test('cleanup', function(t) {
  // windows fix for locked files
  process.chdir(osenv.tmpdir())

  rimraf.sync(pkg)
  t.end()
})

function setup() {
  mkdirp.sync(pkg)
  mkdirp.sync(pkg + '/cache')
  fs.writeFileSync(pkg + '/package.json', JSON.stringify({
    author: "Evan Lucas",
    name: "version-no-tags-test",
    version: "0.0.0",
    description: "Test for git-tag-version flag"
  }), 'utf8')
  process.chdir(pkg)
}