mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
2.7 KiB
118 lines
2.7 KiB
9 years ago
|
var resolve = require('path').resolve
|
||
|
var fs = require('graceful-fs')
|
||
|
var test = require('tap').test
|
||
|
var mkdirp = require('mkdirp')
|
||
|
var rimraf = require('rimraf')
|
||
10 years ago
|
|
||
9 years ago
|
var common = require('../common-tap.js')
|
||
10 years ago
|
|
||
9 years ago
|
var pkg = resolve(__dirname, 'gently-rm-linked')
|
||
|
var dep = resolve(__dirname, 'test-linked')
|
||
|
var glb = resolve(__dirname, 'test-global')
|
||
|
var lnk = resolve(__dirname, 'test-global-link')
|
||
10 years ago
|
|
||
9 years ago
|
var EXEC_OPTS = { cwd: pkg }
|
||
10 years ago
|
|
||
|
var index = "module.exports = function () { console.log('whoop whoop') }"
|
||
|
|
||
|
var fixture = {
|
||
9 years ago
|
name: '@test/linked',
|
||
|
version: '1.0.0',
|
||
10 years ago
|
bin: {
|
||
9 years ago
|
linked: './index.js'
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
test('setup', function (t) {
|
||
10 years ago
|
cleanup()
|
||
|
setup()
|
||
|
|
||
|
t.end()
|
||
|
})
|
||
|
|
||
9 years ago
|
test('install and link', function (t) {
|
||
10 years ago
|
common.npm(
|
||
|
[
|
||
9 years ago
|
'--global',
|
||
|
'--prefix', lnk,
|
||
|
'--loglevel', 'silent',
|
||
|
'install', '../test-linked'
|
||
10 years ago
|
],
|
||
|
EXEC_OPTS,
|
||
|
function (er, code, stdout, stderr) {
|
||
|
t.ifError(er, "test-linked install didn't explode")
|
||
9 years ago
|
t.notOk(code, 'test-linked install also failed')
|
||
|
t.notOk(stderr, 'no log output')
|
||
10 years ago
|
|
||
|
verify(t, stdout)
|
||
|
|
||
|
// again, to make sure unlinking works properlyt
|
||
|
common.npm(
|
||
|
[
|
||
9 years ago
|
'--global',
|
||
|
'--prefix', lnk,
|
||
|
'--loglevel', 'silent',
|
||
|
'install', '../test-linked'
|
||
10 years ago
|
],
|
||
|
EXEC_OPTS,
|
||
|
function (er, code, stdout, stderr) {
|
||
|
t.ifError(er, "test-linked install didn't explode")
|
||
9 years ago
|
t.notOk(code, 'test-linked install also failed')
|
||
|
t.notOk(stderr, 'no log output')
|
||
10 years ago
|
|
||
|
verify(t, stdout)
|
||
|
|
||
|
fs.readdir(pkg, function (er, files) {
|
||
9 years ago
|
t.ifError(er, 'package directory is still there')
|
||
|
t.deepEqual(files, ['node_modules'], 'only stub modules dir remains')
|
||
10 years ago
|
|
||
|
t.end()
|
||
|
})
|
||
|
}
|
||
|
)
|
||
|
}
|
||
|
)
|
||
|
})
|
||
|
|
||
9 years ago
|
test('cleanup', function (t) {
|
||
10 years ago
|
cleanup()
|
||
|
|
||
|
t.end()
|
||
|
})
|
||
|
|
||
9 years ago
|
function removeBlank (line) {
|
||
|
return line !== ''
|
||
|
}
|
||
|
|
||
10 years ago
|
function verify (t, stdout) {
|
||
9 years ago
|
var binPath = resolve(lnk, 'bin', 'linked')
|
||
|
var pkgPath = resolve(lnk, 'lib', 'node_modules', '@test', 'linked')
|
||
|
var trgPath = resolve(pkgPath, 'index.js')
|
||
|
t.deepEqual(
|
||
|
stdout.split('\n').filter(removeBlank),
|
||
|
[ binPath + ' -> ' + trgPath,
|
||
|
resolve(lnk, 'lib'),
|
||
|
'└── @test/linked@1.0.0 '
|
||
|
],
|
||
|
'got expected install output'
|
||
10 years ago
|
)
|
||
|
}
|
||
|
|
||
|
function cleanup () {
|
||
|
rimraf.sync(pkg)
|
||
|
rimraf.sync(dep)
|
||
|
rimraf.sync(lnk)
|
||
|
rimraf.sync(glb)
|
||
|
}
|
||
|
|
||
|
function setup () {
|
||
|
mkdirp.sync(pkg)
|
||
|
mkdirp.sync(glb)
|
||
|
fs.symlinkSync(glb, lnk)
|
||
|
// so it doesn't try to install into npm's own node_modules
|
||
9 years ago
|
mkdirp.sync(resolve(pkg, 'node_modules'))
|
||
10 years ago
|
mkdirp.sync(dep)
|
||
9 years ago
|
fs.writeFileSync(resolve(dep, 'package.json'), JSON.stringify(fixture))
|
||
|
fs.writeFileSync(resolve(dep, 'index.js'), index)
|
||
10 years ago
|
}
|