namshi / mockserver

Mock your backends in a matter of seconds. HTTP is King.
351 stars 89 forks source link

Path after wildcard not recognized #63

Open spooler opened 5 years ago

spooler commented 5 years ago

mockserver 3.0.0

file:

foo/__/bar/GET.mock

request:

/foo/1/bar

expected server output:

Reading from foo/1/bar/GET.mock file: Not matched
Reading from foo/__/bar/GET.mock file: Matched

got:

Reading from foo/1/bar/GET.mock file: Not matched
Reading from foo/__/GET.mock file: Not matched
derit commented 5 years ago

same issue on osx

benaud12 commented 5 years ago

Was having this same issue and the problem for me was in how I declared the path to my mocks.

In short, I was setting up the mockserver like this:

mockserver("./path/to/mocks")

and the problem was caused by the leading ./, so just removing that solved the problem for me:

mockserver("path/to/mocks")

The reason this breaks the wildcard matching is because it strips off the base directory from the wildcard filepaths (https://github.com/namshi/mockserver/blob/200ede1a6e3de9562c3f9caaea20a9203e907e0a/mockserver.js#L175), but it does this by calculating the number of path segments in the base directory and removing them from the wildcard filepaths. However if your base directory includes the leading ./ it will be counted as an additional segment and therefore no matches will be found.

Don't know if this is the reason for the issues above but just putting it here for anyone else who comes across the same problem I did.