1var fs = require('fs') 2var path = require('path') 3 4var mkdirp = require('mkdirp') 5var rimraf = require('rimraf') 6var test = require('tap').test 7var common = require('../common-tap.js') 8 9var pkg = common.pkg 10 11var editorSrc = function () { /* 12#!/usr/bin/env node 13var fs = require('fs') 14if (fs.existsSync(process.argv[2])) { 15 console.log('success') 16} else { 17 console.log('error') 18 process.exit(1) 19} 20*/ }.toString().split('\n').slice(1, -1).join('\n') 21var editorPath = path.join(pkg, 'editor') 22 23test('setup', function (t) { 24 cleanup(function (er) { 25 t.ifError(er, 'old directory removed') 26 27 mkdirp(pkg, '0777', function (er) { 28 fs.writeFileSync(editorPath, editorSrc) 29 fs.chmodSync(editorPath, '0777') 30 t.ifError(er, 'created package directory correctly') 31 t.end() 32 }) 33 }) 34}) 35 36test('saving configs', function (t) { 37 var opts = { 38 cwd: pkg, 39 env: { 40 PATH: process.env.PATH, 41 // We rely on the cwd + relative path combo here because otherwise, 42 // this test will break if there's spaces in the editorPath 43 EDITOR: 'node editor' 44 } 45 } 46 common.npm( 47 [ 48 'config', 49 '--prefix', pkg, 50 '--global', 51 'edit' 52 ], 53 opts, 54 function (err, code, stdout, stderr) { 55 t.ifError(err, 'command ran without issue') 56 57 t.equal(stderr, '', 'got nothing on stderr') 58 t.equal(code, 0, 'exit ok') 59 t.equal(stdout, 'success\n', 'got success message') 60 t.end() 61 } 62 ) 63}) 64 65test('cleanup', function (t) { 66 cleanup(function (er) { 67 t.ifError(er, 'test directory removed OK') 68 t.end() 69 }) 70}) 71 72function cleanup (cb) { 73 rimraf(pkg, cb) 74} 75