Skip to content
Merged
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
12 changes: 8 additions & 4 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ exports.Server = function Server(bsClient, workers, config, callback) {
}
};

var getTestingFrameworkMatcher = function() {
var tag_name = (config['test_framework'] === 'mocha') ? 'head' : 'body';
return new RegExp('(.*)<\/' + tag_name + '>'); ///(.*)<\/body>/;
};

var writeResponse = function(err, data) {

if (err) {
Expand All @@ -197,8 +202,7 @@ exports.Server = function Server(bsClient, workers, config, callback) {
response.writeHead(200, {
'Content-Type': 'text/html; charset=utf-8'
});
var tag_name = (config['test_framework'] === 'mocha') ? 'head' : 'body';
var matcher = new RegExp('(.*)<\/' + tag_name + '>'); ///(.*)<\/body>/;
var matcher = getTestingFrameworkMatcher();
var patch = getReporterPatch();
data = data.replace(matcher, patch);

Expand All @@ -210,7 +214,7 @@ exports.Server = function Server(bsClient, workers, config, callback) {
var mimeType = mime.lookup(filename);
var finalData = data;
if (mimeType === 'text/html') {
var matcher = /(.*)<\/head>/;
var matcher = getTestingFrameworkMatcher();
var patch = getReporterPatch();
finalData = data.replace(matcher, patch);
headers['content-length'] = finalData.length;
Expand Down Expand Up @@ -245,7 +249,7 @@ exports.Server = function Server(bsClient, workers, config, callback) {
}
});
} else {
patchResponse(responseData, headers, function (data, headers) {
patchResponse(responseData && responseData.toString(), headers, function (data, headers) {
callback && callback(data, headers);
});
}
Expand Down