1'use strict' 2var path = require('path') 3var test = require('tap').test 4var Tacks = require('tacks') 5var File = Tacks.File 6var Dir = Tacks.Dir 7var common = require('../common-tap.js') 8 9var basedir = common.pkg 10var testdir = path.join(basedir, 'testdir') 11var cachedir = common.cache 12var globaldir = path.join(basedir, 'global') 13var tmpdir = path.join(basedir, 'tmp') 14 15var conf = { 16 cwd: testdir, 17 env: Object.assign({ 18 npm_config_cache: cachedir, 19 npm_config_tmp: tmpdir, 20 npm_config_prefix: globaldir, 21 npm_config_registry: common.registry, 22 npm_config_loglevel: 'warn' 23 }, process.env) 24} 25 26var cycler = { 27 name: 'cycler', 28 version: '1.0.0', 29 scripts: { 30 uninstall: 'echo #UNINSTALL#', 31 install: 'echo #INSTALL#' 32 } 33} 34 35var fixture = new Tacks(Dir({ 36 cache: Dir(), 37 global: Dir(), 38 tmp: Dir(), 39 testdir: Dir({ 40 'cycler': Dir({ 41 'package.json': File(cycler) 42 }), 43 node_modules: Dir({ 44 'cycler': Dir({ 45 'package.json': File(cycler) 46 }) 47 }), 48 'package.json': File({ 49 name: 'upgrade-lifecycles', 50 version: '1.0.0', 51 dependencies: { 52 'cycler': 'file:cycler' 53 } 54 }) 55 }) 56})) 57 58function setup () { 59 cleanup() 60 fixture.create(basedir) 61} 62 63function cleanup () { 64 fixture.remove(basedir) 65} 66 67test('setup', function (t) { 68 setup() 69 t.done() 70}) 71 72test('upgrade-lifecycles', function (t) { 73 common.npm(['install', 'file:cycler'], conf, function (err, code, stdout, stderr) { 74 if (err) throw err 75 t.is(code, 0, 'command ran ok') 76 77 t.comment(stdout.trim()) 78 t.comment(stderr.trim()) 79 t.match(stdout, /#INSTALL#/, 'ran install lifecycle') 80 t.match(stdout, /#UNINSTALL#/, 'ran uninstall lifecycle') 81 t.done() 82 }) 83}) 84 85test('cleanup', function (t) { 86 cleanup() 87 t.done() 88}) 89