Skip to content

Commit fb33f8e

Browse files
authored
Merge pull request #190 from cwisecarver/bugfix/fix-matcher-logic
Use conditional tag matching logic everywhere
2 parents 52b23f0 + c584dd5 commit fb33f8e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Diff for: lib/server.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ exports.Server = function Server(bsClient, workers, config, callback) {
187187
}
188188
};
189189

190+
var getTestingFrameworkMatcher = function() {
191+
var tag_name = (config['test_framework'] === 'mocha') ? 'head' : 'body';
192+
return new RegExp('(.*)<\/' + tag_name + '>'); ///(.*)<\/body>/;
193+
};
194+
190195
var writeResponse = function(err, data) {
191196

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

@@ -210,7 +214,7 @@ exports.Server = function Server(bsClient, workers, config, callback) {
210214
var mimeType = mime.lookup(filename);
211215
var finalData = data;
212216
if (mimeType === 'text/html') {
213-
var matcher = /(.*)<\/head>/;
217+
var matcher = getTestingFrameworkMatcher();
214218
var patch = getReporterPatch();
215219
finalData = data.replace(matcher, patch);
216220
headers['content-length'] = finalData.length;
@@ -245,7 +249,7 @@ exports.Server = function Server(bsClient, workers, config, callback) {
245249
}
246250
});
247251
} else {
248-
patchResponse(responseData, headers, function (data, headers) {
252+
patchResponse(responseData && responseData.toString(), headers, function (data, headers) {
249253
callback && callback(data, headers);
250254
});
251255
}

0 commit comments

Comments
 (0)