]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/cache-shasum-fork.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / cache-shasum-fork.js
1 var fs = require('graceful-fs')
2 var path = require('path')
3
4 var mkdirp = require('mkdirp')
5 var mr = require('npm-registry-mock')
6 var osenv = require('osenv')
7 var rimraf = require('rimraf')
8 var test = require('tap').test
9
10 var common = require('../common-tap.js')
11
12 // Install from a tarball that thinks it is underscore@1.5.1
13 // (but is actually a fork)
14 var forkPath = path.resolve(
15   __dirname, '..', 'fixtures', 'forked-underscore-1.5.1.tgz'
16 )
17 var pkg = path.resolve(__dirname, 'cache-shasum-fork')
18 var cache = path.join(pkg, 'cache')
19 var server
20
21 test('setup', function (t) {
22   setup()
23   t.comment('test for https://github.com/npm/npm/issues/3265')
24   mr({ port: common.port }, function (er, s) {
25     server = s
26     t.end()
27   })
28 })
29
30 test('npm cache - install from fork', function (t) {
31   setup()
32   common.npm(
33     [
34       '--loglevel', 'silent',
35       '--registry', common.registry,
36       'install', forkPath
37     ],
38     {
39       cwd: pkg,
40       env: { npm_config_cache: cache }
41     },
42     function (err, code, stdout, stderr) {
43       t.ifErr(err, 'install finished without error')
44       t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
45       t.equal(code, 0, 'install finished successfully')
46
47       t.equal(stdout, 'underscore@1.5.1 node_modules/underscore\n')
48       var index = fs.readFileSync(
49         path.join(pkg, 'node_modules', 'underscore', 'index.js'),
50         'utf8'
51       )
52       t.equal(index, 'console.log("This is the fork");\n\n')
53       t.end()
54     }
55   )
56 })
57
58 // Now install the real 1.5.1.
59 test('npm cache - install from origin', function (t) {
60   setup()
61   common.npm(
62     [
63       '--loglevel', 'silent',
64       '--registry', common.registry,
65       'install', 'underscore'
66     ],
67     {
68       cwd: pkg,
69       env: { npm_config_cache: cache }
70     },
71     function (err, code, stdout, stderr) {
72       t.ifErr(err, 'install finished without error')
73       t.equal(code, 0, 'install finished successfully')
74       t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
75       t.equal(stdout, 'underscore@1.5.1 node_modules/underscore\n')
76       var index = fs.readFileSync(
77         path.join(pkg, 'node_modules', 'underscore', 'index.js'),
78         'utf8'
79       )
80       t.equal(index, 'module.exports = require(\'./underscore\');\n')
81       t.end()
82     }
83   )
84 })
85
86 test('cleanup', function (t) {
87   server.close()
88   cleanup()
89   t.end()
90 })
91
92 function cleanup () {
93   process.chdir(osenv.tmpdir())
94   rimraf.sync(pkg)
95 }
96
97 function setup () {
98   mkdirp.sync(cache)
99   mkdirp.sync(path.join(pkg, 'node_modules'))
100   process.chdir(pkg)
101 }