1const fs = require('graceful-fs') 2const path = require('path') 3const common = require('../common-tap.js') 4const pkg = common.pkg 5 6var test = require('tap').test 7var npm = require('../../') 8 9delete process.env['npm_config_commit_hooks'] 10 11test('npm version <semver> with commit-hooks disabled in .npmrc', function (t) { 12 var npmrc = path.resolve(pkg, '.npmrc') 13 fs.writeFileSync(npmrc, 'commit-hooks=false\n', 'ascii') 14 process.chdir(pkg) 15 16 npm.load({ prefix: pkg, userconfig: npmrc }, function (err, conf) { 17 if (err) { 18 t.fail('error loading npm') 19 } 20 t.same(npm.config.get('commit-hooks'), false) 21 t.end() 22 }) 23}) 24 25test('npm version <semver> with commit-hooks disabled', function (t) { 26 npm.load({}, function () { 27 npm.config.set('commit-hooks', false) 28 29 var version = require('../../lib/version') 30 var args1 = version.buildCommitArgs() 31 var args2 = version.buildCommitArgs([ 'commit' ]) 32 var args3 = version.buildCommitArgs([ 'commit', '-m', 'some commit message' ]) 33 34 t.same(args1, [ 'commit', '-n' ]) 35 t.same(args2, [ 'commit', '-n' ]) 36 t.same(args3, [ 'commit', '-n', '-m', 'some commit message' ]) 37 t.end() 38 }) 39}) 40 41test('npm version <semver> with commit-hooks enabled (default)', function (t) { 42 npm.load({}, function () { 43 npm.config.set('commit-hooks', true) 44 45 var version = require('../../lib/version') 46 var args1 = version.buildCommitArgs() 47 var args2 = version.buildCommitArgs([ 'commit' ]) 48 var args3 = version.buildCommitArgs([ 'commit', '-m', 'some commit message' ]) 49 50 t.same(args1, [ 'commit' ]) 51 t.same(args2, [ 'commit' ]) 52 t.same(args3, [ 'commit', '-m', 'some commit message' ]) 53 t.end() 54 }) 55}) 56