summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/version-commit-hooks.js
blob: 4791fc3f3c4d24975e95dead95770fb59f1d8815 (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
var fs = require('graceful-fs')
var path = require('path')
var osenv = require('osenv')
var mkdirp = require('mkdirp')
var rimraf = require('rimraf')
var pkg = path.resolve(__dirname, 'version-commit-hooks')

var test = require('tap').test
var npm = require('../../')

delete process.env['npm_config_commit_hooks']

test('npm version <semver> with commit-hooks disabled in .npmrc', function (t) {
  mkdirp.sync(pkg)
  var npmrc = path.resolve(pkg, '.npmrc')
  fs.writeFileSync(npmrc, 'commit-hooks=false\n', 'ascii')
  process.chdir(pkg)

  npm.load({ prefix: pkg, userconfig: npmrc }, function (err, conf) {
    if (err) {
      t.fail('error loading npm')
    }
    t.same(npm.config.get('commit-hooks'), false)
    t.end()
  })
})

test('npm version <semver> with commit-hooks disabled', function (t) {
  npm.load({}, function () {
    npm.config.set('commit-hooks', false)

    var version = require('../../lib/version')
    var args1 = version.buildCommitArgs()
    var args2 = version.buildCommitArgs([ 'commit' ])
    var args3 = version.buildCommitArgs([ 'commit', '-m', 'some commit message' ])

    t.same(args1, [ 'commit', '-n' ])
    t.same(args2, [ 'commit', '-n' ])
    t.same(args3, [ 'commit', '-m', 'some commit message', '-n' ])
    t.end()
  })
})

test('npm version <semver> with commit-hooks enabled (default)', function (t) {
  npm.load({}, function () {
    npm.config.set('commit-hooks', true)

    var version = require('../../lib/version')
    var args1 = version.buildCommitArgs()
    var args2 = version.buildCommitArgs([ 'commit' ])
    var args3 = version.buildCommitArgs([ 'commit', '-m', 'some commit message' ])

    t.same(args1, [ 'commit' ])
    t.same(args2, [ 'commit' ])
    t.same(args3, [ 'commit', '-m', 'some commit message' ])
    t.end()
  })
})

test('cleanup', function (t) {
  process.chdir(osenv.tmpdir())
  rimraf.sync(pkg)
  t.end()
})