Skip to content

Commit

Permalink
Replace findup-sync with find-up, hopefully to increase startup perfo…
Browse files Browse the repository at this point in the history
…rmance
  • Loading branch information
cspotcode committed Mar 12, 2019
1 parent ca9eba6 commit 32015bc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/cli/config.js
Expand Up @@ -9,7 +9,7 @@
*/

const fs = require('fs');
const findUp = require('findup-sync');
const findUp = require('find-up');
const path = require('path');
const debug = require('debug')('mocha:cli:config');

Expand Down Expand Up @@ -72,7 +72,7 @@ exports.loadConfig = filepath => {
* @returns {string|null} Filepath to config, if found
*/
exports.findConfig = (cwd = process.cwd()) => {
const filepath = findUp(exports.CONFIG_FILES, {cwd});
const filepath = findUp.sync(exports.CONFIG_FILES, {cwd});
if (filepath) {
debug(`found config at ${filepath}`);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/cli/options.js
Expand Up @@ -13,7 +13,7 @@ const {ONE_AND_DONE_ARGS} = require('./one-and-dones');
const mocharc = require('../mocharc.json');
const {list} = require('./run-helpers');
const {loadConfig, findConfig} = require('./config');
const findup = require('findup-sync');
const findUp = require('find-up');
const {deprecate} = require('../utils');
const debug = require('debug')('mocha:cli:options');
const {createMissingArgumentError} = require('../errors');
Expand Down Expand Up @@ -255,7 +255,7 @@ const loadPkgRc = (args = {}) => {
return result;
}
result = {};
const filepath = args.package || findup(mocharc.package);
const filepath = args.package || findUp.sync(mocharc.package);
if (filepath) {
try {
const pkg = JSON.parse(fs.readFileSync(filepath, 'utf8'));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -497,7 +497,7 @@
"debug": "3.2.6",
"diff": "3.5.0",
"escape-string-regexp": "1.0.5",
"findup-sync": "2.0.0",
"find-up": "3.0.0",
"glob": "7.1.3",
"growl": "1.10.5",
"he": "1.2.0",
Expand Down
4 changes: 2 additions & 2 deletions test/node-unit/cli/config.spec.js
Expand Up @@ -109,12 +109,12 @@ describe('cli/config', function() {
let findConfig;

beforeEach(function() {
findup = sandbox.stub().returns('/some/path/.mocharc.js');
findup = {sync: sandbox.stub().returns('/some/path/.mocharc.js')};
rewiremock.enable();
findConfig = rewiremock.proxy(
require.resolve('../../../lib/cli/config'),
r => ({
'findup-sync': r.by(() => findup)
'find-up': r.by(() => findup)
})
).findConfig;
});
Expand Down
6 changes: 4 additions & 2 deletions test/node-unit/cli/options.spec.js
Expand Up @@ -10,14 +10,16 @@ const configPath = require.resolve('../../../lib/cli/config');

const proxyLoadOptions = ({
readFileSync = {},
findupSync = {},
findupSync = null,
findConfig = {},
loadConfig = {}
} = {}) =>
rewiremock.proxy(modulePath, r => ({
fs: r.with({readFileSync}).directChildOnly(),
[mocharcPath]: defaults,
'findup-sync': r.by(() => findupSync).directChildOnly(),
'find-up': r
.by(() => (findupSync ? {sync: findupSync} : {}))
.directChildOnly(),
[configPath]: r.with({findConfig, loadConfig}).directChildOnly()
})).loadOptions;

Expand Down

0 comments on commit 32015bc

Please sign in to comment.