1'use strict' 2var test = require('tap').test 3var common = require('../common-tap.js') 4var path = require('path') 5var rimraf = require('rimraf') 6var mkdirp = require('mkdirp') 7var basepath = common.pkg 8var fixturepath = path.resolve(basepath, 'npm-test-test-package') 9var modulepath = path.resolve(basepath, 'node_modules') 10var installedpath = path.resolve(modulepath, 'npm-test-test-package') 11var Tacks = require('tacks') 12var File = Tacks.File 13var Dir = Tacks.Dir 14 15var fixture = new Tacks( 16 Dir({ 17 README: File( 18 'just an npm test\n' 19 ), 20 'package.json': File({ 21 name: 'npm-test-test-package', 22 author: 'Testy McMock', 23 version: '1.2.3-99-b', 24 description: "This is a test package used for debugging. It has some random data and that's all." 25 }) 26 }) 27) 28 29test('setup', function (t) { 30 setup() 31 t.done() 32}) 33 34test('test-package', function (t) { 35 common.npm(['install', fixturepath], {cwd: basepath}, installCheckAndTest) 36 37 function installCheckAndTest (err, code, stdout, stderr) { 38 if (err) throw err 39 t.is(code, 0, 'install went ok') 40 common.npm(['test'], {cwd: installedpath}, testCheckAndRemove) 41 } 42 43 function testCheckAndRemove (err, code, stdout, stderr) { 44 if (err) throw err 45 t.is(code, 0, 'npm test w/o test is ok') 46 common.npm(['rm', fixturepath], {cwd: basepath}, removeCheckAndDone) 47 } 48 49 function removeCheckAndDone (err, code, stdout, stderr) { 50 if (err) throw err 51 t.is(code, 0, 'remove went ok') 52 t.done() 53 } 54}) 55 56test('cleanup', function (t) { 57 cleanup() 58 t.done() 59}) 60 61function setup () { 62 cleanup() 63 fixture.create(fixturepath) 64 mkdirp.sync(modulepath) 65} 66 67function cleanup () { 68 fixture.remove(fixturepath) 69 rimraf.sync(basepath) 70} 71