]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/install-link-scripts.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / install-link-scripts.js
1 var fs = require('graceful-fs')
2 var path = require('path')
3
4 var mkdirp = require('mkdirp')
5 var osenv = require('osenv')
6 var rimraf = require('rimraf')
7 var test = require('tap').test
8
9 var common = require('../common-tap.js')
10
11 var pkg = path.join(__dirname, 'install-link-scripts')
12 var tmp = path.join(pkg, 'tmp')
13 var dep = path.join(pkg, 'dep')
14
15 var json = {
16   name: 'install-link-scripts',
17   version: '1.0.0',
18   description: 'a test',
19   repository: 'git://github.com/npm/npm.git',
20   license: 'ISC'
21 }
22
23 var dependency = {
24   name: 'dep',
25   version: '1.0.0',
26   scripts: {
27     install: './bin/foo'
28   }
29 }
30
31 var foo = function () {/*
32 #!/usr/bin/env node
33
34 console.log('hey sup')
35 */}.toString().split('\n').slice(1, -1).join('\n')
36
37 process.env.npm_config_prefix = tmp
38
39 test('plain install', function (t) {
40   setup()
41
42   common.npm(
43     [
44       'install', dep,
45       '--tmp', tmp
46     ],
47     { cwd: pkg },
48     function (err, code, stdout, stderr) {
49       t.ifErr(err, 'npm install ' + dep + ' finished without error')
50       t.equal(code, 0, 'exited ok')
51       t.notOk(stderr, 'no output stderr')
52       t.match(stdout, /hey sup/, 'postinstall script for dep ran')
53       t.end()
54     }
55   )
56 })
57
58 test('link', function (t) {
59   setup()
60
61   common.npm(
62     [
63       'link',
64       '--tmp', tmp
65     ],
66     { cwd: dep },
67     function (err, code, stdout, stderr) {
68       t.ifErr(err, 'npm link finished without error')
69       t.equal(code, 0, 'exited ok')
70       t.notOk(stderr, 'no output stderr')
71       t.match(stdout, /hey sup/, 'script ran')
72       t.end()
73     }
74   )
75 })
76
77 test('install --link', function (t) {
78   setup()
79
80   common.npm(
81     [
82       'link',
83       '--tmp', tmp
84     ],
85     { cwd: dep },
86     function (err, code, stdout, stderr) {
87       t.ifErr(err, 'npm link finished without error')
88
89       common.npm(
90         [
91           'install', '--link', dependency.name,
92           '--tmp', tmp
93         ],
94         { cwd: pkg },
95         function (err, code, stdout, stderr) {
96           t.ifErr(err, 'npm install --link finished without error')
97           t.equal(code, 0, 'exited ok')
98           t.notOk(stderr, 'no output stderr')
99           t.notMatch(stdout, /hey sup/, "script didn't run")
100           t.end()
101         }
102       )
103     }
104   )
105 })
106
107 test('cleanup', function (t) {
108   cleanup()
109   t.end()
110 })
111
112 function setup () {
113   cleanup()
114   mkdirp.sync(tmp)
115   fs.writeFileSync(
116     path.join(pkg, 'package.json'),
117     JSON.stringify(json, null, 2)
118   )
119
120   mkdirp.sync(path.join(dep, 'bin'))
121   fs.writeFileSync(
122     path.join(dep, 'package.json'),
123     JSON.stringify(dependency, null, 2)
124   )
125   fs.writeFileSync(path.join(dep, 'bin', 'foo'), foo)
126   fs.chmod(path.join(dep, 'bin', 'foo'), '0755')
127 }
128
129 function cleanup () {
130   process.chdir(osenv.tmpdir())
131   rimraf.sync(pkg)
132 }