]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/add-local.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / add-local.js
1 var path = require('path')
2 var test = require('tap').test
3 var mkdirp = require('mkdirp')
4 var osenv = require('osenv')
5 var rimraf = require('rimraf')
6 var requireInject = require('require-inject')
7
8 var pkg = path.join(__dirname, '/local-dir')
9 var cache = path.join(pkg, '/cache')
10 var tmp = path.join(pkg, '/tmp')
11 var prefix = path.join(pkg, '/prefix')
12
13 var Tacks = require('tacks')
14 var File = Tacks.File
15 var Dir = Tacks.Dir
16
17 test('addLocal directory race on Windows', function (t) {
18   setup()
19   var p = {
20     name: 'test',
21     version: '1.0.0',
22     type: 'directory',
23     spec: pkg
24   }
25   var fixture = new Tacks(
26     Dir({
27       'package.json': File(p)
28     })
29   )
30   var addLocal = requireInject('../../lib/cache/add-local', {
31     '../../lib/npm.js': {
32       cache: cache,
33       tmp: tmp,
34       prefix: prefix
35     },
36     '../../lib/cache/get-stat': function (cb) {
37       cb(null, {})
38     },
39     chownr: function (x, y, z, cb) {
40       cb(new Error('chownr should never have been called'))
41     },
42     '../../lib/cache/add-local-tarball.js': function (tgz, data, shasum, cb) {
43       cb(null)
44     },
45     '../../lib/utils/lifecycle.js': function (data, cycle, p, cb) {
46       cb(null)
47     },
48     '../../lib/utils/tar.js': {
49       pack: function (tgz, p, data, fancy, cb) {
50         cb(null)
51       }
52     },
53     'sha': {
54       get: function (tgz, cb) {
55         cb(null, 'deadbeef')
56       }
57     }
58   })
59
60   fixture.create(pkg)
61   addLocal(p, null, function (err) {
62     t.ifErr(err, 'addLocal completed without error')
63     t.done()
64   })
65 })
66
67 test('addLocal temporary cache file race', function (t) {
68   // See https://github.com/npm/npm/issues/12669
69   setup()
70   var p = {
71     name: 'test',
72     version: '1.0.0',
73     type: 'directory',
74     spec: pkg
75   }
76   var fixture = new Tacks(
77     Dir({
78       'package.json': File(p)
79     })
80   )
81   var addLocal = requireInject('../../lib/cache/add-local', {
82     // basic setup/mock stuff
83     '../../lib/npm.js': {
84       cache: cache,
85       tmp: tmp,
86       prefix: prefix
87     },
88     '../../lib/cache/add-local-tarball.js': function (tgz, data, shasum, cb) {
89       cb(null)
90     },
91     '../../lib/utils/lifecycle.js': function (data, cycle, p, cb) {
92       cb(null)
93     },
94     '../../lib/utils/tar.js': {
95       pack: function (tgz, p, data, fancy, cb) {
96         cb(null)
97       }
98     },
99     'sha': {
100       get: function (tgz, cb) {
101         cb(null, 'deadbeef')
102       }
103     },
104
105     // Test-specific mocked values to simulate race.
106     '../../lib/cache/get-stat': function (cb) {
107       cb(null, {uid: 1, gid: 2})
108     },
109     chownr: function (x, y, z, cb) {
110       // Simulate a race condition between `tar.pack` and `chownr`
111       // where the latter will return `ENOENT` when an async process
112       // removes a file that its internal `fs.readdir` listed.
113       cb({code: 'ENOENT'})
114     }
115   })
116
117   fixture.create(pkg)
118   addLocal(p, null, function (err) {
119     t.ifErr(err, 'addLocal completed without error')
120     t.done()
121   })
122 })
123
124 test('cleanup', function (t) {
125   cleanup()
126   t.done()
127 })
128
129 function setup () {
130   mkdirp.sync(cache)
131   mkdirp.sync(tmp)
132 }
133
134 function cleanup () {
135   process.chdir(osenv.tmpdir())
136   rimraf.sync(pkg)
137 }