Closed andrewluetgers closed 2 years ago
Hi @andrewluetgers, thanks for your PR!
I don't think we're going to make this change, for now. However I would like to give you feedback anyway:
Sorry for the low quality PR.
The PR includes a bunch of changes which are unrelated to your proposed change
Its clear there are two things in here that I should have submitted separately.
1: Custom file names motivation - now I can easily find a file based on the request if I want to edit it, also helps in understanding what mocks I have in place. Of course there are any number of naming schemes one could use which includes adding a random value to eliminate the risk duplicates if one chooses.
2: prettified JSON motivation - for easy diffing and manual editing of JSON responses that are normally sent in a single line.
what happens when we have two files with the same name?
The file gets overwritten but you would have to commit a change and could view the diff and your tests may fail so the issue will rear its head quickly if it is an issue. You would then change the naming scheme and/or your tests.
So our front-end Puppeteer testing process looks like this:
I'd like this as well (none of the libraries I've found seem to support it!):
A good example of this problem is with OAUTH APIs:
The Authorization
header changes often (in my case, hourly before it needs to be renewed/created).
I'd want to save a fixture as api.example.com/path/to/resource/{username}.{hash}.txt
.
hash
is the 5-character MD5 of the request properties (excluding Authorization
since it's not idempotent)
username
differs for each test suite.
@ericclemmons the way I implemented this you provide a function that returns a file name given the request object so this could be easily handled. However I believe nested folder paths would need more coding to support. In my case I just wanted a basic request path as the file name.
function mockName(method, url) {
return (method + "|" + url).replace(/\//g, "_").replace("?", "__").replace(/&/g, "--");
}
Replay.uidFn = req => mockName(req.method, req.url.host+ req.url.path) + ".txt";
this should be closed IMHO in favor of https://github.com/assaf/node-replay/pull/162
allows user to provide a uidFn option to define how to name mock files.