1 var mkdirp = require('mkdirp')
2 var osenv = require('osenv')
3 var path = require('path')
4 var rimraf = require('rimraf')
5 var test = require('tap').test
6 var writeFileSync = require('fs').writeFileSync
8 var common = require('../common-tap.js')
10 var link = path.join(__dirname, 'link')
11 var linkInstall = path.join(__dirname, 'link-install')
12 var linkRoot = path.join(__dirname, 'link-root')
14 var config = 'prefix = ' + linkRoot
15 var configPath = path.join(link, '_npmrc')
19 'npm_config_userconfig': configPath
29 test: 'echo \"Error: no test specified\" && exit 1'
41 test: 'echo \"Error: no test specified\" && exit 1'
48 test('setup', function (t) {
50 common.npm(['ls', '-g', '--depth=0'], OPTS, function (err, c, out) {
52 t.equal(c, 0, 'set up ok')
53 t.notOk(out.match(/UNMET DEPENDENCY foo@/), "foo isn't in global")
58 test('creates global link', function (t) {
60 common.npm(['link'], OPTS, function (err, c, out) {
61 t.ifError(err, 'link has no error')
62 common.npm(['ls', '-g'], OPTS, function (err, c, out, stderr) {
65 t.equal(stderr, '', 'got expected stderr')
66 t.has(out, /foo@1.0.0/, 'creates global link ok')
72 test('link-install the package', function (t) {
73 process.chdir(linkInstall)
74 common.npm(['link', 'foo'], OPTS, function (err) {
75 t.ifError(err, 'link-install has no error')
76 common.npm(['ls'], OPTS, function (err, c, out) {
79 t.has(out, /foo@1.0.0/, 'link-install ok')
85 test('cleanup', function (t) {
86 process.chdir(osenv.tmpdir())
87 common.npm(['rm', 'foo'], OPTS, function (err, code) {
88 t.ifError(err, 'npm removed the linked package without error')
89 t.equal(code, 0, 'cleanup foo in local ok')
90 common.npm(['rm', '-g', 'foo'], OPTS, function (err, code) {
91 t.ifError(err, 'npm removed the global package without error')
92 t.equal(code, 0, 'cleanup foo in global ok')
100 function cleanup () {
101 rimraf.sync(linkRoot)
103 rimraf.sync(linkInstall)
108 mkdirp.sync(linkRoot)
111 path.join(link, 'package.json'),
112 JSON.stringify(readJSON, null, 2)
114 mkdirp.sync(linkInstall)
116 path.join(linkInstall, 'package.json'),
117 JSON.stringify(installJSON, null, 2)
119 writeFileSync(configPath, config)