forked from jakefeasel/mockbuilder
-
Notifications
You must be signed in to change notification settings - Fork 2
/
HARParser.js
32 lines (30 loc) · 1.44 KB
/
HARParser.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
define( ["handlebars", "lodash"],
function (Handlebars, _) {
return {
parse: function (testTemplate, harData, url) {
var compiledTemplate = Handlebars.compile(testTemplate);
harData.log.entries =
_(harData.log.entries)
// only care about the XHR requests
.filter(function (e) {
return _.find(e.request.headers, function (h) {
return h.name === "X-Requested-With" && h.value === "XMLHttpRequest";
});
})
.map(function (e) {
// put the response back in JSON so it will be safe to embed in the Javascript directly
e.response.content.text = JSON.stringify(e.response.content.text);
// add a flag to help with handling trailing commas
e.response.headers[e.response.headers.length-1].last = true;
e.request.url = e.request.url.replace(url, '');
if(e.response.status === 304){
e.response.status = 200;
}
return e;
})
.value();
return compiledTemplate(harData);
}
};
}
);