Skip to content

Commit

Permalink
Memserver params and passthrough tests moved to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Feb 1, 2020
1 parent d46e841 commit beee9b5
Show file tree
Hide file tree
Showing 4 changed files with 1,044 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/pretender-hacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ window.Pretender.prototype.handleRequest = function(request) {
headers,
pretender.prepareBody(
JSON.stringify({
error: `[MemServer] ${verb} ${path} route handler did not return anything to respond to the request!`
error: `[Memserver] ${verb} ${path} route handler did not return anything to respond to the request!`
}),
headers
)
Expand Down Expand Up @@ -183,7 +183,7 @@ function getDefaultRouteHandler(verb, path) {
if (!ResourceModel) {
throw new Error(
chalk.red(
`[MemServer] ${verb} ${path} route handler cannot be generated automatically: ${classify(
`[Memserver] ${verb} ${path} route handler cannot be generated automatically: ${classify(
resourceName
)} is not on your window.${classify(
resourceName
Expand Down
12 changes: 6 additions & 6 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const DEFAULT_PASSTHROUGHS = [
window.FakeXMLHttpRequest = FakeXMLHttpRequest;
window.RouteRecognizer = RouteRecognizer;

// MemServer.{"Server", "shutdown"}
export default class MemServer {
// Memserver.{"Server", "shutdown"}
export default class Memserver {
constructor(options = { logging: true, initializer: () => {}, routes: () => {} }) {
const initializer = options.initializer || function() {}; // fixtures could be loaded here
const routes = options.routes || function() {};
Expand All @@ -41,13 +41,13 @@ function startPretender(routes, options) {

let pretender = new window.Pretender(
function() {
const MemServer = chalk.cyan("[MemServer]");
const Memserver = chalk.cyan("[Memserver]");

if (options.logging) {
this.handledRequest = function(verb, path, request) {
const method = verb.toUpperCase();

console.log(MemServer, colorStatusCode(request.status), method, request.url);
console.log(Memserver, colorStatusCode(request.status), method, request.url);

if (["POST", "PUT"].includes(method)) {
console.log(`${method} REQUEST BODY IS:`, request.params);
Expand All @@ -56,12 +56,12 @@ function startPretender(routes, options) {
console.log(JSON.parse(request.responseText));
};
this.passthroughRequest = function(verb, path, request) {
console.log(MemServer, chalk.yellow("[PASSTHROUGH]"), verb, request.url);
console.log(Memserver, chalk.yellow("[PASSTHROUGH]"), verb, request.url);
};
}

this.unhandledRequest = function(verb, path, request) {
console.log(MemServer, chalk.red("[UNHANDLED REQUEST]"), verb, path);
console.log(Memserver, chalk.red("[UNHANDLED REQUEST]"), verb, path);
console.log(chalk.red("UNHANDLED REQUEST WAS:\n"), request);
console.log(request);
};
Expand Down
Loading

0 comments on commit beee9b5

Please sign in to comment.