Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

smoke

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smoke - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

3

CHANGELOG.md

@@ -0,1 +1,4 @@

# 1.3.0
- Add fallback proxy option
# 1.2.0

@@ -2,0 +5,0 @@ - Add support for middleware hooks

7

cli.js

@@ -14,2 +14,3 @@ const minimist = require('minimist');

-k, --hooks <file> Middleware hooks [default: none]
-x, --proxy <host> Fallback proxy if no mock found
-l, --logs Enable server logs

@@ -28,3 +29,3 @@ -v, --version Show version

number: ['port', 'depth'],
string: ['host', 'set', 'not-found', 'record', 'ignore', 'hooks'],
string: ['host', 'set', 'not-found', 'record', 'ignore', 'hooks', 'proxy'],
boolean: ['help', 'version', 'logs'],

@@ -41,3 +42,4 @@ alias: {

g: 'ignore',
k: 'hooks'
k: 'hooks',
x: 'proxy'
}

@@ -53,2 +55,3 @@ });

hooks: options.hooks,
proxy: options.proxy,
logs: options.logs,

@@ -55,0 +58,0 @@ record: options.record,

@@ -61,3 +61,12 @@ const path = require('path');

ignoreGlobs = ignoreGlobs.map(glob => `!${path.isAbsolute(glob) ? path.relative(basePath, glob) : glob}`);
const mockFiles = await globby(globs.concat(ignoreGlobs), {cwd: basePath});
let mockFiles = await globby(globs.concat(ignoreGlobs), {cwd: basePath});
const singleFileMocks = [];
mockFiles = mockFiles.filter(mock => {
if (mock.endsWith('.mocks.js')) {
singleFileMocks.push(mock);
return false;
}
return true;
});
return mockFiles.map(file => getMock(basePath, file));

@@ -64,0 +73,0 @@ }

{
"name": "smoke",
"version": "1.2.0",
"version": "1.3.0",
"description": "Simple yet powerful file-based mock server with recording abilities",

@@ -33,3 +33,3 @@ "main": "smoke.js",

"fs-extra": "^7.0.1",
"globby": "^8.0.1",
"globby": "^8.0.2",
"import-fresh": "^3.0.0",

@@ -36,0 +36,0 @@ "lodash.template": "^4.4.0",

@@ -38,2 +38,3 @@ # :dash: smoke

- Add custom middlewares to modify requests/responses
- Mock only specific requests and proxy the rest to an existing server

@@ -50,3 +51,3 @@ ## Installation

CLI usage is quite straightforward:
CLI usage is quite straightforward you can just run `smoke` unless you want to add some options:
```

@@ -61,2 +62,4 @@ Usage: smoke [<mocks_folder>] [options]

-g, --ignore <glob> Files to ignore [default: none]
-k, --hooks <file> Middleware hooks [default: none]
-x, --proxy <host> Fallback proxy if no mock found
-l, --logs Enable server logs

@@ -238,2 +241,9 @@ -v, --version Show version

### Fallback proxy
If you want to override responses of an existing server, you can use the `--proxy <host>` option. This will proxy
every request for which a mock does not exist to the specified host.
This can also be useful for mocking yet-to-be-implemented APIs and keep using real implemented APIs.
### Mock recording

@@ -240,0 +250,0 @@

@@ -21,4 +21,5 @@ const path = require('path');

hooks: options.hooks || null,
proxy: options.record || options.proxy || null,
logs: options.logs || false,
record: options.record || null,
record: Boolean(options.record),
depth: typeof options.depth === 'number' ? options.depth : 1,

@@ -90,8 +91,10 @@ saveHeaders: options.saveHeaders || false

if (matches.length === 0) {
if (options.record) {
console.info(`No mock found for ${req.path}, proxying request to ${options.record}`);
return proxy(options.record, {
if (options.proxy) {
console.info(`No mock found for ${req.path}, proxying request to ${options.proxy}`);
return proxy(options.proxy, {
limit: '10mb',
userResDecorator: async (proxyRes, proxyResData, userReq) => {
await record(userReq, proxyRes, proxyResData, options);
if (options.record) {
await record(userReq, proxyRes, proxyResData, options);
}
return proxyResData;

@@ -98,0 +101,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc