express-fixturer
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -1,2 +0,1 @@ | ||
/// <reference types="express" /> | ||
import { Request, Response, NextFunction } from 'express'; | ||
@@ -8,4 +7,5 @@ export interface Parameters { | ||
hashFn?: (req: Request) => object; | ||
logging: 'quiet' | 'verbose'; | ||
} | ||
declare const middlewareFactory: (opts: Parameters) => (req: Request, res: Response, next: NextFunction) => void; | ||
export default middlewareFactory; |
@@ -22,2 +22,3 @@ "use strict"; | ||
fixtureRoutes: false, | ||
logging: 'verbose', | ||
}; | ||
@@ -37,3 +38,5 @@ var getReqPath = function (req, params) { | ||
res.send = function (payload) { | ||
console.log("Writing fixture for route " + req.path + ", file: " + fixturePath); | ||
if (params.logging === 'verbose') { | ||
console.log("Writing fixture for route " + req.path + ", file: " + fixturePath); | ||
} | ||
fs_1.writeFileSync(fixturePath, payload); | ||
@@ -40,0 +43,0 @@ oldSend.call(res, payload); |
{ | ||
"name": "express-fixturer", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Easily manage your API fixtures", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -40,2 +40,3 @@ # Express-fixturer | ||
- hashFn (optional) `(req: express.Request) => object`: Define how to generate your hash used to identify the fixture to the right request. The default hash function will include `req.body, req.cookies, req.params, req.query and req.path` | ||
- logging (optional, default: `verbose`) `verbose | quiet`: If set to `verbose` it will log. | ||
@@ -42,0 +43,0 @@ #### Example |
@@ -14,2 +14,3 @@ import { Request, Response, NextFunction } from 'express'; | ||
hashFn?: (req: Request) => object; | ||
logging: 'quiet' | 'verbose'; | ||
} | ||
@@ -30,2 +31,3 @@ | ||
fixtureRoutes: false, | ||
logging: 'verbose', | ||
}; | ||
@@ -57,5 +59,7 @@ | ||
(res as any).send = (payload: any) => { | ||
console.log( | ||
`Writing fixture for route ${req.path}, file: ${fixturePath}` | ||
); | ||
if (params.logging === 'verbose') { | ||
console.log( | ||
`Writing fixture for route ${req.path}, file: ${fixturePath}` | ||
); | ||
} | ||
writeFileSync(fixturePath, payload); | ||
@@ -62,0 +66,0 @@ oldSend.call(res, payload); |
Sorry, the diff of this file is not supported yet
10487
165
55