]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/link.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / link.js
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
7
8 var common = require('../common-tap.js')
9
10 var link = path.join(__dirname, 'link')
11 var linkInstall = path.join(__dirname, 'link-install')
12 var linkRoot = path.join(__dirname, 'link-root')
13
14 var config = 'prefix = ' + linkRoot
15 var configPath = path.join(link, '_npmrc')
16
17 var OPTS = {
18   env: {
19     'npm_config_userconfig': configPath
20   }
21 }
22
23 var readJSON = {
24   name: 'foo',
25   version: '1.0.0',
26   description: '',
27   main: 'index.js',
28   scripts: {
29     test: 'echo \"Error: no test specified\" && exit 1'
30   },
31   author: '',
32   license: 'ISC'
33 }
34
35 var installJSON = {
36   name: 'bar',
37   version: '1.0.0',
38   description: '',
39   main: 'index.js',
40   scripts: {
41     test: 'echo \"Error: no test specified\" && exit 1'
42   },
43   author: '',
44   license: 'ISC'
45 }
46
47
48 test('setup', function (t) {
49   setup()
50   common.npm(['ls', '-g', '--depth=0'], OPTS, function (err, c, out) {
51     t.ifError(err)
52     t.equal(c, 0, 'set up ok')
53     t.notOk(out.match(/UNMET DEPENDENCY foo@/), "foo isn't in global")
54     t.end()
55   })
56 })
57
58 test('creates global link', function (t) {
59   process.chdir(link)
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) {
63       t.ifError(err)
64       t.equal(c, 0)
65       t.equal(stderr, '', 'got expected stderr')
66       t.has(out, /foo@1.0.0/, 'creates global link ok')
67       t.end()
68     })
69   })
70 })
71
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) {
77       t.ifError(err)
78       t.equal(c, 1)
79       t.has(out, /foo@1.0.0/, 'link-install ok')
80       t.end()
81     })
82   })
83 })
84
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')
93
94       cleanup()
95       t.end()
96     })
97   })
98 })
99
100 function cleanup () {
101   rimraf.sync(linkRoot)
102   rimraf.sync(link)
103   rimraf.sync(linkInstall)
104 }
105
106 function setup () {
107   cleanup()
108   mkdirp.sync(linkRoot)
109   mkdirp.sync(link)
110   writeFileSync(
111     path.join(link, 'package.json'),
112     JSON.stringify(readJSON, null, 2)
113   )
114   mkdirp.sync(linkInstall)
115   writeFileSync(
116     path.join(linkInstall, 'package.json'),
117     JSON.stringify(installJSON, null, 2)
118   )
119   writeFileSync(configPath, config)
120 }