Comparing version 2.1.1 to 2.2.0
@@ -0,1 +1,10 @@ | ||
# 2.2.0 | ||
- Prettify recorded JSON mocks | ||
- Fix recorded mock content type in some cases | ||
## Deprecation notice | ||
- Change route params prefix from `:` to `@` to fix Windows-naming issue | ||
**Note**: old syntax with `:` still works, but mocks using this syntax will | ||
not be working on Windows filesystem. | ||
# 2.1.1 | ||
@@ -2,0 +11,0 @@ - Update documentation regarding collection recording |
@@ -77,3 +77,6 @@ const path = require('path'); | ||
const reqPath = dirComponents.concat(fileComponents).join('/'); | ||
const reqPath = dirComponents | ||
.concat(fileComponents) | ||
.join('/') | ||
.replace(/@/g, ':'); | ||
const keys = []; | ||
@@ -80,0 +83,0 @@ |
@@ -24,4 +24,13 @@ const path = require('path'); | ||
const isCustomMock = options.saveHeaders || !(res.statusCode === 200 || res.statusCode === 204); | ||
let ext; | ||
let ext = contentType && mime.extension(contentType); | ||
// Prettify JSON responses | ||
if (data && ext === 'json') { | ||
try { | ||
data = JSON.parse(data.toString('utf8')); | ||
} catch (error) { | ||
console.warn('Cannot parse JSON from response'); | ||
} | ||
} | ||
if (isCustomMock) { | ||
@@ -32,8 +41,6 @@ const isString = isStringContent(contentType); | ||
statusCode: res.statusCode, | ||
headers: options.saveHeaders ? res.headers : undefined, | ||
body: data ? (isString ? data.toString('utf8') : data.toString('base64')) : null, | ||
headers: options.saveHeaders ? res.headers : contentType ? {'Content-Type': contentType} : undefined, | ||
body: data instanceof Buffer ? (isString ? data.toString('utf8') : data.toString('base64')) : null, | ||
buffer: isString ? undefined : true | ||
}; | ||
} else { | ||
ext = contentType && mime.extension(contentType); | ||
} | ||
@@ -150,3 +157,3 @@ | ||
const reqPath = mock.reqPath[0] === '/' ? mock.reqPath.substring(1) : mock.reqPath; | ||
const reqPath = (mock.reqPath[0] === '/' ? mock.reqPath.substring(1) : mock.reqPath).replace(/:/g, '@'); | ||
const pathComponents = reqPath.split('/').filter(c => c); | ||
@@ -153,0 +160,0 @@ |
{ | ||
"name": "smoke", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "Simple yet powerful file-based mock server with recording abilities", | ||
@@ -37,3 +37,3 @@ "main": "lib/smoke.js", | ||
"lodash.template": "^4.4.0", | ||
"mime-types": "^2.1.21", | ||
"mime-types": "^2.1.22", | ||
"minimist": "^1.2.0", | ||
@@ -40,0 +40,0 @@ "morgan": "^1.9.1", |
# :dash: smoke | ||
[![NPM version](https://img.shields.io/npm/v/smoke.svg)](https://www.npmjs.com/package/smoke) | ||
[![Build status](https://img.shields.io/travis/sinedied/smoke/master.svg)](https://travis-ci.org/sinedied/smoke) | ||
[![Travis build status](https://img.shields.io/travis/sinedied/smoke/master.svg)](https://travis-ci.org/sinedied/smoke) | ||
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/sinedied/smoke?svg=true&branch=master)](https://ci.appveyor.com/project/sinedied/smoke/branch/master) | ||
![Node version](https://img.shields.io/node/v/smoke.svg) | ||
@@ -76,3 +77,3 @@ [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo) | ||
**General format:** `methods_api#route#:routeParam$queryParam=value.__et.extension` | ||
**General format:** `methods_api#route#@routeParam$queryParam=value.__et.extension` | ||
@@ -92,4 +93,4 @@ The path and file name of the mock is used to determinate: | ||
Additionaly, any route component can be defined as a route parameter by prefixing the name with `:`, for example | ||
`api#resource#:id.json` will match `GET api/resource/1` and expose `1` as the value for the `id` parameter that can be | ||
Additionaly, any route component can be defined as a route parameter by prefixing the name with `@`, for example | ||
`api#resource#@id.json` will match `GET api/resource/1` and expose `1` as the value for the `id` parameter that can be | ||
used in dynamic mocks (templates or JavaScript). | ||
@@ -141,3 +142,3 @@ | ||
`http://server/hello?who=world` will result in the query value: `{ who: 'world' }`. | ||
- `params`: map containing matched route parameters. For example the mock `resource#:id.json` with the matched URL | ||
- `params`: map containing matched route parameters. For example the mock `resource#@id.json` with the matched URL | ||
`http://server/resource/123` will result in the params value: `{ id: '123' }`. | ||
@@ -144,0 +145,0 @@ - `headers`: map containing request headers |
@@ -48,2 +48,12 @@ const minimist = require('minimist'); | ||
}); | ||
if (options.version) { | ||
const pkg = require('./package.json'); | ||
return console.log(pkg.version); | ||
} | ||
if (options.help) { | ||
return console.log(help); | ||
} | ||
const app = createServer({ | ||
@@ -66,11 +76,2 @@ basePath: options._[0], | ||
if (options.help) { | ||
return console.log(help); | ||
} | ||
if (options.version) { | ||
const pkg = require('./package.json'); | ||
return console.log(pkg.version); | ||
} | ||
if (app) { | ||
@@ -77,0 +78,0 @@ startServer(app); |
@@ -34,6 +34,2 @@ const minimist = require('minimist'); | ||
if (options.help || options._.length !== 2) { | ||
return console.log(help); | ||
} | ||
if (options.version) { | ||
@@ -44,2 +40,6 @@ const pkg = require('./package.json'); | ||
if (options.help || options._.length !== 2) { | ||
return console.log(help); | ||
} | ||
await convert(options._[0], options._[1], options.ignore, options.depth); | ||
@@ -46,0 +46,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
317860
34
1496
346
+ Added@types/node@22.9.3(transitive)
- Removed@types/node@22.9.1(transitive)
Updatedmime-types@^2.1.22