npm: Upgrade to 1.3.19
[platform/upstream/nodejs.git] / deps / npm / test / tap / version-no-tags.js
1 var common = require('../common-tap.js')
2 var test = require('tap').test
3 var npm = require('../../')
4 var npmc = require.resolve('../../')
5 var osenv = require('osenv')
6 var path = require('path')
7 var fs = require('fs')
8 var rimraf = require('rimraf')
9 var mkdirp = require('mkdirp')
10 var which = require('which')
11 var util = require('util')
12 var spawn = require('child_process').spawn
13 var args = [ npmc
14            , 'version'
15            , 'patch'
16            , '--no-git-tag-version'
17            ]
18 var pkg = __dirname + '/version-no-tags'
19
20 test("npm version <semver> without git tag", function (t) {
21   setup()
22   npm.load({ cache: pkg + '/cache', registry: common.registry}, function () {
23     which('git', function(err, git) {
24       function tagExists(tag, _cb) {
25         var child = spawn(git, ['tag', '-l', tag])
26         var out = ''
27         child.stdout.on('data', function(d) {
28           out += data.toString()
29         })
30         child.on('exit', function() {
31           return _cb(null, Boolean(~out.indexOf(tag)))
32         })
33       }
34
35       var child = spawn(git, ['init'])
36       child.stdout.pipe(process.stdout)
37       child.on('exit', function() {
38         npm.config.set('git-tag-version', false)
39         npm.commands.version(['patch'], function(err) {
40           if (err) return t.fail('Error perform version patch')
41           var testPkg = require(pkg+'/package')
42           if (testPkg.version !== '0.0.1') t.fail(testPkg.version+' !== \'0.0.1\'')
43           t.ok('0.0.1' === testPkg.version)
44           tagExists('v0.0.1', function(err, exists) {
45             t.equal(exists, false, 'git tag DOES exist')
46             t.pass('git tag does not exist')
47             t.end()
48           })
49         })
50       })
51     })
52   })
53 })
54
55 test('cleanup', function(t) {
56   // windows fix for locked files
57   process.chdir(osenv.tmpdir())
58
59   rimraf.sync(pkg)
60   t.end()
61 })
62
63 function setup() {
64   mkdirp.sync(pkg)
65   mkdirp.sync(pkg + '/cache')
66   fs.writeFileSync(pkg + '/package.json', JSON.stringify({
67     author: "Evan Lucas",
68     name: "version-no-tags-test",
69     version: "0.0.0",
70     description: "Test for git-tag-version flag"
71   }), 'utf8')
72   process.chdir(pkg)
73 }