Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Fix issue where toolbox successResponses is stripped #265

Merged
merged 3 commits into from
Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions lib/sw-precache.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ function stringifyToolboxOptions(options) {
var str = JSON.stringify(options);
if (options.origin instanceof RegExp) {
str = str.replace(/("origin":)\{\}/, '$1' + options.origin);
} else if (options.successResponses instanceof RegExp) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be just a standalone if (...) rather than an else if (...), since someone might set both options.origin and options.successResponses to RegExps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. fixed.

str = str.replace(/("successResponses":)\{\}/,
'$1' + options.successResponses);
}
return str;
}
Expand Down
11 changes: 11 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,17 @@ describe('generateRuntimeCaching', function() {
}]);
assert.equal(code, '\ntoolbox.router.get("/*", toolbox.testHandler, {"origin":"http://www.example.com"});');
});

it('should handle successResponses regex', function() {
var code = generateRuntimeCaching([{
urlPattern: '/*',
handler: 'testHandler',
options: {
successResponses: /^200$/
}
}]);
assert.equal(code, '\ntoolbox.router.get("/*", toolbox.testHandler, {"successResponses":/^200$/});');
});
});

describe('cleanResponse', function() {
Expand Down