1// verify that prepublish runs on pack and publish 2var test = require('tap').test 3var common = require('../common-tap') 4var fs = require('graceful-fs') 5var join = require('path').join 6var mkdirp = require('mkdirp') 7var rimraf = require('rimraf') 8 9var pkg = common.pkg 10var manifest = join(pkg, 'package.json') 11var tmp = join(pkg, 'tmp') 12var cache = common.cache 13 14var data = { 15 name: '@scope/generic-package', 16 version: '90000.100001.5' 17} 18 19test('setup', function (t) { 20 var n = 0 21 22 rimraf.sync(pkg) 23 24 mkdirp(pkg, then()) 25 mkdirp(cache, then()) 26 mkdirp(tmp, then()) 27 28 function then () { 29 n++ 30 return function (er) { 31 t.ifError(er) 32 if (--n === 0) next() 33 } 34 } 35 36 function next () { 37 fs.writeFile(manifest, JSON.stringify(data), 'ascii', done) 38 } 39 40 function done (er) { 41 t.ifError(er) 42 43 t.pass('setup done') 44 t.end() 45 } 46}) 47 48test('test', function (t) { 49 var env = { 50 'npm_config_cache': cache, 51 'npm_config_tmp': tmp, 52 'npm_config_prefix': pkg, 53 'npm_config_global': 'false' 54 } 55 56 for (var i in process.env) { 57 if (!/^npm_config_/.test(i)) env[i] = process.env[i] 58 } 59 60 common.npm([ 61 'pack', 62 '--loglevel', 'warn' 63 ], { 64 cwd: pkg, 65 env: env 66 }, function (err, code, stdout, stderr) { 67 t.ifErr(err, 'npm pack finished without error') 68 t.equal(code, 0, 'npm pack exited ok') 69 t.notOk(stderr, 'got stderr data: ' + JSON.stringify('' + stderr)) 70 stdout = stdout.trim() 71 var regex = new RegExp('scope-generic-package-90000.100001.5.tgz', 'ig') 72 t.ok(stdout.match(regex), 'found package') 73 t.end() 74 }) 75}) 76 77test('cleanup', function (t) { 78 rimraf.sync(pkg) 79 t.pass('cleaned up') 80 t.end() 81}) 82