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