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

basic.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. var tap = require('tap')
  2. var pz = require('../promzard.js')
  3. var spawn = require('child_process').spawn
  4. tap.test('run the example', function (t) {
  5. var example = require.resolve('../example/index.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. console.error('%s %s', node, example)
  45. var c = spawn(node, [example], { customFds: [-1,-1,-1] })
  46. var output = ''
  47. c.stdout.on('data', function (d) {
  48. output += d
  49. respond()
  50. })
  51. var actual = ''
  52. c.stderr.on('data', function (d) {
  53. actual += d
  54. })
  55. function respond () {
  56. console.error('respond', output)
  57. if (output.match(/description: $/)) {
  58. c.stdin.write('testing description\n')
  59. return
  60. }
  61. if (output.match(/entry point: \(index\.js\) $/)) {
  62. c.stdin.write('test-entry.js\n')
  63. return
  64. }
  65. if (output.match(/keywords: $/)) {
  66. c.stdin.write('fugazi function waiting room\n')
  67. // "read" module is weird on node >= 0.10 when not a TTY
  68. // requires explicit ending for reasons.
  69. // could dig in, but really just wanna make tests pass, whatever.
  70. c.stdin.end()
  71. return
  72. }
  73. }
  74. c.on('exit', function () {
  75. console.error('exit event')
  76. })
  77. c.on('close', function () {
  78. console.error('actual', actual)
  79. actual = JSON.parse(actual)
  80. t.deepEqual(actual, expect)
  81. t.end()
  82. })
  83. })