node/deps/npm/test/tap/verify-no-lifecycle-on-repo.js
Myles Borins ace4fe566f
deps: update npm to 5.5.1
Closes: https://github.com/nodejs/node/pull/16280

PR-URL: https://github.com/nodejs/node/pull/16509
Fixes: https://github.com/nodejs/node/issues/14161
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2017-10-29 21:32:15 -04:00

74 lines
1.6 KiB
JavaScript

'use strict'
var path = require('path')
var fs = require('graceful-fs')
var mkdirp = require('mkdirp')
var rimraf = require('rimraf')
var test = require('tap').test
var requireInject = require('require-inject')
require('../common-tap.js')
var base = path.join(__dirname, path.basename(__filename, '.js'))
var baseJSON = {
name: 'base',
version: '1.0.0',
repository: {
type: 'git',
url: 'http://example.com'
},
scripts: {
prepublish: 'false'
}
}
var lastOpened
var npm = requireInject.installGlobally('../../lib/npm.js', {
'../../lib/utils/lifecycle.js': function (pkg, stage, wd, moreOpts, cb) {
if (typeof moreOpts === 'function') {
cb = moreOpts
}
cb(new Error("Shouldn't be calling lifecycle scripts"))
},
opener: function (url, options, cb) {
lastOpened = {url: url, options: options}
cb()
}
})
test('setup', function (t) {
cleanup()
setup()
t.end()
})
test('repo', function (t) {
process.chdir(base)
npm.load({browser: 'echo'}, function () {
npm.commands.repo([], function (err) {
t.ifError(err, 'no errors')
t.match(lastOpened.url, baseJSON.repository.url, 'opened the right url')
t.is(lastOpened.options.command, 'echo', 'opened with a specified browser')
t.end()
})
})
})
test('cleanup', function (t) {
cleanup()
t.end()
})
function saveJson (pkgPath, json) {
mkdirp.sync(pkgPath)
fs.writeFileSync(path.join(pkgPath, 'package.json'), JSON.stringify(json, null, 2))
}
function setup () {
saveJson(base, baseJSON)
}
function cleanup () {
rimraf.sync(base)
}