Skip to content

Loading…

added tests from prompter #1

Merged
merged 2 commits into from

2 participants

@substack

This is pretty much the best kind of pull request.

@isaacs isaacs merged commit 74ac817 into npm:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 13, 2012
  1. @substack

    adapted prompter tests

    substack committed
  2. @substack

    delete some superfluous linage

    substack committed
Showing with 81 additions and 0 deletions.
  1. +3 −0 package.json
  2. +30 −0 test/fn.js
  3. +10 −0 test/fn.json
  4. +30 −0 test/simple.js
  5. +8 −0 test/simple.json
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
30 test/fn.js
@@ -0,0 +1,30 @@
+var test = require('tap').test;
+var promzard = require('../');
+
+test('prompt callback param', function (t) {
+ t.plan(1);
+
+ var ctx = { tmpdir : '/tmp' }
+ var file = __dirname + '/fn.json';
+ promzard(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
30 test/simple.js
@@ -0,0 +1,30 @@
+var test = require('tap').test;
+var promzard = require('../');
+
+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"
+ }
+}
Something went wrong with that request. Please try again.