Skip to content

Commit

Permalink
v 1.3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Marketto committed Jan 24, 2019
1 parent 60e97c7 commit 591ec49
Show file tree
Hide file tree
Showing 18 changed files with 381 additions and 167 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ mockettaro -r services
This project is licensed under the MIT License - see the [License](/LICENSE) file for details

## Changelog
### 1.3.12
- Used standard paths for bin and lib
- Fixed default params for MockettaroProgram
- Divided tests per class
- Added bin Unit
- Added separate unit test to prevent cache test issues
### 1.3.11
- Minor fixes
- Completed jsdoc
Expand Down
5 changes: 5 additions & 0 deletions bin/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-process-exit": "off"
}
}
3 changes: 3 additions & 0 deletions bin/mockettaro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node
const { mockettaroProgram } = require('../lib/mockettaro-program.class');
mockettaroProgram().catch(() => process.exit(1));
3 changes: 0 additions & 3 deletions commandline.js

This file was deleted.

1 change: 1 addition & 0 deletions examples/mocks/cities/Florence.GET.code
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
200
9 changes: 9 additions & 0 deletions examples/mocks/cities/Florence.GET.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "Florence",
"originalName": "Firenze",
"population": 380885,
"area": 102.41,
"metropolitanCity": true,
"region": "Tuscany",
"dialingCode": "055"
}
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const mockettaro = require('./dist/mockettaro.class');
const mockettaro = require('./lib/mockettaro.class');

module.exports.mockettaro = mockettaro;
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MockettaroProgram {
* @example MockettaroProgram.FOLDER_MATCHER
*/
static get FOLDER_MATCHER() {
return /^(?:(?:[a-z]:|\.{0,2})?(\\|\/))?([^!#$%&+={}[\]\n]+(\\|\/))*[^!#$%&+={}[\]\n]+$/i;
return /^(?:(?:[a-z]:|\.{1,2})?[\\/])?([^!#$%&+={}[\]\n]+[\\/])*[^!#$%&+={}[\]\n]+$/i;
}

/**
Expand Down Expand Up @@ -179,8 +179,13 @@ class MockettaroProgram {
* @param {string|Function} cwd Current Working Directory
* @returns {Promise<number>} Returns the copy process final status
*/
constructor({argv = process.argv, cwd = process.cwd()}) {

constructor({
argv = process.argv,
cwd = process.cwd()
} = {
argv: process.argv,
cwd: process.cwd()
}) {
const program = this.constructor.cmdParser(...argv)

if (program.verbose && program.silent) {
Expand All @@ -190,7 +195,6 @@ class MockettaroProgram {
const mockettaro = require('./mockettaro.class');
const logger = require("@marketto/js-logger").global();
const server = require('express')();
const path = require('path');

const {port, resource, folder, responseDelay, cacheLifetime, silent, verbose} = program;
server.use(`/${resource}`, mockettaro({
Expand All @@ -206,10 +210,11 @@ class MockettaroProgram {
return new Promise((resolve, reject) => {
try {
const serverInstance = server.listen(port, () => {
logger.info(`Mockettaro serving ${path.join(cwd, folder)} content @ localhost:${port}/${resource}`);
logger.info(`Mockettaro serving ${folder} content @ localhost:${port}/${resource}`);
resolve(serverInstance);
});
} catch (err) {
logger.error(err);
reject(err);
}
});
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
137 changes: 136 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mockettaro",
"version": "1.3.11",
"version": "1.3.12",
"description": "Node Rest Mock Server",
"main": "index.js",
"scripts": {
Expand All @@ -9,7 +9,7 @@
"docs": "jsdoc . -c jsdoc.json"
},
"bin": {
"mockettaro": "./commandline.js"
"mockettaro": "./bin/mockettaro.js"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sonar.projectVersion=1.3.11
sonar.projectVersion=1.3.12
sonar.sourceEncoding=UTF-8
sonar.sources=./
sonar.exclusions=**/node_modules/**,**/examples/**,**/test/**,**/coverage/**
Expand Down
27 changes: 27 additions & 0 deletions test/bin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const chai = require('chai');
const logger = require("@marketto/js-logger").global();

chai.use(require('chai-things'));
chai.should();

logger.config = { error: true, info: false, debug: false, warn: false };

describe('Commandline', () => {
const { exec } = require('child_process');
const pkgjson = require('../package.json');

it('Should return package version', done => {
exec(`node ${pkgjson.bin.mockettaro} -v`, (err, stdout, stderr) => {
(!err).should.be.true;
(!stderr).should.be.true;
stdout.should.match(new RegExp(`\\s*${pkgjson.version}\\s*`));
if (err) {
logger.error(err);
}
if (stderr) {
logger.error(err);
}
done();
});
});
});
Loading

0 comments on commit 591ec49

Please sign in to comment.