1var test = require('tap').test; 2var promzard = require('../'); 3var fs = require('fs') 4var file = __dirname + '/fn.input'; 5 6var expect = { 7 a : 3, 8 b : '!2B...', 9 c : { 10 x : 5500, 11 y : '/tmp/y/file.txt', 12 } 13} 14expect.a_function = fs.readFileSync(file, 'utf8') 15expect.asyncPrompt = 'async prompt' 16 17if (process.argv[2] === 'child') { 18 return child() 19} 20 21test('prompt callback param', function (t) { 22 t.plan(1); 23 24 var spawn = require('child_process').spawn 25 var child = spawn(process.execPath, [__filename, 'child']) 26 27 var output = '' 28 child.stderr.on('data', function (c) { 29 output += c 30 }) 31 32 child.on('close', function () { 33 console.error('output=%j', output) 34 output = JSON.parse(output) 35 t.same(output, expect); 36 t.end() 37 }) 38 39 setTimeout(function () { 40 child.stdin.write('\n') 41 }, 100) 42 setTimeout(function () { 43 child.stdin.write('55\n') 44 }, 150) 45 setTimeout(function () { 46 child.stdin.end('async prompt\n') 47 }, 200) 48}) 49 50function child () { 51 var ctx = { tmpdir : '/tmp' } 52 var file = __dirname + '/fn.input'; 53 promzard(file, ctx, function (err, output) { 54 console.error(JSON.stringify(output)) 55 }) 56} 57