-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load config as a JS file only. Allow dynamic logic/options #34
Comments
Do you think the e.g. // jambox config
module.exports = {
stub: {
// "dynamic" stub:
'**/log': (request) => {
return Promise.resolve({ ok: true });
},
// "static" stub:
'**/*.png': {
status: 200,
preferNetwork: true,
file: path.join(__dirname, '.jambox', 'placeholder.png'),
},
}
} Or: // jambox config
module.exports = {
stub: request => {
if (matches(request.url, '**/log')) {
return Promise.resolve({ ok: true });
} else if (matches(request.url, '**/.png')) {
return {
status: 200,
preferNetwork: true,
file: path.join(__dirname, '.jambox', 'placeholder.png'),
};
}
return Promise.reject({notStubbed: true});
}
} |
Strong preference for the latter. Though to be fair, both versions could be allowed. One function for all stubs supports every possible scenario so it would at least make sense as the first take. |
Would it be worth exposing a "matches" like function also to the function (similar to example: module.exports = {
stub(request, { defaultMatch }) {
if (defaultMatch(request.url, '**/log')) {
//
}
}
} |
Yeah sure that can be done. Is it worth it? I don't know, it's not difficult to provide it, but its also might not end-up being very useful |
Fully switch over to using the config as a loaded js module. Add some dynamic option support, the two main features are listed below.
cache.hashFunction(request, defaultHashFunction) -> Promise<hash>
Let the user define a custom hash function. Very useful for certain type of requests. The resulting
hash
is used throughout for identifying the cached record (like filenames, ids). A user could for example always return the same hash value if desired for certain type of requests which maintain dynamic parameters but don't influence the response. A customhash
value can also make artifacts easily identifiable.The hash function will always be preferred over
defaultHashFunction
.stub: (request) -> Promise<response>
Let the user define custom stubs via a function. The glob matching might be too difficult.
The text was updated successfully, but these errors were encountered: