]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/url-dependencies.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / url-dependencies.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')
11 var server
12
13 var pkg = path.resolve(__dirname, 'url-dependencies')
14
15 var json = {
16   author: 'Steve Mason',
17   name: 'url-dependencies',
18   version: '0.0.0',
19   dependencies: {
20     underscore: common.registry + '/underscore/-/underscore-1.3.1.tgz'
21   }
22 }
23
24 var mockRoutes = {
25   'get': {
26     '/underscore/-/underscore-1.3.1.tgz': [200]
27   }
28 }
29
30 test('setup', function (t) {
31   mr({ port: common.port, mocks: mockRoutes }, function (er, s) {
32     server = s
33     t.end()
34   })
35 })
36
37 test('url-dependencies: download first time', function (t) {
38   setup()
39
40   performInstall(t, function (output) {
41     if (!tarballWasFetched(output)) {
42       t.fail('Tarball was not fetched')
43     } else {
44       t.pass('Tarball was fetched')
45     }
46     t.end()
47   })
48 })
49
50 test('url-dependencies: do not download subsequent times', function (t) {
51   setup()
52
53   performInstall(t, function () {
54     performInstall(t, function (output) {
55       if (tarballWasFetched(output)) {
56         t.fail('Tarball was fetched second time around')
57       } else {
58         t.pass('Tarball was not fetched')
59       }
60       t.end()
61     })
62   })
63 })
64
65 test('cleanup', function (t) {
66   server.close()
67   cleanup()
68   t.end()
69 })
70
71 function cleanup () {
72   // windows fix for locked files
73   process.chdir(osenv.tmpdir())
74   rimraf.sync(path.resolve(pkg))
75 }
76
77 function setup () {
78   cleanup()
79   mkdirp.sync(pkg)
80   fs.writeFileSync(
81     path.join(pkg, 'package.json'),
82     JSON.stringify(json, null, 2)
83   )
84 }
85
86 function tarballWasFetched (output) {
87   return output.indexOf(
88     'http fetch GET ' +
89       common.registry +
90       '/underscore/-/underscore-1.3.1.tgz'
91   ) > -1
92 }
93
94 function performInstall (t, cb) {
95   var opts = {
96     cwd: pkg,
97     env: {
98       npm_config_registry: common.registry,
99       npm_config_cache_lock_stale: 1000,
100       npm_config_cache_lock_wait: 1000,
101       npm_config_loglevel: 'http',
102       HOME: process.env.HOME,
103       Path: process.env.PATH,
104       PATH: process.env.PATH
105     }
106   }
107   common.npm(['install'], opts, function (err, code, stdout, stderr) {
108     t.ifError(err, 'install success')
109     t.notOk(code, 'npm install exited with code 0')
110
111     cb(stderr)
112   })
113 }