Sorry, the diff of this file is not supported yet
@@ -10,3 +10,3 @@ version: 2 | ||
| - run: npm test | ||
| - run: npm run danger | ||
| - run: npm run format:check | ||
@@ -17,2 +17,2 @@ workflows: | ||
| jobs: | ||
| - test | ||
| - test |
+1
-1
| module.exports = { | ||
| printWidth: 100, | ||
| singleQuote: true, | ||
| singleQuote: true | ||
| }; |
+21
-8
| { | ||
| "name": "simulado", | ||
| "version": "3.3.0", | ||
| "version": "3.3.1", | ||
| "description": "A simple nodejs mockserver", | ||
@@ -22,9 +22,20 @@ "main": "src/index.js", | ||
| "scripts": { | ||
| "start": "babel-node ./bin/simulado", | ||
| "watch": "nodemon -e js,html node_modules/.bin/babel-node ./bin/simulado", | ||
| "start": "./bin/simulado", | ||
| "watch": "nodemon -e js,html ./bin/simulado", | ||
| "test": "mocha --compilers js:@babel/register --require test.setup.js --recursive './src/**/*.test.js'", | ||
| "compile": "babel src --out-dir lib", | ||
| "format": "prettier --write './src/**/*.js' './bin/simulado'", | ||
| "danger": "danger ci" | ||
| "format": "prettier --write '**/*.{js,json,md}' && prettier --write --parser babylon bin/simulado", | ||
| "format:check": "prettier-check '**/*.{js,json,md}' && prettier-check --parser babylon bin/simulado" | ||
| }, | ||
| "husky": { | ||
| "hooks": { | ||
| "pre-commit": "pretty-quick --staged && lint-staged" | ||
| } | ||
| }, | ||
| "lint-staged": { | ||
| "bin/simulado": [ | ||
| "prettier --write --parser babylon", | ||
| "git add" | ||
| ] | ||
| }, | ||
| "author": "", | ||
@@ -35,12 +46,14 @@ "license": "ISC", | ||
| "@babel/core": "^7.1.2", | ||
| "@babel/node": "^7.0.0", | ||
| "@babel/preset-env": "^7.1.0", | ||
| "@babel/register": "^7.0.0", | ||
| "chai": "^4.2.0", | ||
| "danger": "^4.3.0", | ||
| "glob": "^7.1.3", | ||
| "husky": "^1.1.2", | ||
| "lint-staged": "^8.0.3", | ||
| "mocha": "^5.2.0", | ||
| "nodemon": "^1.18.4", | ||
| "nodemon": "^1.18.7", | ||
| "portscanner": "^2.2.0", | ||
| "prettier": "^1.14.3", | ||
| "prettier-check": "^2.0.0", | ||
| "pretty-quick": "^1.8.0", | ||
| "sinon": "^6.3.4", | ||
@@ -47,0 +60,0 @@ "sinon-chai": "^3.2.0", |
+55
-46
@@ -1,2 +0,2 @@ | ||
| # Simulado [](https://circleci.com/gh/ldabiralai/simulado) [](https://www.npmjs.com/package/simulado) []() | ||
| # Simulado [](https://circleci.com/gh/ldabiralai/simulado) [](https://www.npmjs.com/package/simulado) []() | ||
@@ -8,2 +8,3 @@ [](https://heroku.com/deploy) | ||
| ### Install | ||
| ```bash | ||
@@ -14,3 +15,5 @@ npm i simulado --save-dev | ||
| ### Usage | ||
| #### CLI | ||
| This will keep the server alive until the process is killed (unlike the below). | ||
@@ -23,2 +26,3 @@ | ||
| ##### Options | ||
| `-p`, `--port` - Port number that Simulado should start on. | ||
@@ -29,2 +33,3 @@ | ||
| ##### For HTTPS, use the following options | ||
| `-c`, `--cert <filepath>` - Path to certificate | ||
@@ -35,33 +40,28 @@ | ||
| #### Web Client | ||
| Once Simulado has started, going to `http://localhost:<SIMULADO_PORT_NUM>` will display a list of mocked endpoints and their responses. | ||
| #### Basic Usage | ||
| #### Basic Usage (ES6) | ||
| ```javascript | ||
| import simulado from 'simulado'; | ||
| import axios from 'axios'; | ||
| // Start Simulado server | ||
| simulado.start({ | ||
| port: 1234, // Default: 7001 | ||
| https: { | ||
| key: 'path/to/key', | ||
| cert: 'path/to/cert' | ||
| } | ||
| }); | ||
| (async function() { | ||
| // Start Simulado server | ||
| await simulado.start(); | ||
| // Mock a response | ||
| simulado.setMock({ | ||
| method: 'GET', | ||
| path: '/data', | ||
| status: 200, | ||
| body: { | ||
| data: 'Some Data' | ||
| } | ||
| }); | ||
| // Mock a response | ||
| await simulado.setMock({ | ||
| path: '/data', | ||
| body: 'Hello World!' | ||
| }); | ||
| // Make a request | ||
| request.get('http://localhost:1234/data') | ||
| .then(console.log) // => { data: 'Some Data' } | ||
| // Make a request | ||
| const response = await axios.get('http://localhost:7001/data'); | ||
| console.log(response.data); // => 'Hello World!' | ||
| // Stop Simulado server once done | ||
| simulado.stop(); | ||
| // Stop Simulado server once done | ||
| await simulado.stop(); | ||
| })(); | ||
| ``` | ||
@@ -72,69 +72,78 @@ | ||
| #### `start([options])` | ||
| Start Simulado | ||
| * options `<Object>` | ||
| * `port` `<number>` - Specify the port number to start Simulado on. Default: `7001` | ||
| * `https` `<object>` - Enable https support | ||
| * `key` `<string>` - path to key file | ||
| * `cert` `<string>` - path to cert file | ||
| - options `<Object>` | ||
| - `port` `<number>` - Specify the port number to start Simulado on. Default: `7001` | ||
| - `https` `<object>` - Enable https support | ||
| - `key` `<string>` - path to key file | ||
| - `cert` `<string>` - path to cert file | ||
| #### `setRemoteServer(url)` | ||
| Sets the url of a simulado instance on which the client should set mocks, for use if simulado lives on another server. | ||
| * `url` `<String>` for example `https://my-simulado-server.herokuapp.com` | ||
| - `url` `<String>` for example `https://my-simulado-server.herokuapp.com` | ||
| #### `setMock(mockResponse)` | ||
| Sets a mock response | ||
| * `mockResponse` `<MockResponse>` - Add a response to the store. [Full options MockResponse](#mock-response-options). | ||
| - `mockResponse` `<MockResponse>` - Add a response to the store. [Full options MockResponse](#mock-response-options). | ||
| #### `setMocks(mockResponses)` | ||
| Sets multiple mock responses | ||
| * `mockResponses` `[<MockResponse>]` - Add responses to the store. [Full options MockResponse](#mock-response-options). | ||
| - `mockResponses` `[<MockResponse>]` - Add responses to the store. [Full options MockResponse](#mock-response-options). | ||
| #### `setDefaults(mockResponses)` | ||
| Clears mocked responses and sets new mocked responses | ||
| * `mockResponses` `[<MockResponse>]` - Add responses to the store. [Full options MockResponse](#mock-response-options). | ||
| - `mockResponses` `[<MockResponse>]` - Add responses to the store. [Full options MockResponse](#mock-response-options). | ||
| #### `lastRequests(method, path[, limit])` | ||
| Fetch the last requests for a path | ||
| * `method` `<String>` - The request method for the requests you want to fetch | ||
| * `path` `<String>` - The path of the requests you want to fetch | ||
| * `limit` `<number>` - Only return the given number of last requests | ||
| - `method` `<String>` - The request method for the requests you want to fetch | ||
| - `path` `<String>` - The path of the requests you want to fetch | ||
| - `limit` `<number>` - Only return the given number of last requests | ||
| #### `lastRequest(method, path)` | ||
| Fetch the last request for a path | ||
| * `method` `<String>` - The request method for the requests you want to fetch | ||
| * `path` `<String>` - The path of the requests you want to fetch | ||
| - `method` `<String>` - The request method for the requests you want to fetch | ||
| - `path` `<String>` - The path of the requests you want to fetch | ||
| #### `clearResponse(method, path)` | ||
| Clear mocked response from the store | ||
| * `method` `<String>` - The HTTP request method to clear saved response from | ||
| * `path` `<String>` - The path to match against when clearing | ||
| - `method` `<String>` - The HTTP request method to clear saved response from | ||
| - `path` `<String>` - The path to match against when clearing | ||
| #### `clearResponses()` | ||
| Clear all mocked responses from the store. | ||
| #### `clearRequest(method, path)` | ||
| #### `clearRequest(method, path)` | ||
| Clear captured request from the store | ||
| * `method` `<String>` - The HTTP request method to clear saved request from | ||
| * `path` `<String>` - The path to match against when clearing | ||
| - `method` `<String>` - The HTTP request method to clear saved request from | ||
| - `path` `<String>` - The path to match against when clearing | ||
| #### `clearRequests()` | ||
| Clear all captured requests from the store. | ||
| #### `stop()` | ||
| #### `stop()` | ||
| Stop Simulado. | ||
| ### Mock Response Options | ||
| ```javascript | ||
@@ -141,0 +150,0 @@ { |
+5
-4
@@ -10,6 +10,2 @@ <!DOCTYPE HTML> | ||
| <script src="/simulado/public/babel.min.js"></script> | ||
| <script type="text/javascript"> | ||
| window.mockedResponses = <%- mockedResponses %>; | ||
| hljs.initHighlightingOnLoad(); | ||
| </script> | ||
| <style> | ||
@@ -31,2 +27,7 @@ body { | ||
| <body> | ||
| <pre id="mockedResponses" style="display: none"><%= mockedResponses %></pre> | ||
| <script type="text/javascript"> | ||
| window.mockedResponses = JSON.parse(document.querySelector('#mockedResponses').textContent); | ||
| hljs.initHighlightingOnLoad(); | ||
| </script> | ||
| <div id="root"></div> | ||
@@ -33,0 +34,0 @@ <script type="text/babel"> |
| import { schedule, message, fail } from "danger"; | ||
| import fs from 'fs'; | ||
| import prettier from 'prettier'; | ||
| import glob from 'glob'; | ||
| const srcDirGlob = `${__dirname}/src/**/*.js`; | ||
| const options = { | ||
| singleQuote: true, | ||
| printWidth: 100, | ||
| parser: 'babylon' | ||
| }; | ||
| const getAllFilePaths = dirGlob => { | ||
| return new Promise((resolve, reject) => { | ||
| glob(dirGlob, (err, filePaths) => { | ||
| if (err) { | ||
| reject(err); | ||
| } else { | ||
| resolve(filePaths); | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| const isFileFormatted = path => { | ||
| const fileContents = fs.readFileSync(path); | ||
| return prettier.check(fileContents.toString(), options); | ||
| } | ||
| schedule(async () => { | ||
| try { | ||
| const failedFilePaths = []; | ||
| const filePaths = await getAllFilePaths(srcDirGlob); | ||
| filePaths.forEach(filePath => { | ||
| if (!isFileFormatted(filePath)) { | ||
| failedFilePaths.push(filePath); | ||
| } | ||
| }); | ||
| if (failedFilePaths.length > 0) { | ||
| fail('You haven\'t formated the code using prettier. Please run `npm run format` before merging the PR'); | ||
| } else { | ||
| message(':tada: Your code is formatted correctly'); | ||
| } | ||
| } catch (e) { | ||
| fail('Looks like something went wrong! :/'); | ||
| } | ||
| }); |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
172
5.52%4
-20%1570686
-0.05%17
13.33%7605
-0.56%