-
Notifications
You must be signed in to change notification settings - Fork 0
/
visitor.js
114 lines (105 loc) · 3.72 KB
/
visitor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
var vows = require("vows");
var assert = require("assert");
var server = require("../lib/server");
var visitor = require("../lib/visitor");
var Browser = require("../lib/browsers").Browser;
var macros = require("../lib/macros"),
request = macros.request,
httpify = macros.httpify;
// debugging
var ui = require("../lib/ui");
var signal = require("../lib/signal");
ui.verbose(1); // show debug-level logs
signal.listen(); // graceful shutdown on SIGINT
function requestTest (fixture, requestOnly) {
var suite = {
topic : request(
200,
"/tests/add",
{ tests : [ __dirname + "/" + fixture + ".html" ] },
"PUT"
),
"the test id is returned" : function (id) {
assert.isString(id);
}
};
if ( // FIXME: Kludge for tests that just shouldn't stop the runner
requestOnly !== true
) suite["and the status is requested"] = {
topic : request(200, function (id) {
return "/status/" + id;
}),
"the test data is returned" : function (results) {
assert.isObject(results);
assert.include(results, "passed");
assert.include(results, "failed");
assert.include(results, "name");
assert.include(results, "total");
},
"the suite passed" : function (result) {
assert.ok(result.passed);
assert.equal(result.failed, 0);
}
};
return suite;
}
function requestRunner (transport, browser) {
return {
topic : function (port) {
var vow = this;
var tests = server.getEmitterForPort(port);
var cb = function (event, listener) {
if ("add" !== event) return;
vow.callback(null, listener);
tests.removeListener("newListener", cb);
};
tests.on("newListener", cb);
visitor.visit(
[ browser || Browser.canonical() ],
["http://localhost:" + port + "/?timeout=3000&transport=" + transport]
);
},
"the server listens to the test add event" : function (listener) {
assert.isFunction(listener);
},
// Bad tests
// TODO: Yeti should report errors in its report for these conditions
// Right now, we only verify the test runner skips them okay
"and a test with SyntaxError is added" : requestTest("fixture-syntax-error", true),
"and a missing test is added" : requestTest("fixture-404", true),
// Normal tests
"and a test is added" : requestTest("fixture"),
"and a YUI 2.x test is added" : requestTest("fixture-yui2"),
"and a test with spaces is added" : requestTest("fixture with spaces/fixture again")
};
}
vows.describe("Visitors").addBatch({
"A Yeti server visited by the canonical browser" : {
"for the default test runner": {
topic : httpify(),
"was requested" : requestRunner("")
}
},
"A Yeti server visited by Safari" : {
/* "for the XHR test runner": {
topic : httpify(),
"was requested" : requestRunner("xhr", "Safari")
}, FIXME */
"for the EventSource test runner": {
topic : httpify(),
"was requested" : requestRunner("eventsource", "Safari")
}
},
"A Yeti server visited by Chrome" : {
"for the default test runner": {
topic : httpify(),
"was requested" : requestRunner("", "chrome")
}
},
"A Yeti server visited by Opera" : {
"for the default test runner": {
topic : httpify(),
"was requested" : requestRunner("", "opera")
}
}
}).export(module);