summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/promzard/test/basic.js
blob: ad1c92df9c4c0593488fba1c6f941016880dfd51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var tap = require('tap')
var pz = require('../promzard.js')
var spawn = require('child_process').spawn

tap.test('run the example', function (t) {

  var example = require.resolve('../example/index.js')
  var node = process.execPath

  var expect =  {
    "name": "example",
    "version": "0.0.0",
    "description": "testing description",
    "main": "test-entry.js",
    "directories": {
      "example": "example",
      "test": "test"
    },
    "dependencies": {},
    "devDependencies": {
      "tap": "~0.2.5"
    },
    "scripts": {
      "test": "tap test/*.js"
    },
    "repository": {
      "type": "git",
      "url": "git://github.com/substack/example.git"
    },
    "homepage": "https://github.com/substack/example",
    "keywords": [
      "fugazi",
      "function",
      "waiting",
      "room"
    ],
    "author": {
      "name": "James Halliday",
      "email": "mail@substack.net",
      "url": "http://substack.net"
    },
    "license": "MIT",
    "engine": {
      "node": ">=0.6"
    }
  }

  console.error('%s %s', node, example)
  var c = spawn(node, [example], { customFds: [-1,-1,-1] })
  var output = ''
  c.stdout.on('data', function (d) {
    output += d
    respond()
  })

  var actual = ''
  c.stderr.on('data', function (d) {
    actual += d
  })

  function respond () {
    console.error('respond', output)
    if (output.match(/description: $/)) {
      c.stdin.write('testing description\n')
      return
    }
    if (output.match(/entry point: \(index\.js\) $/)) {
      c.stdin.write('test-entry.js\n')
      return
    }
    if (output.match(/keywords: $/)) {
      c.stdin.write('fugazi function waiting room\n')
      // "read" module is weird on node >= 0.10 when not a TTY
      // requires explicit ending for reasons.
      // could dig in, but really just wanna make tests pass, whatever.
      c.stdin.end()
      return
    }
  }

  c.on('exit', function () {
    console.error('exit event')
  })

  c.on('close', function () {
    console.error('actual', actual)
    actual = JSON.parse(actual)
    t.deepEqual(actual, expect)
    t.end()
  })
})