Skip to content

Commit

Permalink
reformat everything with Prettier
Browse files Browse the repository at this point in the history
replaces 5fc5845
  • Loading branch information
boneskull committed May 18, 2018
1 parent 11b6867 commit 697952b
Show file tree
Hide file tree
Showing 133 changed files with 7,358 additions and 6,168 deletions.
101 changes: 80 additions & 21 deletions bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const exit = code => {
// https://github.com/joyent/node/issues/6247 is just one bug example
// https://github.com/visionmedia/mocha/issues/333 has a good discussion
const done = () => {
if (!(draining--)) {
if (!draining--) {
process.exit(clampedCode);
}
};
Expand Down Expand Up @@ -150,9 +150,16 @@ const images = {
// options

program
.version(JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8')).version)
.version(
JSON.parse(
fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8')
).version
)
.usage('[debug] [options] [files]')
.option('-A, --async-only', 'force all tests to take a callback (async) or return a promise')
.option(
'-A, --async-only',
'force all tests to take a callback (async) or return a promise'
)
.option('-c, --colors', 'force enabling of colors')
.option('-C, --no-colors', 'force disabling of colors')
.option('-G, --growl', 'enable growl notification support')
Expand All @@ -168,24 +175,53 @@ program
.option('-r, --require <name>', 'require the given module')
.option('-s, --slow <ms>', '"slow" test threshold in milliseconds [75]')
.option('-t, --timeout <ms>', 'set test-case timeout in milliseconds [2000]')
.option('-u, --ui <name>', `specify user-interface (${interfaceNames.join('|')})`, 'bdd')
.option(
'-u, --ui <name>',
`specify user-interface (${interfaceNames.join('|')})`,
'bdd'
)
.option('-w, --watch', 'watch files for changes')
.option('--check-leaks', 'check for global variable leaks')
.option('--full-trace', 'display the full stack trace')
.option('--compilers <ext>:<module>,...', 'use the given module(s) to compile files', list, [])
.option(
'--compilers <ext>:<module>,...',
'use the given module(s) to compile files',
list,
[]
)
.option('--debug-brk', "enable node's debugger breaking on the first line")
.option('--globals <names>', 'allow the given comma-delimited global [names]', list, [])
.option(
'--globals <names>',
'allow the given comma-delimited global [names]',
list,
[]
)
.option('--es_staging', 'enable all staged features')
.option('--harmony<_classes,_generators,...>', 'all node --harmony* flags are available')
.option('--preserve-symlinks', 'Instructs the module loader to preserve symbolic links when resolving and caching modules')
.option(
'--harmony<_classes,_generators,...>',
'all node --harmony* flags are available'
)
.option(
'--preserve-symlinks',
'Instructs the module loader to preserve symbolic links when resolving and caching modules'
)
.option('--icu-data-dir', 'include ICU data')
.option('--inline-diffs', 'display actual/expected differences inline within each string')
.option(
'--inline-diffs',
'display actual/expected differences inline within each string'
)
.option('--no-diff', 'do not show a diff on failure')
.option('--inspect', 'activate devtools in chrome')
.option('--inspect-brk', 'activate devtools in chrome and break on the first line')
.option(
'--inspect-brk',
'activate devtools in chrome and break on the first line'
)
.option('--interfaces', 'display available interfaces')
.option('--no-deprecation', 'silence deprecation warnings')
.option('--exit', 'force shutdown of the event loop after test run: mocha will call process.exit')
.option(
'--exit',
'force shutdown of the event loop after test run: mocha will call process.exit'
)
.option('--no-timeouts', 'disables timeouts, given implicitly with --debug')
.option('--no-warnings', 'silence all node process warnings')
.option('--opts <path>', 'specify opts path', 'test/mocha.opts')
Expand All @@ -195,18 +231,37 @@ program
.option('--log-timer-events', 'Time events including external callbacks')
.option('--recursive', 'include sub directories')
.option('--reporters', 'display available reporters')
.option('--retries <times>', 'set numbers of time to retry a failed test case')
.option('--throw-deprecation', 'throw an exception anytime a deprecated function is used')
.option(
'--retries <times>',
'set numbers of time to retry a failed test case'
)
.option(
'--throw-deprecation',
'throw an exception anytime a deprecated function is used'
)
.option('--trace', 'trace function calls')
.option('--trace-deprecation', 'show stack traces on deprecations')
.option('--trace-warnings', 'show stack traces on node process warnings')
.option('--use_strict', 'enforce strict mode')
.option('--watch-extensions <ext>,...', 'additional extensions to monitor with --watch', list, [])
.option(
'--watch-extensions <ext>,...',
'additional extensions to monitor with --watch',
list,
[]
)
.option('--delay', 'wait for async suite definition')
.option('--allow-uncaught', 'enable uncaught errors to propagate')
.option('--forbid-only', 'causes test marked with only to fail the suite')
.option('--forbid-pending', 'causes pending tests and test marked with skip to fail the suite')
.option('--file <file>', 'include a file to be ran during the suite', collect, [])
.option(
'--forbid-pending',
'causes pending tests and test marked with skip to fail the suite'
)
.option(
'--file <file>',
'include a file to be ran during the suite',
collect,
[]
)
.option('--exclude <file>', 'a file or glob pattern to ignore', collect, []);

program._name = 'mocha';
Expand Down Expand Up @@ -447,7 +502,7 @@ if (program.forbidPending) mocha.forbidPending();

if (program.compilers.length > 0) {
require('util').deprecate(() => {},
'"--compilers" will be removed in a future version of Mocha; see https://git.io/vdcSr for more info')();
'"--compilers" will be removed in a future version of Mocha; see https://git.io/vdcSr for more info')();
}
const extensions = ['js'];
program.compilers.forEach(c => {
Expand Down Expand Up @@ -489,7 +544,9 @@ args.forEach(arg => {
newFiles = utils.lookupFiles(arg, extensions, program.recursive);
} catch (err) {
if (err.message.indexOf('cannot resolve path') === 0) {
console.error(`Warning: Could not find any test files matching pattern: ${arg}`);
console.error(
`Warning: Could not find any test files matching pattern: ${arg}`
);
return;
}

Expand All @@ -500,7 +557,9 @@ args.forEach(arg => {
if (typeof newFiles === 'string') {
newFiles = [newFiles];
}
newFiles = newFiles.filter(fileName => program.exclude.every(pattern => !minimatch(fileName, pattern)));
newFiles = newFiles.filter(fileName =>
program.exclude.every(pattern => !minimatch(fileName, pattern))
);
}

files = files.concat(newFiles);
Expand Down Expand Up @@ -538,7 +597,7 @@ if (program.watch) {
process.exit(130);
});

const watchFiles = utils.files(cwd, [ 'js' ].concat(program.watchExtensions));
const watchFiles = utils.files(cwd, ['js'].concat(program.watchExtensions));
let runAgain = false;

loadAndRun = () => {
Expand Down Expand Up @@ -585,7 +644,7 @@ if (program.watch) {
}
});
} else {
// load
// load

mocha.files = files;
runner = mocha.run(program.exit ? exit : exitLater);
Expand Down
17 changes: 11 additions & 6 deletions bin/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ module.exports = getOptions;
* Get options.
*/

function getOptions () {
if (process.argv.length === 3 && (process.argv[2] === '-h' || process.argv[2] === '--help')) {
function getOptions() {
if (
process.argv.length === 3 &&
(process.argv[2] === '-h' || process.argv[2] === '--help')
) {
return;
}

const optsPath = process.argv.indexOf('--opts') === -1
? 'test/mocha.opts'
: process.argv[process.argv.indexOf('--opts') + 1];
const optsPath =
process.argv.indexOf('--opts') === -1
? 'test/mocha.opts'
: process.argv[process.argv.indexOf('--opts') + 1];

try {
const opts = fs.readFileSync(optsPath, 'utf8')
const opts = fs
.readFileSync(optsPath, 'utf8')
.replace(/\\\s/g, '%20')
.split(/\s/)
.filter(Boolean)
Expand Down
36 changes: 20 additions & 16 deletions browser-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var Mocha = require('./lib/mocha');
* @return {undefined}
*/

var mocha = new Mocha({ reporter: 'html' });
var mocha = new Mocha({reporter: 'html'});

/**
* Save timer references to avoid Sinon interfering (see GH-237).
Expand All @@ -38,12 +38,12 @@ var originalOnerrorHandler = global.onerror;
* Revert to original onerror handler if previously defined.
*/

process.removeListener = function (e, fn) {
process.removeListener = function(e, fn) {
if (e === 'uncaughtException') {
if (originalOnerrorHandler) {
global.onerror = originalOnerrorHandler;
} else {
global.onerror = function () {};
global.onerror = function() {};
}
var i = uncaughtExceptionHandlers.indexOf(fn);
if (i !== -1) {
Expand All @@ -56,9 +56,9 @@ process.removeListener = function (e, fn) {
* Implements uncaughtException listener.
*/

process.on = function (e, fn) {
process.on = function(e, fn) {
if (e === 'uncaughtException') {
global.onerror = function (err, url, line) {
global.onerror = function(err, url, line) {
fn(new Error(err + ' (' + url + ':' + line + ')'));
return !mocha.allowUncaught;
};
Expand All @@ -74,9 +74,9 @@ mocha.suite.removeAllListeners('pre-require');
var immediateQueue = [];
var immediateTimeout;

function timeslice () {
function timeslice() {
var immediateStart = new Date().getTime();
while (immediateQueue.length && (new Date().getTime() - immediateStart) < 100) {
while (immediateQueue.length && new Date().getTime() - immediateStart < 100) {
immediateQueue.shift()();
}
if (immediateQueue.length) {
Expand All @@ -90,7 +90,7 @@ function timeslice () {
* High-performance override of Runner.immediately.
*/

Mocha.Runner.immediately = function (callback) {
Mocha.Runner.immediately = function(callback) {
immediateQueue.push(callback);
if (!immediateTimeout) {
immediateTimeout = setTimeout(timeslice, 0);
Expand All @@ -102,8 +102,8 @@ Mocha.Runner.immediately = function (callback) {
* This is useful when running tests in a browser because window.onerror will
* only receive the 'message' attribute of the Error.
*/
mocha.throwError = function (err) {
uncaughtExceptionHandlers.forEach(function (fn) {
mocha.throwError = function(err) {
uncaughtExceptionHandlers.forEach(function(fn) {
fn(err);
});
throw err;
Expand All @@ -114,7 +114,7 @@ mocha.throwError = function (err) {
* Normally this would happen in Mocha.prototype.loadFiles.
*/

mocha.ui = function (ui) {
mocha.ui = function(ui) {
Mocha.prototype.ui.call(this, ui);
this.suite.emit('pre-require', global, null, this);
return this;
Expand All @@ -124,9 +124,9 @@ mocha.ui = function (ui) {
* Setup mocha with the given setting options.
*/

mocha.setup = function (opts) {
mocha.setup = function(opts) {
if (typeof opts === 'string') {
opts = { ui: opts };
opts = {ui: opts};
}
for (var opt in opts) {
if (opts.hasOwnProperty(opt)) {
Expand All @@ -140,7 +140,7 @@ mocha.setup = function (opts) {
* Run mocha, returning the Runner.
*/

mocha.run = function (fn) {
mocha.run = function(fn) {
var options = mocha.options;
mocha.globals('location');

Expand All @@ -155,10 +155,14 @@ mocha.run = function (fn) {
mocha.invert();
}

return Mocha.prototype.run.call(mocha, function (err) {
return Mocha.prototype.run.call(mocha, function(err) {
// The DOM Document is not available in Web Workers.
var document = global.document;
if (document && document.getElementById('mocha') && options.noHighlighting !== true) {
if (
document &&
document.getElementById('mocha') &&
options.noHighlighting !== true
) {
Mocha.utils.highlightTags('code');
}
if (fn) {
Expand Down
19 changes: 9 additions & 10 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ const browserPlatformPairs = {
module.exports = config => {
let bundleDirpath;
const cfg = {
frameworks: [
'browserify',
'expect',
'mocha'
],
frameworks: ['browserify', 'expect', 'mocha'],
files: [
// we use the BDD interface for all of the tests that
// aren't interface-specific.
Expand All @@ -32,8 +28,9 @@ module.exports = config => {
},
browserify: {
debug: true,
configure: function configure (b) {
b.ignore('glob')
configure: function configure(b) {
b
.ignore('glob')
.ignore('fs')
.ignore('path')
.ignore('supports-color')
Expand All @@ -43,8 +40,10 @@ module.exports = config => {
}
if (bundleDirpath) {
// write bundle to directory for debugging
fs.writeFileSync(path.join(bundleDirpath,
`mocha.${Date.now()}.js`), content);
fs.writeFileSync(
path.join(bundleDirpath, `mocha.${Date.now()}.js`),
content
);
}
});
}
Expand Down Expand Up @@ -155,7 +154,7 @@ module.exports = config => {
config.set(cfg);
};

function addSauceTests (cfg) {
function addSauceTests(cfg) {
cfg.reporters.push('saucelabs');
const browsers = Object.keys(browserPlatformPairs);
cfg.browsers = cfg.browsers.concat(browsers);
Expand Down
Loading

0 comments on commit 697952b

Please sign in to comment.