Skip to content

Commit

Permalink
let all of the things
Browse files Browse the repository at this point in the history
  • Loading branch information
Bladymir Tellez committed Apr 2, 2018
1 parent 74ddd0d commit 2ab118d
Show file tree
Hide file tree
Showing 36 changed files with 302 additions and 302 deletions.
4 changes: 2 additions & 2 deletions bin/help_menu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var HelpMenu = function() {
var helpDescription = [
let HelpMenu = function() {
let helpDescription = [
"",
"Usage:",
" mockingjays <command> [options]",
Expand Down
4 changes: 2 additions & 2 deletions bin/mockingjays.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Mockingjays from '../index';
import HelpMenu from './help_menu';
import OptionParser from './option_parser';

var userOptions = OptionParser.parse(process.argv);
let userOptions = OptionParser.parse(process.argv);

switch (true) {
case OptionParser.shouldDisplayHelp(userOptions):
Expand All @@ -21,4 +21,4 @@ switch (true) {
default:
console.log('Error Parsing Options. Expected: serve, rehash, --help, or --version');
HelpMenu();
}
}
18 changes: 9 additions & 9 deletions bin/option_parser.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import parseArgs from 'minimist';
import _ from 'lodash';

var OptionsParser = {}
let OptionsParser = {}

var hasCommand = (arg) => arg == 'serve' || arg == 'rehash'
let hasCommand = (arg) => arg == 'serve' || arg == 'rehash'

OptionsParser.parse = function(processArgs) {
var userArgs = parseArgs(processArgs.slice(2));
var command = _.find(userArgs._, hasCommand)
let userArgs = parseArgs(processArgs.slice(2));
let command = _.find(userArgs._, hasCommand)
delete userArgs._ // Argument are parse. Done Extracting Values
return _.extend(userArgs, {command: command})
}


OptionsParser.shouldDisplayHelp = function (options) {
var argCount = 0;
for (var key in options) {
let argCount = 0;
for (let key in options) {
argCount++;
}
return options.command == 'help' || options.help || argCount == 0;
Expand All @@ -33,9 +33,9 @@ OptionsParser.shouldRehash = function (options) {


OptionsParser.shouldServe = function (options) {
var displayHelpMenu = OptionsParser.shouldDisplayHelp(options);
var displayVersionNumber = OptionsParser.shouldDisplayVersion(options);
var rehash = OptionsParser.shouldRehash(options);
let displayHelpMenu = OptionsParser.shouldDisplayHelp(options);
let displayVersionNumber = OptionsParser.shouldDisplayVersion(options);
let rehash = OptionsParser.shouldRehash(options);
return !displayHelpMenu && !displayVersionNumber && !rehash;
}

Expand Down
28 changes: 14 additions & 14 deletions features/step_definitions/cache_header_options_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import {Then, When} from 'cucumber';
const TIMEOUT = 20 * 1000;

When(/^I make a "([^"]*)" request to "([^"]*)" with headers:$/, {timeout: TIMEOUT}, function (method, urlPath, table, done) {
var headers = {};
let headers = {};

table.rows().forEach(row => headers[row[0]] = row[1]);

var options = {
let options = {
hostname: 'localhost',
port: this.options.port,
path: urlPath,
method: method,
headers: headers
};

var req = http.request(options, (response) => {
var chunks = [];
let req = http.request(options, (response) => {
let chunks = [];
response.on('data', (chunk) => {
chunks.push(chunk);
});
Expand All @@ -40,24 +40,24 @@ When(/^I make a "([^"]*)" request to "([^"]*)" with headers:$/, {timeout: TIMEOU


When(/^I make a GET request to "([^"]*)" with the query strings:$/, function (path, table, done) {
var first = true;
var queryString = table.hashes().reduce(function(qs, current) {
var key = current.KEY;
var val = current.VALUE;
let first = true;
let queryString = table.hashes().reduce(function(qs, current) {
let key = current.KEY;
let val = current.VALUE;
qs += (first ? '' : '&') + key + '=' + (isNaN(val) ? val : parseInt(val, 10));
first = false;
return qs;
}, '?');

var options = {
let options = {
hostname: 'localhost',
port: this.options.port,
path: path + queryString,
method: 'GET'
};

var req = http.request(options, function(response) {
var str = '';
let req = http.request(options, function(response) {
let str = '';
response.on('data', function (chunk) {str += chunk;});
response.on('end', function() {
this.result = str;
Expand All @@ -71,14 +71,14 @@ When(/^I make a GET request to "([^"]*)" with the query strings:$/, function (pa


Then(/^I see a cache file for "([^"]*)" with the following headers:$/, function (path, table, done) {
var files = this.cacheFiles(this.options.cacheDir, path);
let files = this.cacheFiles(this.options.cacheDir, path);
if (files.length != 1) {
done('Expecting 1 file for form-data. '+ files.length +' found');
return;
}

var generatedJSON = JSON.parse(fs.readFileSync(files[0], {encoding: 'utf-8'}));
var requiredHeadersFound = true;
let generatedJSON = JSON.parse(fs.readFileSync(files[0], {encoding: 'utf-8'}));
let requiredHeadersFound = true;

table.rows().forEach(function(row) {
requiredHeadersFound = requiredHeadersFound
Expand Down
20 changes: 10 additions & 10 deletions features/step_definitions/form_data_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ When(/^I wait$/, {timeout: 60 * 1000 * 5}, function () {


When(/^I make a form data request to "([^"]*)"$/, function (path, done) {
var postData = '--AaB03x\r\n' +
let postData = '--AaB03x\r\n' +
'content-disposition: form-data; name="x"\r\n' +
'\r\n' +
'Hello World\r\n' +
'--AaB03x--\r\n';

var options = {
let options = {
hostname: 'localhost',
port: this.options.port,
path: path,
Expand All @@ -25,8 +25,8 @@ When(/^I make a form data request to "([^"]*)"$/, function (path, done) {
method: 'POST'
};

var req = http.request(options, function(response) {
var str = '';
let req = http.request(options, function(response) {
let str = '';
response.on('data', function (chunk) {str += chunk;});
response.on('end', function() {
this.result = str;
Expand All @@ -40,19 +40,19 @@ When(/^I make a form data request to "([^"]*)"$/, function (path, done) {


Then(/^the boundary is a mockingjays boundary$/, function (done) {
var files = this.cacheFiles(this.options.cacheDir, '/formData');
let files = this.cacheFiles(this.options.cacheDir, '/formData');
if (files.length != 1) {
done('Expecting 1 file for form-data. '+ files.length +' found');
return;
}
var generatedJSON = JSON.parse(fs.readFileSync(files[0], {encoding: 'utf-8'}));
var hasUpdatedBoundary = generatedJSON.request.body.match('mockingjay');
let generatedJSON = JSON.parse(fs.readFileSync(files[0], {encoding: 'utf-8'}));
let hasUpdatedBoundary = generatedJSON.request.body.match('mockingjay');

done(!hasUpdatedBoundary ? 'Missing Mockingjays Boundary in Form Data': null);
});

When(/^I make a POST request to "([^"]*)" with the JSON body:$/, function (path, postData, done) {
var options = {
let options = {
hostname: 'localhost',
port: this.options.port,
path: path,
Expand All @@ -62,8 +62,8 @@ When(/^I make a POST request to "([^"]*)" with the JSON body:$/, function (path,
method: 'POST'
}

var req = http.request(options, function(response) {
var str = '';
let req = http.request(options, function(response) {
let str = '';
response.on('data', function(chunk) {str += chunk;});
response.on('end', function() {
this.result = str;
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/minimal_mockingjay_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Given(/^I want to create a Mockingjay instance with no options$/, function (done


Given(/^I want to create a Mockingjay instance with the following options$/, function (optionsTable, done) {
var options = {}
let options = {}
optionsTable.rows().forEach(function (row) {
return options[row[0]] = row[1];
});
Expand Down
4 changes: 2 additions & 2 deletions features/step_definitions/request_response_log_steps.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {When} from 'cucumber';

When(/^I can see the log file "([^"]*)"$/, function (logFileName, done) {
var files = this.logFile(this.options.cacheDir, logFileName);
let files = this.logFile(this.options.cacheDir, logFileName);
done(files.length ? undefined : 'Expected to see log file:' + logFileName + ", but found "+ files.length + " files");
});
});
12 changes: 6 additions & 6 deletions features/step_definitions/stateful_requests_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ Given(/^I provide the following transition config$/, function (string, done) {


When(/^I make a "([^"]*)" request to "([^"]*)"$/, function (method, path, done) {
var options = {
let options = {
hostname: 'localhost',
port: this.options.port,
path: path,
method: method
}

var req = http.request(options, (response) => {
var str = '';
let req = http.request(options, (response) => {
let str = '';
response.on('data', (chunk) => {str += chunk;});
response.on('end', () => {
this.result = str;
Expand All @@ -34,17 +34,17 @@ When(/^I make a "([^"]*)" request to "([^"]*)"$/, function (method, path, done)


Then(/^I can see (\d+) cache files for "([^"]*)"$/, function (count, path, done) {
var files = this.cacheFiles(this.options.cacheDir, path);
let files = this.cacheFiles(this.options.cacheDir, path);
done(files.length == parseInt(count, 10) ? undefined : 'Expected to see ' + count + " cache files, but found "+ files.length);
});


Then(/^I see the result "([^"]*)"$/, function (result, done) {
var msg = [
let msg = [
'Expected Result Not Found',
'Expected: ' + result,
'Found: ' + this.result
].join('\n');

done(this.result.indexOf(result) > -1 ? undefined : msg);
});
});
6 changes: 3 additions & 3 deletions features/support/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs';
import TestServer from './test_server';

Before('@TestServer', async function (scenario) {
var world = this;
let world = this;
world.serverState = {count: 0};
world.server = await TestServer();

Expand Down Expand Up @@ -41,7 +41,7 @@ Before('@TestServer', async function (scenario) {


After('@TestServer', function (scenario) {
var world = this;
let world = this;
world.serverState.count = 0;
world.server.stop();
});
});
12 changes: 6 additions & 6 deletions features/support/test_server.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import Hapi from 'hapi';
import inert from 'inert';

var TestServerBuilder = async function(options){
let TestServerBuilder = async function(options){
options = options || {};
var userHost = options.host || 'localhost';
var userPort = options.port || 9001;
var hapiInstance = new Hapi.server({host: userHost, port: userPort});
let userHost = options.host || 'localhost';
let userPort = options.port || 9001;
let hapiInstance = new Hapi.server({host: userHost, port: userPort});
await hapiInstance.register(inert);

return new TestServer(hapiInstance);
};

var TestServer = function(server){
let TestServer = function(server){
this.state = {};
this.server = server;
};
Expand All @@ -33,7 +33,7 @@ TestServer.prototype.stop = function () {
};

TestServer.prototype.start = function () {
var self = this;
let self = this;
this.server.start((err) => {
if (err) { throw err; }
});
Expand Down
10 changes: 5 additions & 5 deletions features/support/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import path from 'path';

function World() {
this.cacheFiles = function(cacheDir, endpoint) {
var cwd = process.cwd();
let cwd = process.cwd();
endpoint = endpoint.toLowerCase()
var isFile = function (filePath) { return !FileSystemHelper.directoryExists(filePath); };
let isFile = function (filePath) { return !FileSystemHelper.directoryExists(filePath); };
return FileSystemHelper.findFileType(path.join(cwd, cacheDir, endpoint), isFile);
}

this.logFile = function(cacheDir, logFile) {
var cwd = process.cwd();
var isFile = function (filePath) { return filePath.indexOf(logFile) > -1;};
let cwd = process.cwd();
let isFile = function (filePath) { return filePath.indexOf(logFile) > -1;};
return FileSystemHelper.findFileType(path.join(cwd, cacheDir), isFile);
}
}

setWorldConstructor(World)
setWorldConstructor(World)
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Mockingjay from './src/mockingjay';
import Rehasher from './src/rehasher';
import DefaultOptions from './src/default_options';

var Mockingjays = function() {}
let Mockingjays = function() {}

/**
* Start creates a Mockingjays Server and starts proxying
Expand All @@ -16,10 +16,10 @@ var Mockingjays = function() {}
* @param onReady - A {Function} to be called when the proxy is ready. [Optional]
*/
Mockingjays.prototype.start = function(options, onReady) {
var defaultOptions = new DefaultOptions();
var finalOptions = defaultOptions.merge(options);
var mockingjay = new Mockingjay(finalOptions);
var requestHandler = function(req, res) {
let defaultOptions = new DefaultOptions();
let finalOptions = defaultOptions.merge(options);
let mockingjay = new Mockingjay(finalOptions);
let requestHandler = function(req, res) {
mockingjay.onRequest(req, res);
};
this.server = Server.listen(finalOptions, requestHandler, onReady);
Expand All @@ -39,8 +39,8 @@ Mockingjays.prototype.close = function(done) {
* :serverBaseUrl - Base URL for the source server.
*/
Mockingjays.prototype.rehash = function(options) {
var defaultOptions = new DefaultOptions();
var finalOptions = defaultOptions.merge(options, {attemptToCreateCacheDir: false});
let defaultOptions = new DefaultOptions();
let finalOptions = defaultOptions.merge(options, {attemptToCreateCacheDir: false});
new Rehasher(finalOptions).process();
}

Expand Down
Loading

0 comments on commit 2ab118d

Please sign in to comment.