Skip to content
This repository has been archived by the owner on Feb 22, 2019. It is now read-only.

Commit

Permalink
made the calculation of new responses more efficient.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Malan committed May 6, 2015
1 parent c867e74 commit 677b815
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions test-support/helpers/betamax-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
} from './fake-server';

var responses = [], strings = [];
var allResponseUrls = [];

//turning headers into js is a real pain
function parseResponseHeaders(headerStr) {
Expand All @@ -26,6 +27,9 @@ function parseResponseHeaders(headerStr) {
export default {
setup: function() {
var server = getServer();
server.responses.mapBy('url').forEach(function(response) {
allResponseUrls[response] = true;
});

//listen to incoming xhr requests
$( document ).ajaxSuccess(function( event, xhr, settings ) {
Expand All @@ -38,8 +42,9 @@ export default {
headers: parseResponseHeaders(xhr.getAllResponseHeaders())
};
//if response isn't in old or new cassettes, add it to new one
if(!responses.mapBy('url').concat(server.responses.mapBy('url')).uniq().contains(url)){
if(!allResponseUrls['url']) {
responses.push(newResponse);
allResponseUrls[newResponse.url] = true;

//ensure that if a request is added to new cassette, it
//doesn't hit the server again
Expand All @@ -56,7 +61,6 @@ export default {
},

download: function() {

//convert responses into string expected by sinon
strings.push("export default function(server) {\n\n");
if (responses.length > 0){
Expand All @@ -70,7 +74,6 @@ export default {
});

strings.push("}");

//html 5 for downloading recordings
var blob = new window.Blob(strings);
var encodedUri = window.URL.createObjectURL(blob);
Expand Down

0 comments on commit 677b815

Please sign in to comment.