1'use strict' 2var path = require('path') 3var fs = require('graceful-fs') 4var mkdirp = require('mkdirp') 5var rimraf = require('rimraf') 6var test = require('tap').test 7var requireInject = require('require-inject') 8const common = require('../common-tap.js') 9 10var base = common.pkg 11 12var baseJSON = { 13 name: 'base', 14 version: '1.0.0', 15 repository: { 16 type: 'git', 17 url: 'http://example.com' 18 }, 19 scripts: { 20 prepublish: 'false' 21 } 22} 23 24var lastOpened 25var npm = requireInject.installGlobally('../../lib/npm.js', { 26 '../../lib/utils/lifecycle.js': function (pkg, stage, wd, moreOpts, cb) { 27 if (typeof moreOpts === 'function') { 28 cb = moreOpts 29 } 30 31 cb(new Error("Shouldn't be calling lifecycle scripts")) 32 }, 33 opener: function (url, options, cb) { 34 lastOpened = {url: url, options: options} 35 cb() 36 } 37}) 38 39test('setup', function (t) { 40 cleanup() 41 setup() 42 t.end() 43}) 44 45test('repo', function (t) { 46 process.chdir(base) 47 npm.load({browser: 'echo'}, function () { 48 npm.commands.repo([], function (err) { 49 t.ifError(err, 'no errors') 50 t.match(lastOpened.url, baseJSON.repository.url, 'opened the right url') 51 t.is(lastOpened.options.command, 'echo', 'opened with a specified browser') 52 t.end() 53 }) 54 }) 55}) 56 57test('cleanup', function (t) { 58 cleanup() 59 t.end() 60}) 61 62function saveJson (pkgPath, json) { 63 mkdirp.sync(pkgPath) 64 fs.writeFileSync(path.join(pkgPath, 'package.json'), JSON.stringify(json, null, 2)) 65} 66 67function setup () { 68 saveJson(base, baseJSON) 69} 70 71function cleanup () { 72 rimraf.sync(base) 73} 74