[apps/tidep0084.git] / example / iot-gateway / node_modules / aws-iot-device-sdk / node_modules / mqtt / node_modules / help-me / test.js
2 var test = require('tape')
3 , concat = require('concat-stream')
4 , fs = require('fs')
5 , helpMe = require('./')
7 test('show the doc/help.txt from the require.main folder if no options are passed', function(t) {
8 t.plan(2)
10 helpMe()
11 .createHelpStream()
12 .pipe(concat(function(data) {
13 fs.readFile('./doc/help.txt', function(err, expected) {
14 t.error(err)
15 t.equal(data.toString(), expected.toString())
16 })
17 }))
18 })
20 test('show a generic help.txt from a folder to a stream', function(t) {
21 t.plan(2)
23 helpMe({
24 dir: 'fixture/basic'
25 }).createHelpStream()
26 .pipe(concat(function(data) {
27 fs.readFile('fixture/basic/help.txt', function(err, expected) {
28 t.error(err)
29 t.equal(data.toString(), expected.toString())
30 })
31 }))
32 })
34 test('custom help command with an array', function(t) {
35 t.plan(2)
37 helpMe({
38 dir: 'fixture/basic'
39 }).createHelpStream(['hello'])
40 .pipe(concat(function(data) {
41 fs.readFile('fixture/basic/hello.txt', function(err, expected) {
42 t.error(err)
43 t.equal(data.toString(), expected.toString())
44 })
45 }))
46 })
48 test('custom help command without an ext', function(t) {
49 t.plan(2)
51 helpMe({
52 dir: 'fixture/basic'
53 , ext: ''
54 }).createHelpStream(['hello'])
55 .pipe(concat(function(data) {
56 fs.readFile('fixture/basic/hello', function(err, expected) {
57 t.error(err)
58 t.equal(data.toString(), expected.toString())
59 })
60 }))
61 })
63 test('custom help command with a string', function(t) {
64 t.plan(2)
66 helpMe({
67 dir: 'fixture/basic'
68 }).createHelpStream('hello')
69 .pipe(concat(function(data) {
70 fs.readFile('fixture/basic/hello.txt', function(err, expected) {
71 t.error(err)
72 t.equal(data.toString(), expected.toString())
73 })
74 }))
75 })
77 test('missing help file', function(t) {
78 t.plan(1)
80 helpMe({
81 dir: 'fixture/basic'
82 }).createHelpStream('abcde')
83 .on('error', function(err) {
84 t.equal(err.code, 'ENOENT')
85 })
86 .resume()
87 })