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

buffer.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. var tap = require('tap')
  2. var pz = require('../promzard.js')
  3. var spawn = require('child_process').spawn
  4. tap.test('run the example using a buffer', function (t) {
  5. var example = require.resolve('../example/buffer.js')
  6. var node = process.execPath
  7. var expect = {
  8. "name": "example",
  9. "version": "0.0.0",
  10. "description": "testing description",
  11. "main": "test-entry.js",
  12. "directories": {
  13. "example": "example",
  14. "test": "test"
  15. },
  16. "dependencies": {},
  17. "devDependencies": {
  18. "tap": "~0.2.5"
  19. },
  20. "scripts": {
  21. "test": "tap test/*.js"
  22. },
  23. "repository": {
  24. "type": "git",
  25. "url": "git://github.com/substack/example.git"
  26. },
  27. "homepage": "https://github.com/substack/example",
  28. "keywords": [
  29. "fugazi",
  30. "function",
  31. "waiting",
  32. "room"
  33. ],
  34. "author": {
  35. "name": "James Halliday",
  36. "email": "mail@substack.net",
  37. "url": "http://substack.net"
  38. },
  39. "license": "MIT",
  40. "engine": {
  41. "node": ">=0.6"
  42. }
  43. }
  44. var c = spawn(node, [example], { customFds: [-1,-1,-1] })
  45. var output = ''
  46. c.stdout.on('data', function (d) {
  47. output += d
  48. respond()
  49. })
  50. var actual = ''
  51. c.stderr.on('data', function (d) {
  52. actual += d
  53. })
  54. function respond () {
  55. if (output.match(/description: $/)) {
  56. c.stdin.write('testing description\n')
  57. return
  58. }
  59. if (output.match(/entry point: \(index\.js\) $/)) {
  60. c.stdin.write('test-entry.js\n')
  61. return
  62. }
  63. if (output.match(/keywords: $/)) {
  64. c.stdin.write('fugazi function waiting room\n')
  65. // "read" module is weird on node >= 0.10 when not a TTY
  66. // requires explicit ending for reasons.
  67. // could dig in, but really just wanna make tests pass, whatever.
  68. c.stdin.end()
  69. return
  70. }
  71. }
  72. c.on('close', function () {
  73. actual = JSON.parse(actual)
  74. t.deepEqual(actual, expect)
  75. t.end()
  76. })
  77. })