1const fs = require('graceful-fs') 2const path = require('path') 3const t = require('tap') 4const common = require('../common-tap.js') 5const npm = require('../../') 6const pkg = common.pkg 7const cache = common.cache 8const npmrc = path.resolve(pkg, './.npmrc') 9const configContents = 'sign-git-tag=false\n' 10 11t.test('setup', t => { 12 process.chdir(pkg) 13 fs.writeFileSync(npmrc, configContents, 'ascii') 14 fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({ 15 author: 'Lucas Theisen', 16 name: 'version-allow-same-version', 17 version: '0.0.1', 18 description: 'Test for npm version without --allow-same-version' 19 }), 'utf8') 20 npm.load({cache: cache, 'allow-same-version': false, registry: common.registry}, t.end) 21}) 22 23t.test('without --allow-same-version', t => { 24 npm.config.set('allow-same-version', false) 25 26 const version = require('../../lib/version') 27 28 const commit1 = version.buildCommitArgs() 29 const commit2 = version.buildCommitArgs([ 'commit' ]) 30 const commit3 = version.buildCommitArgs([ 'commit', '-m', 'some commit message' ]) 31 32 t.same(commit1, [ 'commit' ]) 33 t.same(commit2, [ 'commit' ]) 34 t.same(commit3, [ 'commit', '-m', 'some commit message' ]) 35 36 const tag = version.buildTagFlags() 37 38 t.same(tag, '-m') 39 40 npm.commands.version(['0.0.1'], function (err) { 41 t.isa(err, Error, 'got an error') 42 t.like(err.message, /Version not changed/) 43 t.end() 44 }) 45}) 46 47t.test('with --allow-same-version', t => { 48 npm.config.set('allow-same-version', true) 49 50 const version = require('../../lib/version') 51 52 const commit1 = version.buildCommitArgs() 53 const commit2 = version.buildCommitArgs([ 'commit' ]) 54 const commit3 = version.buildCommitArgs([ 'commit', '-m', 'some commit message' ]) 55 56 t.same(commit1, [ 'commit', '--allow-empty' ]) 57 t.same(commit2, [ 'commit', '--allow-empty' ]) 58 t.same(commit3, [ 'commit', '--allow-empty', '-m', 'some commit message' ]) 59 60 const tag = version.buildTagFlags() 61 62 t.same(tag, '-fm') 63 64 npm.commands.version(['0.0.1'], function (err) { 65 if (err) { 66 throw err 67 } 68 t.end() 69 }) 70}) 71