X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.maps.server%2Fnode%2Fnode-v4.8.0-win-x64%2Fnode_modules%2Fnpm%2Ftest%2Ftap%2Fadd-local.js;fp=org.simantics.maps.server%2Fnode%2Fnode-v4.8.0-win-x64%2Fnode_modules%2Fnpm%2Ftest%2Ftap%2Fadd-local.js;h=0a5b7b5dc376364caa6a4d6efba4064e97daa917;hb=2529be6d456deeb07c128603ce4971f1dc29b695;hp=0000000000000000000000000000000000000000;hpb=2636fc31c16c23711cf2b06a4ae8537bba9c1d35;p=simantics%2Fdistrict.git diff --git a/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/add-local.js b/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/add-local.js new file mode 100644 index 00000000..0a5b7b5d --- /dev/null +++ b/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/add-local.js @@ -0,0 +1,137 @@ +var path = require('path') +var test = require('tap').test +var mkdirp = require('mkdirp') +var osenv = require('osenv') +var rimraf = require('rimraf') +var requireInject = require('require-inject') + +var pkg = path.join(__dirname, '/local-dir') +var cache = path.join(pkg, '/cache') +var tmp = path.join(pkg, '/tmp') +var prefix = path.join(pkg, '/prefix') + +var Tacks = require('tacks') +var File = Tacks.File +var Dir = Tacks.Dir + +test('addLocal directory race on Windows', function (t) { + setup() + var p = { + name: 'test', + version: '1.0.0', + type: 'directory', + spec: pkg + } + var fixture = new Tacks( + Dir({ + 'package.json': File(p) + }) + ) + var addLocal = requireInject('../../lib/cache/add-local', { + '../../lib/npm.js': { + cache: cache, + tmp: tmp, + prefix: prefix + }, + '../../lib/cache/get-stat': function (cb) { + cb(null, {}) + }, + chownr: function (x, y, z, cb) { + cb(new Error('chownr should never have been called')) + }, + '../../lib/cache/add-local-tarball.js': function (tgz, data, shasum, cb) { + cb(null) + }, + '../../lib/utils/lifecycle.js': function (data, cycle, p, cb) { + cb(null) + }, + '../../lib/utils/tar.js': { + pack: function (tgz, p, data, fancy, cb) { + cb(null) + } + }, + 'sha': { + get: function (tgz, cb) { + cb(null, 'deadbeef') + } + } + }) + + fixture.create(pkg) + addLocal(p, null, function (err) { + t.ifErr(err, 'addLocal completed without error') + t.done() + }) +}) + +test('addLocal temporary cache file race', function (t) { + // See https://github.com/npm/npm/issues/12669 + setup() + var p = { + name: 'test', + version: '1.0.0', + type: 'directory', + spec: pkg + } + var fixture = new Tacks( + Dir({ + 'package.json': File(p) + }) + ) + var addLocal = requireInject('../../lib/cache/add-local', { + // basic setup/mock stuff + '../../lib/npm.js': { + cache: cache, + tmp: tmp, + prefix: prefix + }, + '../../lib/cache/add-local-tarball.js': function (tgz, data, shasum, cb) { + cb(null) + }, + '../../lib/utils/lifecycle.js': function (data, cycle, p, cb) { + cb(null) + }, + '../../lib/utils/tar.js': { + pack: function (tgz, p, data, fancy, cb) { + cb(null) + } + }, + 'sha': { + get: function (tgz, cb) { + cb(null, 'deadbeef') + } + }, + + // Test-specific mocked values to simulate race. + '../../lib/cache/get-stat': function (cb) { + cb(null, {uid: 1, gid: 2}) + }, + chownr: function (x, y, z, cb) { + // Simulate a race condition between `tar.pack` and `chownr` + // where the latter will return `ENOENT` when an async process + // removes a file that its internal `fs.readdir` listed. + cb({code: 'ENOENT'}) + } + }) + + fixture.create(pkg) + addLocal(p, null, function (err) { + t.ifErr(err, 'addLocal completed without error') + t.done() + }) +}) + +test('cleanup', function (t) { + cleanup() + t.done() +}) + +function setup () { + mkdirp.sync(cache) + mkdirp.sync(tmp) +} + +function cleanup () { + process.chdir(osenv.tmpdir()) + rimraf.sync(pkg) +}