1'use strict' 2var mr = require('npm-registry-mock') 3var npa = require('npm-package-arg') 4var test = require('tap').test 5 6var common = require('../common-tap.js') 7var npm = require('../../lib/npm.js') 8 9var pkg = common.pkg 10 11test('setup', function (t) { 12 process.chdir(pkg) 13 14 var opts = { 15 cache: common.cache, 16 registry: common.registry, 17 // important to make sure devDependencies don't get stripped 18 dev: true 19 } 20 npm.load(opts, t.end) 21}) 22 23test('fetch-package-metadata provides resolved metadata', function (t) { 24 t.plan(4) 25 26 var fetchPackageMetadata = require('../../lib/fetch-package-metadata') 27 28 var testPackage = npa('test-package@>=0.0.0') 29 30 mr({ port: common.port }, thenFetchMetadata) 31 32 var server 33 function thenFetchMetadata (err, s) { 34 t.ifError(err, 'setup mock registry') 35 server = s 36 37 fetchPackageMetadata(testPackage, __dirname, thenVerifyMetadata) 38 } 39 40 function thenVerifyMetadata (err, pkg) { 41 t.ifError(err, 'fetched metadata') 42 43 t.equals(pkg._resolved, 'http://localhost:' + common.port + '/test-package/-/test-package-0.0.0.tgz', '_resolved') 44 t.equals(pkg._integrity, 'sha1-sNMrbEXCWcV4uiADdisgUTG9+9E=', '_integrity') 45 server.close() 46 t.end() 47 } 48}) 49