Debug mock server scripts
Our mock server scripts are runing in nodejs environment, which allows for easy debugging using the console.log()
function. These logs will be associated with each corresponding HTTP request and can be reviewed in the request logs for further analysis.
As an example, adding console logs to the route callback functions can be done like this:
// use console.log(...) to print logs to console for debugging.
// here is the example:
mock.define("/users", "POST", function(req, res) {
console.log("hello world, this is a debug message");
console.log(12345);
console.log("hello", "world", true);
console.log({hello:"hello", world:"world"});
console.log(req.body);
var users = [
{ username: "hello", email: "hello@gmail.com" },
{ username: "world", email: "world@gmail.com" }
]
console.log(users);
res.status(200).json(users);
});
You will be able to view the console logs in the detailed log for each request: