summaryrefslogtreecommitdiff
path: root/node_modules/prompt/test
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/prompt/test')
-rw-r--r--node_modules/prompt/test/helpers.js161
-rw-r--r--node_modules/prompt/test/interactive-prompt-test.js49
-rw-r--r--node_modules/prompt/test/macros.js82
-rw-r--r--node_modules/prompt/test/prompt-test.js817
4 files changed, 1109 insertions, 0 deletions
diff --git a/node_modules/prompt/test/helpers.js b/node_modules/prompt/test/helpers.js
new file mode 100644
index 0000000..b21021f
--- /dev/null
+++ b/node_modules/prompt/test/helpers.js
@@ -0,0 +1,161 @@
+/*
+ * helpers.js: test helpers for the prompt tests.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var stream = require('stream'),
+ util = require('util'),
+ prompt = require('../lib/prompt');
+
+var helpers = exports;
+
+var MockReadWriteStream = helpers.MockReadWriteStream = function () {
+ //
+ // No need to do anything here, it's just a mock.
+ //
+ var self = this;
+ this.on('pipe', function (src) {
+ var _emit = src.emit;
+ src.emit = function () {
+ //console.dir(arguments);
+ _emit.apply(src, arguments);
+ };
+
+ src.on('data', function (d) {
+ self.emit('data', d + '');
+ })
+ })
+};
+
+util.inherits(MockReadWriteStream, stream.Stream);
+
+['resume', 'pause', 'setEncoding', 'flush', 'end'].forEach(function (method) {
+ MockReadWriteStream.prototype[method] = function () { /* Mock */ };
+});
+
+MockReadWriteStream.prototype.write = function (msg) {
+ this.emit('data', msg);
+ return true;
+};
+
+MockReadWriteStream.prototype.writeNextTick = function (msg) {
+ var self = this
+ process.nextTick(function () {
+ self.write(msg);
+ });
+};
+
+//
+// Create some mock streams for asserting against
+// in our prompt teSts.
+//
+helpers.stdin = new MockReadWriteStream();
+helpers.stdout = new MockReadWriteStream();
+helpers.stderr = new MockReadWriteStream();
+
+//
+// Because `read` uses a `process.nextTick` for reading from
+// stdin, it is necessary to write sequences of input with extra
+// `process.nextTick` calls
+//
+helpers.stdin.writeSequence = function (lines) {
+ if (!lines || !lines.length) {
+ return;
+ }
+
+ helpers.stdin.writeNextTick(lines.shift());
+ prompt.once('prompt', function () {
+ process.nextTick(function () {
+ helpers.stdin.writeSequence(lines);
+ });
+ });
+}
+
+//
+// Monkey punch `util.error` to silence console output
+// and redirect to helpers.stderr for testing.
+//
+process.stderr.write = function () {
+ helpers.stderr.write.apply(helpers.stderr, arguments);
+}
+
+// 1) .properties
+// 2) warning --> message
+// 3) Name --> description || key
+// 4) validator --> conform (fxns), pattern (regexp), format (built-in)
+// 5) empty --> required
+helpers.schema = {
+ properties: {
+ oldschema: {
+ message: 'Enter your username',
+ validator: /^[\w|\-]+$/,
+ warning: 'username can only be letters, numbers, and dashes',
+ empty: false
+ },
+ riffwabbles: {
+ pattern: /^[\w|\-]+$/,
+ message: 'riffwabbles can only be letters, numbers, and dashes',
+ default: 'foobizzles'
+ },
+ number: {
+ type: 'number',
+ message: 'pick a number, any number',
+ default: 10
+ },
+ integer: {
+ type: 'integer'
+ },
+ boolean: {
+ type: 'boolean'
+ },
+ username: {
+ pattern: /^[\w|\-]+$/,
+ message: 'Username can only be letters, numbers, and dashes'
+ },
+ notblank: {
+ required: true
+ },
+ password: {
+ hidden: true,
+ required: true
+ },
+ badValidator: {
+ pattern: ['cant', 'use', 'array']
+ },
+ animal: {
+ description: 'Enter an animal',
+ default: 'dog',
+ pattern: /dog|cat/
+ },
+ sound: {
+ description: 'What sound does this animal make?',
+ conform: function (value) {
+ var animal = prompt.history(0).value;
+
+ return animal === 'dog' && value === 'woof'
+ || animal === 'cat' && value === 'meow';
+ }
+ },
+ fnvalidator: {
+ name: 'fnvalidator',
+ validator: function (line) {
+ return line.slice(0,2) == 'fn';
+ },
+ message: 'fnvalidator must start with "fn"'
+ },
+ fnconform: {
+ conform: function (line) {
+ return line.slice(0,2) == 'fn';
+ },
+ message: 'fnconform must start with "fn"'
+ }/*,
+ cbvalidator: {
+ conform: function (line, next) {
+ next(line.slice(0,2) == 'cb');
+ },
+ message: 'cbvalidator must start with "cb"'
+ }*/
+ }
+};
diff --git a/node_modules/prompt/test/interactive-prompt-test.js b/node_modules/prompt/test/interactive-prompt-test.js
new file mode 100644
index 0000000..a3032e3
--- /dev/null
+++ b/node_modules/prompt/test/interactive-prompt-test.js
@@ -0,0 +1,49 @@
+/*
+ * prompt-test.js: Tests for prompt.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var assert = require('assert'),
+ vows = require('vows'),
+ prompt = require('../lib/prompt'),
+ winston = require('winston').cli(),
+ helpers = require('./helpers');
+
+vows.describe('prompt/interactive').addBatch({
+ "When using prompt": {
+ topic: function () {
+ //
+ // Reset the prompt for interactive testing
+ //
+ prompt.started = false;
+ prompt.start();
+ winston.info('These prompt tests are interactive');
+ winston.info('Not following instructions will result in test failure');
+ return null;
+ },
+ "the getInput() method": {
+ "when passed a complex property with `hidden: true`": {
+ topic: function () {
+ winston.info('When prompted, enter: 12345 [backspace] [backspace] [enter]');
+ prompt.getInput({ path: ['password'], schema: helpers.schema.properties.password }, this.callback);
+ },
+ "should respond with `123`": function (err, result) {
+ assert.isNull(err);
+ assert.equal(result, '123');
+ },
+ "and then when passed a complex property expecting a number": {
+ topic: function () {
+ winston.info('When prompted, enter: 123 [enter]');
+ prompt.getInput({ path: ['number'], schema: helpers.schema.properties.number }, this.callback);
+ },
+ "should respond with `123` (as a number)": function (err, result) {
+ assert.isNull(err);
+ assert.equal(result, 123);
+ }
+ }
+ }
+ }
+ }
+}).export(module);
diff --git a/node_modules/prompt/test/macros.js b/node_modules/prompt/test/macros.js
new file mode 100644
index 0000000..9f58f08
--- /dev/null
+++ b/node_modules/prompt/test/macros.js
@@ -0,0 +1,82 @@
+/*
+ * macros.js: Test macros for prompt.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var assert = require('assert'),
+ helpers = require('./helpers'),
+ prompt = require('../lib/prompt');
+
+exports.shouldConfirm = function (options, mixin) {
+ var message = options.response.toString().replace(/\n/g, ''),
+ messages = ["When using prompt", "the confirm() method"],
+ context = {},
+ last = context;
+
+ messages = messages.concat(options.messages || []);
+
+ while (messages.length) {
+ var text = messages.shift();
+ last[text] = {};
+ last = last[text];
+ }
+
+ last['responding with ' + message] = {
+ topic: function () {
+ if(!mixin)
+ prompt.confirm(options.prop, this.callback);
+ else
+ prompt.confirm(options.prop, mixin, this.callback);
+
+ if (!Array.isArray(options.response)) {
+ helpers.stdin.writeNextTick(options.response + '\n');
+ }
+ else {
+ helpers.stdin.writeSequence(options.response);
+ }
+ },
+ "should respond with true" : function(err, result) {
+ assert.isNull(err);
+ assert.isTrue(result);
+ }
+ }
+
+ return context;
+};
+
+exports.shouldNotConfirm = function (options) {
+ var message = options.response.toString().replace(/\n/g, ''),
+ messages = ["When using prompt", "the confirm() method"],
+ context = {},
+ last = context;
+
+ messages = messages.concat(options.messages || []);
+
+ while (messages.length) {
+ var text = messages.shift();
+ last[text] = {};
+ last = last[text];
+ }
+
+ last['responding with ' + message] = {
+ topic: function () {
+ prompt.confirm(options.prop, this.callback);
+
+ if (!Array.isArray(options.response)) {
+ helpers.stdin.writeNextTick(options.response + '\n');
+ }
+ else {
+ helpers.stdin.writeSequence(options.response);
+ }
+ },
+ "should respond with false" : function(err, result) {
+ assert.isNull(err);
+ assert.isFalse(result);
+ }
+ };
+
+ return context;
+};
+
diff --git a/node_modules/prompt/test/prompt-test.js b/node_modules/prompt/test/prompt-test.js
new file mode 100644
index 0000000..2be73bc
--- /dev/null
+++ b/node_modules/prompt/test/prompt-test.js
@@ -0,0 +1,817 @@
+/*
+ * prompt-test.js: Tests for prompt.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var assert = require('assert'),
+ vows = require('vows'),
+ prompt = require('../lib/prompt'),
+ helpers = require('./helpers'),
+ macros = require('./macros'),
+ schema = helpers.schema;
+
+// A helper to pass fragments of our schema into prompt as full schemas.
+function grab () {
+ var names = [].slice.call(arguments),
+ complete = { schema: {} };
+
+ names.forEach(function (name) {
+ complete.path = [name],
+ complete.schema = schema.properties[name];
+ });
+ return complete;
+};
+
+//
+// Reset the prompt for mock testing
+//
+prompt.started = false;
+prompt.start({
+ stdin: helpers.stdin,
+ stdout: helpers.stdout
+});
+
+vows.describe('prompt').addBatch({
+ "When using prompt": {
+ "the getInput() method": {
+ "with a simple string prompt": {
+ topic: function () {
+ var that = this;
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ })
+
+ prompt.getInput('test input', this.callback);
+ helpers.stdin.writeNextTick('test value\n');
+ },
+ "should prompt to stdout and respond with data": function (err, input) {
+ assert.isNull(err);
+ assert.equal(input, 'test value');
+ assert.isTrue(this.msg.indexOf('test input') !== -1);
+ }
+ },
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the getInput() method": {
+ "with any field that is not supposed to be empty": {
+ "and we don't provide any input": {
+ topic: function () {
+ var that = this;
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ });
+
+ helpers.stderr.once('data', function (msg) {
+ that.errmsg = msg;
+ });
+
+ prompt.getInput(grab('notblank'), function () {});
+ prompt.once('invalid', this.callback.bind(null, null))
+ helpers.stdin.writeNextTick('\n');
+ },
+ "should prompt with an error": function (_, prop, input) {
+ assert.isObject(prop);
+ assert.equal(input, '');
+ assert.isTrue(this.errmsg.indexOf('Invalid input') !== -1);
+ assert.isTrue(this.msg.indexOf('notblank') !== -1);
+ }
+ }
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the getInput() method": {
+ "with a hidden field that is not supposed to be empty": {
+ "and we provide valid input": {
+ topic: function () {
+ var that = this;
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ });
+
+ prompt.getInput('password', this.callback);
+ helpers.stdin.writeNextTick('trustno1\n');
+ },
+
+ "should prompt to stdout and respond with data": function (err, input) {
+ assert.isNull(err);
+ assert.equal(input, 'trustno1');
+ assert.isTrue(this.msg.indexOf('password') !== -1);
+ }
+ },
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the getInput() method": {
+ "with a hidden field that is not supposed to be empty": {
+ "and we don't provide an input": {
+ topic: function () {
+ var that = this;
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ });
+
+ helpers.stderr.once('data', function (msg) {
+ that.errmsg = msg;
+ });
+
+ prompt.getInput(grab('password'), function () {} );
+ prompt.once('invalid', this.callback.bind(null, null))
+ helpers.stdin.writeNextTick('\n');
+ },
+ "should prompt with an error": function (ign, prop, input) {
+ assert.isObject(prop);
+ assert.equal(input, '');
+ assert.isTrue(this.errmsg.indexOf('Invalid input') !== -1);
+ assert.isTrue(this.msg.indexOf('password') !== -1);
+ }
+ }
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the getInput() method": {
+ "with an integer field": {
+ "and we provide valid input": {
+ topic: function () {
+ var that = this;
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ });
+
+ prompt.getInput(grab('integer'), this.callback);
+ helpers.stdin.writeNextTick('42\n');
+ },
+ "should prompt to stdout and respond with data": function (err, input) {
+ assert.isNull(err);
+ assert.equal(input, '42');
+ assert.isTrue(this.msg.indexOf('integer') !== -1);
+ }
+ },
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the getInput() method": {
+ "with an integer field": {
+ "and we don't provide an integer": {
+ topic: function () {
+ var that = this;
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ });
+
+ helpers.stderr.once('data', function (msg) {
+ that.errmsg = msg;
+ })
+
+ prompt.getInput(grab('integer'), this.callback);
+
+ prompt.once('invalid', function () {
+ prompt.once('prompt', function () {
+ process.nextTick(function () {
+ helpers.stdin.writeNextTick('42\n');
+ })
+ })
+ });
+
+ helpers.stdin.writeNextTick('4.2\n');
+ },
+ "should prompt with an error before completing the operation": function (err, input) {
+ assert.isNull(err);
+ assert.equal(input, '42');
+ assert.isTrue(this.errmsg.indexOf('Invalid input') !== -1);
+ assert.isTrue(this.msg.indexOf('integer') !== -1);
+ }
+ }
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the getInput() method": {
+ "with a boolean field": {
+ "and we provide valid input": {
+ topic: function () {
+ var that = this;
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ });
+
+ prompt.getInput(grab('boolean'), this.callback);
+ helpers.stdin.writeNextTick('true\n');
+ },
+ "should prompt to stdout and respond with data": function (err, input) {
+ assert.isNull(err);
+ assert.equal(input, true);
+ assert.isTrue(this.msg.indexOf('boolean') !== -1);
+ }
+ },
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the getInput() method": {
+ "with a boolean field": {
+ "and we don't provide an bool": {
+ topic: function () {
+ var that = this;
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ });
+
+ helpers.stderr.once('data', function (msg) {
+ that.errmsg = msg;
+ })
+
+ prompt.getInput(grab('boolean'), this.callback);
+
+ prompt.once('invalid', function () {
+ prompt.once('prompt', function () {
+ process.nextTick(function () {
+ helpers.stdin.writeNextTick('F\n');
+ })
+ })
+ });
+
+ helpers.stdin.writeNextTick('4.2\n');
+ },
+ "should prompt with an error before completing the operation": function (err, input) {
+ assert.isNull(err);
+ assert.equal(input, false);
+ assert.isTrue(this.errmsg.indexOf('Invalid input') !== -1);
+ assert.isTrue(this.msg.indexOf('boolean') !== -1);
+ }
+ }
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the getInput() method": {
+ "with a complex property prompt": {
+ "and a valid input": {
+ topic: function () {
+ var that = this;
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ });
+
+ prompt.getInput(grab('username'), this.callback);
+ helpers.stdin.writeNextTick('some-user\n');
+ },
+ "should prompt to stdout and respond with data": function (err, input) {
+ assert.isNull(err);
+ assert.equal(input, 'some-user');
+ assert.isTrue(this.msg.indexOf('username') !== -1);
+ }
+ }
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the getInput() method": {
+ "with a complex property prompt": {
+ "and an invalid input": {
+ topic: function () {
+ var that = this;
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ });
+
+ helpers.stderr.once('data', function (msg) {
+ that.errmsg = msg;
+ })
+
+ prompt.getInput(grab('username'), this.callback);
+
+ prompt.once('invalid', function () {
+ prompt.once('prompt', function () {
+ process.nextTick(function () {
+ helpers.stdin.writeNextTick('some-user\n');
+ })
+ })
+ });
+
+ helpers.stdin.writeNextTick('some -user\n');
+ },
+ "should prompt with an error before completing the operation": function (err, input) {
+ assert.isNull(err);
+ assert.equal(input, 'some-user');
+ assert.isTrue(this.errmsg.indexOf('Username can only be letters, numbers, and dashes') !== -1);
+ assert.isTrue(this.msg.indexOf('username') !== -1);
+ }
+ }
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the getInput() method": {
+ "with a complex property prompt": {
+ "with an invalid validator (array)": {
+ topic: function () {
+ var that = this,
+ called;
+
+ prompt.getInput(grab('badValidator'), function (err) {
+ if (!called) {
+ called = true;
+ that.callback(err);
+ }
+ });
+ helpers.stdin.writeNextTick('some-user\n');
+ },
+ "should respond with an error": function (err, ign) {
+ assert.isTrue(!!err);
+ }
+ }
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the get() method": {
+ "with a simple string prompt": {
+ "that is not a property in prompt.properties": {
+ topic: function () {
+ var that = this;
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ })
+
+ prompt.get('test input', this.callback);
+ helpers.stdin.writeNextTick('test value\n');
+ },
+ "should prompt to stdout and respond with the value": function (err, result) {
+ assert.isNull(err);
+ assert.include(result, 'test input');
+ assert.equal(result['test input'], 'test value');
+ assert.isTrue(this.msg.indexOf('test input') !== -1);
+ }
+ },
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the get() method": {
+ "with a simple string prompt": {
+ "that is a property name in prompt.properties": {
+ "with a default value": {
+ topic: function () {
+ var that = this;
+
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ });
+
+ prompt.properties.riffwabbles = schema.properties.riffwabbles;
+ prompt.get('riffwabbles', this.callback);
+ helpers.stdin.writeNextTick('\n');
+ },
+ "should prompt to stdout and respond with the default value": function (err, result) {
+ assert.isNull(err);
+ assert.isTrue(this.msg.indexOf('riffwabbles') !== -1);
+ assert.isTrue(this.msg.indexOf('(foobizzles)') !== -1);
+ assert.include(result, 'riffwabbles');
+ assert.equal(result['riffwabbles'], schema.properties['riffwabbles'].default);
+ }
+ },
+ }
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the get() method": {
+ "with a simple string prompt": {
+ "that is a property name in prompt.properties": {
+ "that expects a numeric value": {
+ "and gets valid input": {
+ topic: function () {
+ var that = this;
+
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ });
+
+ prompt.properties.number = schema.properties.number;
+ prompt.get('number', this.callback);
+ helpers.stdin.writeNextTick('15\n');
+ },
+ "should prompt to stdout and respond with a numeric value": function (err, result) {
+ assert.isNull(err);
+ assert.include(result, 'number');
+ assert.equal(result['number'], 15);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the get() method": {
+ "with a simple string prompt": {
+ "that is a property name in prompt.properties": {
+ "with a sync function validator (.validator)": {
+ topic: function () {
+ var that = this;
+
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ });
+
+ prompt.get(helpers.schema.properties.fnvalidator, this.callback);
+ helpers.stdin.writeNextTick('fn123\n');
+ },
+ "should accept a value that is checked": function (err, result) {
+ assert.isNull(err);
+ assert.equal(result['fnvalidator'],'fn123');
+ }
+ }
+ }
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the get() method": {
+ "with a simple string prompt": {
+ "that is a property name in prompt.properties": {
+ "with a sync function validator (.conform)": {
+ topic: function () {
+ var that = this;
+
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ });
+
+ prompt.get(grab('fnconform'), this.callback);
+ helpers.stdin.writeNextTick('fn123\n');
+ },
+ "should accept a value that is checked": function (err, result) {
+ assert.isNull(err);
+ assert.equal(result['fnconform'],'fn123');
+ }
+ }
+ //
+ // Remark Does not work with revalidator
+ //
+ // "with a callback validator": {
+ // topic: function () {
+ // var that = this;
+ //
+ // helpers.stdout.once('data', function (msg) {
+ // that.msg = msg;
+ // });
+ //
+ // prompt.get(grab('cbvalidator'), this.callback);
+ // helpers.stdin.writeNextTick('cb123\n');
+ // },
+ // "should not accept a value that is correct": function (err, result) {
+ // assert.isNull(err);
+ // assert.equal(result['cbvalidator'],'cb123');
+ // }
+ // }
+ }
+ },
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the get() method": {
+ "with a simple string prompt": {
+ "that is a property name in prompt.properties": {
+ "with a sync function before (.before)": {
+ topic: function() {
+ var that = this;
+
+ helpers.stdout.once('data', function(msg) {
+ that.msg = msg;
+ });
+
+ prompt.get({
+ properties: {
+ fnbefore: {
+ before: function(v) {
+ return 'v' + v;
+ }
+ }
+ }
+ }, this.callback);
+ helpers.stdin.writeNextTick('fn456\n');
+ },
+ "should modify user's input": function(e, result) {
+ assert.equal(result.fnbefore, 'vfn456');
+ }
+ }
+ }
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the get() method": {
+ "skip prompt with prompt.overide": {
+ topic: function () {
+ prompt.override = { coconihet: 'whatever' }
+ prompt.get('coconihet', this.callback);
+ },
+ "skips prompt and uses overide": function (err, results) {
+ assert.equal(results.coconihet, 'whatever')
+ }
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the addProperties() method": {
+ topic: function () {
+ prompt.addProperties({}, ['foo', 'bar'], this.callback);
+ helpers.stdin.writeSequence(['foo\n', 'bar\n']);
+ },
+ "should add the properties to the object": function (err, obj) {
+ assert.isNull(err);
+ assert.isObject(obj);
+ assert.equal(obj.foo, 'foo');
+ assert.equal(obj.bar, 'bar');
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the get() method": {
+ "with old schema": {
+ topic: function () {
+ var that = this;
+
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ });
+
+ prompt.properties.username = schema.properties.oldschema;
+ prompt.get('username', this.callback);
+
+ helpers.stdin.writeSequence(['\n', 'hell$\n', 'hello\n']);
+ },
+ "should prompt to stdout and respond with the default value": function (err, result) {
+ assert.isNull(err);
+ assert.isTrue(this.msg.indexOf('username') !== -1);
+ assert.include(result, 'username');
+ assert.equal(result.username, 'hello');
+ }
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the history() method": {
+ "when used inside of a complex property": {
+ "with correct value(s)": {
+ topic: function () {
+ prompt.get([grab('animal'), grab('sound')], this.callback);
+ helpers.stdin.writeSequence(['dog\n', 'woof\n']);
+ },
+ "should respond with the values entered": function (err, result) {
+ assert.isTrue(!err);
+ assert.equal(result.animal, 'dog');
+ assert.equal(result.sound, 'woof');
+ assert.equal(prompt.history('nothing'), null);
+ assert.deepEqual(prompt.history('animal'), { property: 'animal', value: 'dog' });
+ }
+ },
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "the history() method": {
+ "when used inside of a complex property": {
+ "with an incorrect value": {
+ topic: function () {
+ prompt.get([grab('animal'), grab('sound')], function () {});
+ prompt.once('invalid', this.callback.bind(null, null));
+ helpers.stdin.writeSequence(['dog\n', 'meow\n']);
+ },
+ "should prompt for the error": function (ign, property, line) {
+ assert.equal(property.path.join(''), 'sound');
+ assert.equal(line, 'meow');
+ }
+ }
+ }
+ }
+ }
+}).addBatch({
+ "when using prompt": {
+ "the get() method": {
+ topic: function () {
+ prompt.override = { xyz: 468, abc: 123 }
+ prompt.get(['xyz', 'abc'], this.callback);
+ },
+ "should respond with overrides": function (err, results) {
+ assert.isNull(err);
+ assert.deepEqual(results, { xyz: 468, abc: 123 });
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "with fancy properties": {
+ "the get() method": {
+ topic: function () {
+ prompt.override = { UVW: 5423, DEF: 64235 }
+ prompt.get({
+ properties: {
+ 'UVW': {
+ description: 'a custom message',
+ default: 6
+ },
+ 'DEF': {
+ description: 'a custom message',
+ default: 6
+ }
+ }
+ }, this.callback);
+ },
+ "should respond with overrides": function (err, results) {
+ assert.isNull(err);
+ assert.deepEqual(results, { UVW: 5423, DEF: 64235 });
+ }
+ }
+ }
+ }
+}).addBatch({
+ "When using prompt": {
+ "with a type and a description property": {
+ "the get() method": {
+ topic: function () {
+ var that = this;
+ helpers.stdout.once('data', function (msg) {
+ that.msg = msg;
+ });
+
+ prompt.get({
+ name: 'test',
+ type: 'number',
+ description: 'Please input a number'
+ }, this.callback);
+ helpers.stdin.writeNextTick('42\n');
+ },
+ "should prompt to stdout and respond with the value": function (err, result) {
+ assert.isNull(err);
+ assert.include(result, 'test');
+ assert.equal(result['test'], '42');
+ assert.isTrue(this.msg.indexOf('Please input a number') !== -1);
+ }
+ },
+ }
+ }
+ })
+.addBatch(
+ macros.shouldConfirm({
+ messages: ['with a string message'],
+ prop: 'test',
+ response: 'Y'
+ })
+).addBatch(
+ macros.shouldConfirm({
+ messages: ['with an empty string and default yes'],
+ prop: 'test',
+ response: ''
+ }, {
+ default: 'yes'
+ })
+).addBatch(
+ macros.shouldNotConfirm({
+ messages: ['with a string message'],
+ prop: 'test',
+ response: 'N'
+ })
+).addBatch(
+ macros.shouldConfirm({
+ messages: ['with a string message'],
+ prop: 'test',
+ response: 'YES'
+ })
+).addBatch(
+ macros.shouldNotConfirm({
+ messages: ['with a string message'],
+ prop: 'test',
+ response: 'NO'
+ })
+).addBatch(
+ macros.shouldConfirm({
+ messages: ['with a string message'],
+ prop: 'test',
+ response: 'T'
+ })
+).addBatch(
+ macros.shouldNotConfirm({
+ messages: ['with a string message'],
+ prop: 'test',
+ response: 'F'
+ })
+).addBatch(
+ macros.shouldConfirm({
+ messages: ['with a string message'],
+ prop: 'test',
+ response: 'TRUE'
+ })
+).addBatch(
+ macros.shouldNotConfirm({
+ messages: ['with a string message'],
+ prop: 'test',
+ response: 'FALSE'
+ })
+).addBatch(
+ macros.shouldConfirm({
+ messages: ['with an object', 'and description set'],
+ prop: { description: 'a custom message' },
+ response: 'Y'
+ })
+).addBatch(
+ macros.shouldConfirm({
+ messages: ['with an object', 'and they forgot the description'],
+ prop: { description: 'a custom message' },
+ response: 'Y'
+ })
+).addBatch(
+ macros.shouldConfirm({
+ messages: ['with an object', 'and custom validators'],
+ prop: {
+ description: 'node or jitsu?',
+ pattern: /^(node|jitsu)/i,
+ yes: /^node/i
+ },
+ response: 'node'
+ })
+).addBatch(
+ macros.shouldNotConfirm({
+ messages: ['with an object', 'and custom validators'],
+ prop: {
+ description: 'node or jitsu?',
+ pattern: /^(node|jitsu)/i,
+ yes: /^node/i
+ },
+ response: 'jitsu'
+ })
+).addBatch(
+ macros.shouldConfirm({
+ messages: ['with multiple strings'],
+ prop: ["test", "test2", "test3"],
+ response: ['Y\n', 'y\n', 'YES\n']
+ })
+).addBatch(
+ macros.shouldNotConfirm({
+ messages: ['with multiple strings'],
+ prop: ["test", "test2", "test3"],
+ response: ['Y\n', 'N\n', 'YES\n']
+ })
+).addBatch(
+ macros.shouldNotConfirm({
+ messages: ['with multiple strings'],
+ prop: ["test", "test2", "test3"],
+ response: ['n\n', 'NO\n', 'N\n']
+ })
+).addBatch(
+ macros.shouldConfirm({
+ messages: ['with multiple objects'],
+ prop: [
+ { message: "test" },
+ { message: "test2" }
+ ],
+ response: ['y\n', 'y\n']
+ })
+).addBatch(
+ macros.shouldNotConfirm({
+ messages: ['with multiple objects'],
+ prop: [
+ { message: "test" },
+ { message: "test2" }
+ ],
+ response: ['n\n', 'n\n']
+ })
+).addBatch(
+ macros.shouldNotConfirm({
+ messages: ['with multiple objects'],
+ prop: [
+ { message: "test" },
+ { message: "test2" }
+ ],
+ response: ['n\n', 'y\n']
+ })
+).export(module);