Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

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