Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adapted prompter tests

  • Loading branch information...
commit ff724dba9ca7aacb45e102206a5d6a226468370d 1 parent c029a2b
@substack substack authored
View
3  package.json
@@ -9,6 +9,9 @@
"dependencies": {
"read": "0.0.3"
},
+ "devDependencies": {
+ "tap": "~0.2.5"
+ },
"main": "promzard.js",
"scripts": {
"test": "tap test/*.js"
View
31 test/fn.js
@@ -0,0 +1,31 @@
+var test = require('tap').test;
+var prompter = require('../');
+var Stream = require('stream');
+
+test('prompt callback param', function (t) {
+ t.plan(1);
+
+ var ctx = { tmpdir : '/tmp' }
+ var file = __dirname + '/fn.json';
+ prompter(file, ctx, function (err, output) {
+ t.same(
+ {
+ a : 3,
+ b : '!2B...',
+ c : {
+ x : 5500,
+ y : '/tmp/y/file.txt',
+ }
+ },
+ output
+ );
+ });
+
+ setTimeout(function () {
+ process.stdin.emit('data', '\n');
+ }, 100);
+
+ setTimeout(function () {
+ process.stdin.emit('data', '55\n');
+ }, 200);
+});
View
10 test/fn.json
@@ -0,0 +1,10 @@
+{
+ "a": 1 + 2,
+ "b": prompt('To be or not to be?', '!2b', function (s) {
+ return s.toUpperCase() + '...'
+ }),
+ "c": {
+ "x": prompt(function (x) { return x * 100 }),
+ "y": tmpdir + "/y/file.txt"
+ }
+}
View
31 test/simple.js
@@ -0,0 +1,31 @@
+var test = require('tap').test;
+var promzard = require('../');
+var Stream = require('stream');
+
+test('simple', function (t) {
+ t.plan(1);
+
+ var ctx = { tmpdir : '/tmp' }
+ var file = __dirname + '/simple.json';
+ promzard(file, ctx, function (err, output) {
+ t.same(
+ {
+ a : 3,
+ b : '!2b',
+ c : {
+ x : 55,
+ y : '/tmp/y/file.txt',
+ }
+ },
+ output
+ );
+ });
+
+ setTimeout(function () {
+ process.stdin.emit('data', '\n');
+ }, 100);
+
+ setTimeout(function () {
+ process.stdin.emit('data', '55\n');
+ }, 200);
+});
View
8 test/simple.json
@@ -0,0 +1,8 @@
+{
+ "a": 1 + 2,
+ "b": prompt('To be or not to be?', '!2b'),
+ "c": {
+ "x": prompt(),
+ "y": tmpdir + "/y/file.txt"
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.