2 var test = require('tap').test
3 var common = require('../common-tap.js')
4 var path = require('path')
5 var rimraf = require('rimraf')
6 var mkdirp = require('mkdirp')
7 var basepath = path.resolve(__dirname, path.basename(__filename, '.js'))
8 var fixturepath = path.resolve(basepath, 'npm-test-array-bin')
9 var modulepath = path.resolve(basepath, 'node_modules')
10 var installedpath = path.resolve(modulepath, 'npm-test-array-bin')
11 var Tacks = require('tacks')
14 var fixture = new Tacks(
18 '#!/usr/bin/env node\n' +
19 "console.log('test ran ok')\n"
22 'package.json': File({
23 name: 'npm-test-array-bin',
33 "require('child_process').exec('array-bin', { env: process.env },\n" +
34 ' function (err, stdout, stderr) {\n' +
35 " if (err && err.code) throw new Error('exited badly with code = ' + err.code)\n" +
36 ' console.log(stdout)\n' +
37 ' console.error(stderr)\n' +
43 test('setup', function (t) {
47 test('array-bin', function (t) {
48 common.npm(['install', fixturepath], {cwd: basepath}, installCheckAndTest)
49 function installCheckAndTest (err, code, stdout, stderr) {
51 t.is(code, 0, 'install went ok')
52 t.equal(stderr, '', 'no error output')
53 common.npm(['test'], {cwd: installedpath}, testCheckAndRemove)
55 function testCheckAndRemove (err, code, stdout, stderr) {
56 t.ifError(err, 'npm test on array bin')
57 t.equal(code, 0, 'exited OK')
58 t.equal(stderr.trim(), '', 'no error output')
59 t.match(stdout, /test ran ok/, 'child script ran properly')
60 common.npm(['rm', fixturepath], {cwd: basepath}, removeCheckAndDone)
62 function removeCheckAndDone (err, code, stdout, stderr) {
64 t.is(code, 0, 'remove went ok')
68 test('cleanup', function (t) {
74 fixture.create(fixturepath)
75 mkdirp.sync(modulepath)
78 fixture.remove(fixturepath)