Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix moduleless QUnit output #79

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ task("install", function () {

desc("Run all of Yeti's functional tests");
task("test-functional", function () {
var args = ["--spec"];
var args = ["--isolate", "--spec"];
bin("vows", args.concat(getTestFiles("functional")), complete);
}, {
async: true
});

desc("Run all of Yeti's unit tests");
task("test-unit", function () {
var args = [];
var args = ["--isolate"];
if (process.env.TRAVIS) {
args.push("--spec");
}
Expand Down
73 changes: 43 additions & 30 deletions lib/hub/view/public/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ window.$yetify = function (options) {
data = {},
tests = {},
count = 1,
curModuleName = "",
curTestName;

function complete(results) {
Expand Down Expand Up @@ -105,7 +106,19 @@ window.$yetify = function (options) {
return result.message || "";
}

qunit.log = function (test) {
function formatTests() {
var i, out = {};
for (i in tests) {
out[tests[i].name] = {
result: tests[i].result,
message: message(tests[i]),
name: tests[i].name
};
}
return out;
}

qunit.log(function (test) {
tests["test" + count] = {
message: test.message,
result: (test.result) ? test.result : "fail",
Expand All @@ -115,46 +128,46 @@ window.$yetify = function (options) {
};

count = count + 1;
};
});

qunit.moduleStart = function (test) {
qunit.testStart(function (test) {
curTestName = test.name;
};
});

qunit.moduleDone = function (test) {
var testName = curTestName,
i;
qunit.testDone(function (test) {
var module = formatTests(),
name = curModuleName + curTestName;

data[testName] = {
name: testName,
passed: test.passed,
failed: test.failed,
total: test.total
};
module.name = name;
module.passed = test.passed;
module.failed = test.failed;
module.total = test.total;

for (i in tests) {
data[testName][tests[i].name] = {
result: tests[i].result,
message: message(tests[i]),
name: tests[i].name
};
}
data[name] = module;

tests = {};
count = 1;
};
});

qunit.done = function (tests) {
var results = data;
qunit.moduleStart(function (test) {
curModuleName = test.name + ": ";
});

results.passed = tests.passed;
results.failed = tests.failed;
results.total = tests.total;
results.duration = tests.runtime;
results.name = document.title;
qunit.moduleDone(function (test) {
curModuleName = "";
});

complete(results);
};
qunit.done(function (tests) {
data = Y.merge(formatTests(), data);

data.passed = tests.passed;
data.failed = tests.failed;
data.total = tests.total;
data.duration = tests.runtime;
data.name = document.title;

complete(data);
});

qunit.start();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@
"jake": ">=0.2.35",
"rimraf": ">=2.0.1",
"walkdir": ">=0.0.5",
"mock-utf8-stream": ">=0.1.0"
"mock-utf8-stream": ">=0.1.1"
}
}
14 changes: 14 additions & 0 deletions test/functional/fixture/qunit-module.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<head>
<title>Yeti QUnit Module Test</title>
<link rel="stylesheet" href="../../../dep/dev/qunit.css">
</head>
<div id="qunit"></div>
<script src="../../../dep/dev/qunit.js"></script>
<script>
QUnit.config.autostart = false;
module("Yeti Example Module");
test("hello qunit", function () {
ok(1 == 1, "Yay!");
});
</script>
1 change: 1 addition & 0 deletions test/functional/fixture/qunit.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<div id="qunit"></div>
<script src="../../../dep/dev/qunit.js"></script>
<script>
QUnit.config.autostart = false;
test("hello qunit", function () {
ok(1 == 1, "Yay!");
});
Expand Down
133 changes: 133 additions & 0 deletions test/functional/junit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
"use strict";

var vows = require("vows");
var assert = require("assert");

var portfinder = require("portfinder");

var hub = require("../lib/hub");
var cliTopic = require("../lib/cli");

var EventEmitter2 = require("../../lib/event-emitter");

vows.describe("Yeti JUnit Functional").addBatch({
"A Yeti CLI with moduleless QUnit with JUnit output": {
topic: cliTopic(function (topic) {
var vow = this;

topic.stderr.startCapture();

portfinder.getPort(function (err, port) {
if (err) {
vow.callback(err);
return;
}

port = String(port);
topic.port = port;

topic.stderr.expect("When ready", function () {
topic.stderr.stopCapture();
topic.output = topic.stderr.capturedData;
vow.callback(null, topic);
});

topic.stdout.startCapture();

topic.fe.route([
"node",
"cli.js",
"--junit",
"-p", port,
__dirname + "/fixture/qunit.html"
]);
});
}),
"is ok": function (topic) {
assert.isUndefined(topic.stack);
},
"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");
},
"prompts on the writableStream": function (topic) {
assert.include(topic.output, "When ready, press Enter");
},
"a browser": hub.phantomContext({
"visits Yeti": {
topic: function (browser, topic) {
var vow = this;

topic.browser = browser;

topic.stderr.expect("Agent connected", function (err, capturedData) {
topic.output = capturedData;
vow.callback(null, topic);
});

function onPageOpen(err, status) {
if (err) {
vow.callback(err);
}
}

browser.createPage(function (err, page) {
page.open("http://localhost:" + topic.port, onPageOpen);
});
},
"is ok": function (topic) {
assert.isUndefined(topic.stack);
},
"the stderr output contains the User-Agent": function (topic) {
assert.include(topic.output, "PhantomJS");
},
"when Enter is pressed": {
topic: function (topic) {
var vow = this;

topic.stderr.expect("pass", function (err, capturedData) {
topic.output = capturedData;
vow.callback(null, topic);
});

topic.stdin.write("\n"); // Enter
},
"is ok": function (topic) {
assert.isUndefined(topic.stack);
},
"the stderr output contains the test summary": function (topic) {
// FIXME, tests should be test
assert.include(topic.output, "1 tests passed");
},
"the stderr output contains Agent complete": function (topic) {
assert.include(topic.output, "Agent complete");
},
"should exit": {
topic: function (topic) {
var vow = this;
topic.emitter.once("exit", function (code) {
topic.stdout.stopCapture();
topic.exitCode = code;
vow.callback(null, topic);
});
},
"with status code 0": function (topic) {
assert.strictEqual(topic.exitCode, 0);
},
"the stdout output contains JUnit XML": function (topic) {
assert.ok(topic.stdout.capturedData.indexOf("<?xml") === 0,
"Expected XML prolog in: " + topic.stdout.capturedData);
assert.include(topic.stdout.capturedData, "</testsuites>");
},
"the stdout output contains a JUnit testcase": function (topic) {
// https://github.com/yui/yeti/issues/78
assert.include(topic.stdout.capturedData, '<testcase name="hello qunit: test1"');
}
}
}
}
}) // phantomContext
}
}).export(module);
35 changes: 35 additions & 0 deletions test/lib/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict";

var streams = require("mock-utf8-stream");

var EventEmitter2 = require("../../lib/event-emitter");
var CLI = require("../../lib/cli").CLI;

module.exports = function cliTopic(fn) {
return function () {
var vow = this,
topic,
emitter = new EventEmitter2();

topic = {
fe: null,
stdin: new streams.MockReadableStream(),
stdout: new streams.MockWritableStream(),
stderr: new streams.MockWritableStream(),
emitter: emitter
};

function mockExit(code) {
emitter.emit("exit", code);
}

topic.fe = new CLI({
stdin: topic.stdin,
stdout: topic.stdout,
stderr: topic.stderr,
exitFn: mockExit
});

return fn.call(vow, topic);
};
};