1var fs = require('fs') 2var path = require('path') 3 4var test = require('tap').test 5 6var npm = require('../../') 7var common = require('../common-tap.js') 8 9var pkg = common.pkg 10 11var EXEC_OPTS = { cwd: pkg } 12 13test('npm version --preid=rc uses prerelease id', function (t) { 14 setup() 15 16 npm.load({ cache: pkg + '/cache', registry: common.registry }, function () { 17 common.npm(['version', 'prerelease', '--preid=rc'], EXEC_OPTS, function (err) { 18 if (err) return t.fail('Error perform version prerelease') 19 var newVersion = require(path.resolve(pkg, 'package.json')).version 20 t.equal(newVersion, '0.0.1-rc.0', 'got expected version') 21 t.end() 22 }) 23 }) 24}) 25 26function setup () { 27 var contents = { 28 author: 'Daniel Wilches', 29 name: 'version-prerelease-id', 30 version: '0.0.0', 31 description: 'Test for version of prereleases with preids' 32 } 33 34 fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify(contents), 'utf8') 35 fs.writeFileSync(path.resolve(pkg, 'npm-shrinkwrap.json'), JSON.stringify(contents), 'utf8') 36 process.chdir(pkg) 37} 38