]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/init-package-json/node_modules/promzard/test/fn.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / init-package-json / node_modules / promzard / test / fn.js
1 var test = require('tap').test;
2 var promzard = require('../');
3 var fs = require('fs')
4 var file = __dirname + '/fn.input';
5
6 var expect = {
7   a : 3,
8   b : '!2B...',
9   c : {
10     x : 5500,
11     y : '/tmp/y/file.txt',
12   }
13 }
14 expect.a_function = fs.readFileSync(file, 'utf8')
15 expect.asyncPrompt = 'async prompt'
16
17 if (process.argv[2] === 'child') {
18   return child()
19 }
20
21 test('prompt callback param', function (t) {
22   t.plan(1);
23
24   var spawn = require('child_process').spawn
25   var child = spawn(process.execPath, [__filename, 'child'])
26
27   var output = ''
28   child.stderr.on('data', function (c) {
29     output += c
30   })
31
32   child.on('close', function () {
33     console.error('output=%j', output)
34     output = JSON.parse(output)
35     t.same(output, expect);
36     t.end()
37   })
38
39   setTimeout(function () {
40     child.stdin.write('\n')
41   }, 100)
42   setTimeout(function () {
43     child.stdin.write('55\n')
44   }, 150)
45   setTimeout(function () {
46     child.stdin.end('async prompt\n')
47   }, 200)
48 })
49
50 function child () {
51   var ctx = { tmpdir : '/tmp' }
52   var file = __dirname + '/fn.input';
53   promzard(file, ctx, function (err, output) {
54     console.error(JSON.stringify(output))
55   })
56 }