Skip to content

Commit

Permalink
chore: Automatic style fixes performed by eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
realityking committed Feb 24, 2018
1 parent d713b1c commit 7d5700c
Show file tree
Hide file tree
Showing 46 changed files with 830 additions and 1,080 deletions.
64 changes: 33 additions & 31 deletions src/add-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,29 @@ Stack: ${error.stack}
);

if (!isHooksDataCorrect) {
return next(
new Error('hooksData option must be an object e.g. {"filename.js":"console.log("Hey!")"}')
);
return next(new Error('hooksData option must be an object e.g. {"filename.js":"console.log("Hey!")"}'));
}

// Run code in sandbox
async.eachSeries(Object.keys(runner.configuration.hooksData), (key, nextHook) => {
const data = runner.configuration.hooksData[key];
async.eachSeries(
Object.keys(runner.configuration.hooksData), (key, nextHook) => {
const data = runner.configuration.hooksData[key];

// Run code in sandbox
sandboxHooksCode(data, (sandboxError, result) => {
if (sandboxError) { return nextHook(sandboxError); }
// Run code in sandbox
sandboxHooksCode(data, (sandboxError, result) => {
if (sandboxError) { return nextHook(sandboxError); }

// Merge stringified hooks
runner.hooks = mergeSandboxedHooks(runner.hooks, result);
// Merge stringified hooks
runner.hooks = mergeSandboxedHooks(runner.hooks, result);

// Fixing #168 issue
fixLegacyTransactionNames(runner.hooks);
// Fixing #168 issue
fixLegacyTransactionNames(runner.hooks);

nextHook();
});
}
, next);
nextHook();
});
}
, next
);
}

if (!runner.logs) { runner.logs = []; }
Expand Down Expand Up @@ -153,22 +153,24 @@ Stack: ${error.stack}
// Load sandbox files from fs
logger.info('Loading hook files in sandboxed context:', files);

return async.eachSeries(files, (resolvedPath, nextFile) =>
return async.eachSeries(
files, (resolvedPath, nextFile) =>
// Load hook file content
fs.readFile(resolvedPath, 'utf8', (readingError, data) => {
if (readingError) { return nextFile(readingError); }
// Run code in sandbox
sandboxHooksCode(data, (sandboxError, result) => {
if (sandboxError) { return nextFile(sandboxError); }
runner.hooks = mergeSandboxedHooks(runner.hooks, result);

// Fixing #168 issue
fixLegacyTransactionNames(runner.hooks);

return nextFile();
});
})
, callback);
fs.readFile(resolvedPath, 'utf8', (readingError, data) => {
if (readingError) { return nextFile(readingError); }
// Run code in sandbox
sandboxHooksCode(data, (sandboxError, result) => {
if (sandboxError) { return nextFile(sandboxError); }
runner.hooks = mergeSandboxedHooks(runner.hooks, result);

// Fixing #168 issue
fixLegacyTransactionNames(runner.hooks);

return nextFile();
});
})
, callback
);
}

module.exports = addHooks;
8 changes: 2 additions & 6 deletions src/child-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ function signalKill(childProcess, callback) {
const taskkill = spawn('taskkill', ['/F', '/T', '/PID', childProcess.pid]);
taskkill.on('exit', (exitStatus) => {
if (exitStatus) {
return callback(
new Error(`Unable to forcefully terminate process ${childProcess.pid}`)
);
return callback(new Error(`Unable to forcefully terminate process ${childProcess.pid}`));
}
callback();
});
Expand Down Expand Up @@ -108,9 +106,7 @@ function terminate(childProcess, options = {}, callback) {
if (force) {
signalKill(childProcess, callback);
} else {
callback(
new Error(`Unable to gracefully terminate process ${childProcess.pid}`)
);
callback(new Error(`Unable to gracefully terminate process ${childProcess.pid}`));
}
}
};
Expand Down
8 changes: 2 additions & 6 deletions src/configure-reporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@ function configureReporters(config, stats, tests, runner) {
if (reportersArr.length > 0) {
const usedCliReporters = intersection(reportersArr, cliReporters);
if (usedCliReporters.length === 0) {
return new CliReporter(
config.emitter, stats, tests, config.options['inline-errors'], config.options.details
);
return new CliReporter(config.emitter, stats, tests, config.options['inline-errors'], config.options.details);
}
return addReporter(usedCliReporters[0], config.emitter, stats, tests);
}
return new CliReporter(
config.emitter, stats, tests, config.options['inline-errors'], config.options.details
);
return new CliReporter(config.emitter, stats, tests, config.options['inline-errors'], config.options.details);
}

function addReporter(reporter, emitter, statistics, testsArg, path) {
Expand Down
10 changes: 6 additions & 4 deletions src/dredd-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,12 @@ ${packageData.name} v${packageData.version} \
const waitMilis = waitSecs * 1000;
logger.info(`Waiting ${waitSecs} seconds for backend server process to start`);

this.wait = setTimeout(() => {
this.runDredd(this.dreddInstance);
}
, waitMilis);
this.wait = setTimeout(
() => {
this.runDredd(this.dreddInstance);
}
, waitMilis
);
}
}

Expand Down
106 changes: 56 additions & 50 deletions src/dredd.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,56 +136,60 @@ https://dredd.readthedocs.io/en/latest/how-it-works/#using-https-proxy

// Expand all globs
expandGlobs(callback) {
async.each(this.configuration.options.path, (globToExpand, globCallback) => {
if (/^http(s)?:\/\//.test(globToExpand)) {
this.configuration.files = this.configuration.files.concat(globToExpand);
return globCallback();
}
async.each(
this.configuration.options.path, (globToExpand, globCallback) => {
if (/^http(s)?:\/\//.test(globToExpand)) {
this.configuration.files = this.configuration.files.concat(globToExpand);
return globCallback();
}

glob(globToExpand, (err, match) => {
if (err) { return globCallback(err); }
this.configuration.files = this.configuration.files.concat(match);
if (match.length === 0) {
err = new Error(`
glob(globToExpand, (err, match) => {
if (err) { return globCallback(err); }
this.configuration.files = this.configuration.files.concat(match);
if (match.length === 0) {
err = new Error(`
API description document(s) not found on path:
'${globToExpand}'
`);
return globCallback(err);
}
globCallback();
});
}
return globCallback(err);
}
globCallback();
});
}
, (err) => {
if (err) { return callback(err, this.stats); }
if (err) { return callback(err, this.stats); }

if (this.configDataIsEmpty && this.configuration.files.length === 0) {
err = new Error(`
if (this.configDataIsEmpty && this.configuration.files.length === 0) {
err = new Error(`
API description document (or documents) not found on path:
'${this.configuration.options.path}'
`);
return callback(err, this.stats);
}
return callback(err, this.stats);
}

// Remove duplicate filenames
this.configuration.files = removeDuplicates(this.configuration.files);
callback(null, this.stats);
});
// Remove duplicate filenames
this.configuration.files = removeDuplicates(this.configuration.files);
callback(null, this.stats);
}
);
}

// Load all files
loadFiles(callback) {
// 6 parallel connections is a standard limit when connecting to one hostname,
// use the same limit of parallel connections for reading/downloading files
async.eachLimit(this.configuration.files, 6, (fileUrlOrPath, loadCallback) => {
const { protocol, host } = url.parse(fileUrlOrPath);
if (host && ['http:', 'https:'].includes(protocol)) {
logger.verbose('Downloading remote file:', fileUrlOrPath);
this.downloadFile(fileUrlOrPath, loadCallback);
} else {
this.readLocalFile(fileUrlOrPath, loadCallback);
async.eachLimit(
this.configuration.files, 6, (fileUrlOrPath, loadCallback) => {
const { protocol, host } = url.parse(fileUrlOrPath);
if (host && ['http:', 'https:'].includes(protocol)) {
logger.verbose('Downloading remote file:', fileUrlOrPath);
this.downloadFile(fileUrlOrPath, loadCallback);
} else {
this.readLocalFile(fileUrlOrPath, loadCallback);
}
}
}
, callback);
, callback
);
}

downloadFile(fileUrl, callback) {
Expand Down Expand Up @@ -234,24 +238,26 @@ Is the provided path correct?
this.transactions = [];

// Compile HTTP transactions for each API description
async.each(Object.keys(this.configuration.data), (filename, next) => {
const fileData = this.configuration.data[filename];
if (!fileData.annotations) { fileData.annotations = []; }

logger.verbose('Compiling HTTP transactions from API description file:', filename);
dreddTransactions.compile(fileData.raw, filename, (compilationError, compilationResult) => {
if (compilationError) { return next(compilationError); }

fileData.mediaType = compilationResult.mediaType;
fileData.annotations = fileData.annotations.concat(compilationResult.annotations);
this.transactions = this.transactions.concat(compilationResult.transactions);
next();
});
}
async.each(
Object.keys(this.configuration.data), (filename, next) => {
const fileData = this.configuration.data[filename];
if (!fileData.annotations) { fileData.annotations = []; }

logger.verbose('Compiling HTTP transactions from API description file:', filename);
dreddTransactions.compile(fileData.raw, filename, (compilationError, compilationResult) => {
if (compilationError) { return next(compilationError); }

fileData.mediaType = compilationResult.mediaType;
fileData.annotations = fileData.annotations.concat(compilationResult.annotations);
this.transactions = this.transactions.concat(compilationResult.transactions);
next();
});
}
, (runtimeError) => {
if (!runtimeError) { runtimeError = handleRuntimeProblems(this.configuration.data); }
callback(runtimeError, this.stats);
});
if (!runtimeError) { runtimeError = handleRuntimeProblems(this.configuration.data); }
callback(runtimeError, this.stats);
}
);
}

// Start the runner
Expand Down
3 changes: 1 addition & 2 deletions src/interactive-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ interactiveConfig.processAnswers = function (config, answers, callback) {

interactiveConfig.run = function (config, callback) {
interactiveConfig.prompt(config, answers =>
interactiveConfig.processAnswers(config, answers, callback)
);
interactiveConfig.processAnswers(config, answers, callback));
};

interactiveConfig.updateCircle = function () {
Expand Down
3 changes: 1 addition & 2 deletions src/reporters/cli-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ CliReporter.prototype.configureEmitter = function (emitter) {
`${this.stats.failures} failing, ` +
`${this.stats.errors} errors, ` +
`${this.stats.skipped} skipped, ` +
`${this.stats.tests} total`
);
`${this.stats.tests} total`);
}

logger.complete(`Tests took ${this.stats.duration}ms`);
Expand Down
3 changes: 1 addition & 2 deletions src/reporters/x-unit-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ XUnitReporter.prototype.configureEmitter = function (emitter) {
skip: this.stats.skipped,
timestamp: (new Date()).toUTCString(),
time: this.stats.duration / 1000
}, false)
);
}, false));
callback();
} else {
logger.error(err);
Expand Down
8 changes: 5 additions & 3 deletions src/sandbox-hooks-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ output\
`;

const sandbox = new Pitboss(wrappedCode);
sandbox.run({ libraries: {
_Hooks: '../../../lib/hooks', console: 'console'
} }, (err, result) => {
sandbox.run({
libraries: {
_Hooks: '../../../lib/hooks', console: 'console'
}
}, (err, result) => {
sandbox.kill();
if (err) { return callback(err); }
callback(undefined, result);
Expand Down
Loading

0 comments on commit 7d5700c

Please sign in to comment.