Skip to content
Browse files

Tests for throbber

  • Loading branch information...
1 parent e9e1c22 commit ec7b04ae3c2f13c25ae83ffee8960b51186fc1aa @medikoo committed Aug 8, 2011
Showing with 113 additions and 0 deletions.
  1. +14 −0 test/__playground/throbber.formatted.js
  2. +13 −0 test/__playground/throbber.js
  3. +86 −0 test/throbber.js
View
14 test/__playground/throbber.formatted.js
@@ -0,0 +1,14 @@
+#!/usr/bin/env node
+
+'use strict';
+
+var throbber = require('../../lib/throbber')
+ , interval = require('clock/lib/interval')
+ , format = require('../../lib/index').red;
+
+var i = interval(100, true);
+
+throbber(i, format);
+process.stdout.write('START');
+
+setTimeout(i.stop.bind(i), 500);
View
13 test/__playground/throbber.js
@@ -0,0 +1,13 @@
+#!/usr/bin/env node
+
+'use strict';
+
+var throbber = require('../../lib/throbber')
+ , interval = require('clock/lib/interval');
+
+var i = interval(100, true);
+
+throbber(i);
+process.stdout.write('START');
+
+setTimeout(i.stop.bind(i), 500);
View
86 test/throbber.js
@@ -0,0 +1,86 @@
+'use strict';
+
+var spawn = require('child_process').spawn
+ , pg = __dirname + '/__playground'
+ , initChars = '-\\|/';
+
+module.exports = {
+ "": function (a, d) {
+ var t = spawn(pg + '/throbber.js')
+ , out = ""
+ , err = ""
+ , chars = initChars
+ , i, wrote = false
+ , watch = function () {
+ setTimeout(function () {
+ i = setInterval(function () {
+ var expected = "";
+ if (wrote) {
+ expected += '\u0008';
+ }
+ wrote = true;
+ expected += chars[0];
+ chars = chars.slice(1);
+ a(out, expected);
+ out = "";
+ }, 100);
+ }, 50);
+ },
+ initialized = false;
+
+ t.stdout.on('data', function (data) {
+ if (!initialized) {
+ initialized = true;
+ watch();
+ } else {
+ out += data;
+ }
+ });
+ t.stderr.on('data', function (data) {
+ err += data;
+ });
+ t.on('exit', function () {
+ clearInterval(i);
+ a(err, "", "No stderr output"); d();
+ });
+ },
+ "Formatted": function (a, d) {
+ var t = spawn(pg + '/throbber.formatted.js')
+ , out = ""
+ , err = ""
+ , chars = initChars
+ , i, wrote = false
+ , watch = function () {
+ setTimeout(function () {
+ i = setInterval(function () {
+ var expected = "";
+ if (wrote) {
+ expected += '\u0008';
+ }
+ wrote = true;
+ expected += '\x1b[31m' + chars[0] + '\x1b[39m';
+ chars = chars.slice(1);
+ a(out, expected);
+ out = "";
+ }, 100);
+ }, 50);
+ },
+ initialized = false;
+
+ t.stdout.on('data', function (data) {
+ if (!initialized) {
+ initialized = true;
+ watch();
+ } else {
+ out += data;
+ }
+ });
+ t.stderr.on('data', function (data) {
+ err += data;
+ });
+ t.on('exit', function () {
+ clearInterval(i);
+ a(err, "", "No stderr output"); d();
+ });
+ }
+};

0 comments on commit ec7b04a

Please sign in to comment.
Something went wrong with that request. Please try again.