/
echo.js
62 lines (58 loc) · 1.87 KB
/
echo.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
/**
* @fileOverview
* Batches for testing the Echo example application.
*/
var assert = require("assert");
var Thywill = require("thywill");
var Message = Thywill.getBaseClass("Message");
var tools = require("./tools");
/**
* Add general tests for the Echo application to the suite.
*/
exports.general = function (suite) {
var instanceIndex = 0;
var applicationIndex = 0;
// The initial batches load the application page and then connect via
// Socket.IO. The matches are checked against the page contents. Here
// we're looking at the templates that should be included.
var pageMatches = [
"<button>{{buttonText}}</button>",
'<div class="echoed-message">{{data}}</div>'
];
tools.workAlready.addInitialBatches(suite, instanceIndex, pageMatches);
// A check to see if sending works.
suite.addBatch({
"Send message without waiting on response": {
topic: function () {
var message = new Message("pre-test");
suite.clients[instanceIndex].action({
type: "emit",
args: ["fromClient", suite.thywills[instanceIndex].applications[applicationIndex].id, message]
}, this.callback);
},
"message sent": function (error) {
assert.isUndefined(error);
}
}
});
// A delay to be sure that the Echo response to the last message is
// done with before testing for the next one.
suite.addBatch({
"Delay": {
topic: function () {
setTimeout(this.callback, 200);
},
"delayed": function () {}
}
});
// Test the echoing functionality.
var sendMessage = "test";
var responseMessage = "test";
tools.workAlready.addSendAndAwaitResponseBatch("Echo message and response", suite, {
applicationIndex: applicationIndex,
sendInstanceIndex: instanceIndex,
responseInstanceIndex: instanceIndex,
sendMessage: sendMessage,
responseMessage: responseMessage
});
};