Skip to content
Myr

remove messy/broken test

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent e1466b0 · Browse files · 1 file+0 added−123 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+0 added−123 removed

  • tests:+0 added−123 removed

1 file+0 added−123 removed

deleted:test/test.prompt.js-123 removed
1/**2 * Module dependencies.3 */45var events = require('events')6 , program = require('../')7 , should = require('should');89// TODO: this is all super messy... rewrite1011//mock stdin on process12var stdin = new events.EventEmitter();13stdin.setEncoding = stdin.resume = function() {};14stdin.write = function(data) { stdin.emit('data', data); };15process.__defineGetter__('stdin', function() { return stdin });1617//mock stdout on process18var stdout = new events.EventEmitter();19stdout.write = function(data) { this.emit('data', data) };20stdout.expect = function(expected, fn) {21 var actual = '';22 this.once('data', function(data){ actual = data; });23 fn();24 actual.should.equal(expected);25}26//var realOut = process.stdout;27process.__defineGetter__('stdout', function() { return stdout });2829var count = 0;30var test = function(expected) {31 count++;32 return function(actual) {33 count--;34 if(expected instanceof Date) {35 //need something better :(36 //using `new Date(date.toString())` round trip37 //loosing some precision for .getTime()38 actual.should.be.an.instanceof(Date);39 } else {40 actual.should.equal(expected);41 }42 }43}4445process.on('exit', function(){46 count.should.equal(0);47})4849/* Single Line String Prompt Tests */50var prompt = 'hello '51 , expected = 'world';5253// simple single line string 54stdout.expect(prompt, function(){55 program.prompt(prompt, test(expected));56 stdin.write(expected); 57})58// with trim59stdout.expect(prompt, function(){60 program.prompt(prompt, test(expected));61 stdin.write(' ' + expected + ' '); 62})63// newline64stdout.expect(prompt, function(){65 program.prompt(prompt, test(''));66 stdin.write('\n'); 67})6869/* Multiline Tests*/70var prompt = 'A multiline';71stdout.expect(prompt + '\n', function() {72 program.prompt(prompt, test('hello world\n and what a world\nit could be'));73 stdin.write('hello world\n');74 stdin.write(' and what a world\n');75 stdin.write('it could be\n');76 stdin.write('\n');77})7879/* Date Prompt Tests */80var prompt = 'A date '81 , expected = new Date();82 83// simple date84stdout.expect(prompt, function(){85 program.prompt(prompt, Date, test(expected));86 stdin.write(expected.toString()); 87})88// not a date twice89stdout.expect(prompt, function() {90 program.prompt(prompt, Date, test(expected));91 92 stdout.expect(prompt + '(must be a date) ', function() {93 stdin.write('blue'); 94 })95 stdout.expect(prompt + '(must be a date) ', function() {96 stdin.write('blue'); 97 })98 stdin.write(expected.toString()); 99})100101/* Number Prompt Tests*/102var prompt = 'A number '103 , expected = 12;104 105//simple number106stdout.expect(prompt, function(){107 program.prompt(prompt, Number, test(expected));108 stdin.write(expected.toString()); 109})110111// not a number twice112stdout.expect(prompt, function() {113 program.prompt(prompt, Number, test(expected));114 115 stdout.expect(prompt + '(must be a number) ', function() {116 stdin.write('blue'); 117 })118 stdout.expect(prompt + '(must be a number) ', function() {119 stdin.write('blue'); 120 })121 stdin.write(expected.toString()); 122})123