Permalink
Browse files

Add test for failing command-line UI. Ref #95.

Add YETI_MOCK_DEBUG for debugging the MockWritableStream.
When set, MockWritableStream#expect prints out what it's
expecting and collecting.

This is useful for creating new tests.
  • Loading branch information...
1 parent 14c7f22 commit 08a190596116acd1b408ccf7973e3c9e9c7138ed @reid reid committed Oct 5, 2012
Showing with 83 additions and 0 deletions.
  1. +67 −0 test/cli.js
  2. +16 −0 test/lib/streams.js
View
67 test/cli.js
@@ -156,6 +156,73 @@ vows.describe("Yeti CLI").addBatch({
}
}
})
+ },
+ "A Yeti CLI with a failing file": {
+ topic: cliTopic(function (topic) {
+ topic.stderr.expect("When ready", this.callback);
+
+ topic.fe.route([
+ "node",
+ "cli.js",
+ "-p", "9012",
+ __dirname + "/fixture/query-string.html",
+ ]);
+ }),
+ "prints hub creation message on stderr": function (topic) {
+ assert.ok(topic.output.indexOf("Creating a Hub.") === 0);
+ },
+ "waits for agents to connect on stderr": function (topic) {
+ assert.include(topic.output, "Waiting for agents to connect");
+ assert.include(topic.output, "also available locally at");
+ },
+ "prompts on the writableStream": function (topic) {
+ assert.include(topic.output, "When ready, press Enter");
+ },
+ "a browser": hub.phantomContext({
+ "visits Yeti": {
+ topic: function (browser, cli) {
+ var vow = this;
+
+ expectThenCallback(vow, cli.config.stderr, "Agent connected");
+
+ function onPageOpen(err, status) {
+ if (err) {
+ vow.callback(err);
+ }
+ }
+
+ browser.createPage(function (err, page) {
+ page.open("http://localhost:9012", onPageOpen);
+ });
+ },
+ "is ok": function (topic) {
+ assert.isUndefined(topic.stack);
+ },
+ "the stderr output contains the User-Agent": function (topic) {
+ assert.include(topic.output, "Mozilla");
+ },
+ "when Enter is pressed": {
+ topic: function (connectionSnapshot, browser, cli) {
+ expectThenCallback(this, cli.config.stdout, "failed");
+
+ cli.config.stdin.write("\n"); // Enter
+ },
+ "is ok": function (topic) {
+ assert.isUndefined(topic.stack);
+ },
+ "the stderr output contains the failing test details": function (topic) {
+ assert.include(topic.output, "testMoof");
+ assert.include(topic.output, "Values should be equal.");
+ assert.include(topic.output, "Expected: moof (string)");
+ assert.include(topic.output, "Actual: ? (string)");
+ assert.include(topic.output, "1 of 1 tests failed");
+ },
+ "the stderr output contains Agent complete": function (topic) {
+ assert.include(topic.output, "Agent complete");
+ }
+ }
+ }
+ })
}
}).addBatch({
"parseArgv when given arguments": {
View
16 test/lib/streams.js
@@ -7,6 +7,8 @@
var util = require("util");
var EventEmitter2 = require("../../lib/events").EventEmitter2;
+var DEBUG = process.env.YETI_MOCK_DEBUG;
+
function makeString(data) {
if (Buffer.isBuffer(data)) {
data = data.toString("utf8");
@@ -78,6 +80,10 @@ MockReadableStream.prototype.write = WRITE;
*/
function MockWritableStream() {
EventEmitter2.call(this);
+
+ if (DEBUG) {
+ this.id = (Math.random() * 100000) | 0;
+ }
}
util.inherits(MockWritableStream, EventEmitter2);
@@ -114,13 +120,23 @@ MockWritableStream.prototype.write = WRITE;
*/
MockWritableStream.prototype.expect = function (expectedString, cb) {
var self = this,
+ what,
dataEvents = [];
+ if (DEBUG) {
+ what = "MockWritableStream<" + self.id + ">#expect:";
+ console.log(what, "Expecting:", expectedString);
+ }
+
self.on("data", function ondata(data) {
data = makeString(data);
dataEvents.push(data);
+ if (DEBUG) {
+ console.log(what, "Collecting:", data);
+ }
+
if (expectedString && data.indexOf(expectedString) !== -1) {
self.removeListener("data", ondata);
cb(null, dataEvents.join(""));

0 comments on commit 08a1905

Please sign in to comment.