Skip to content

Commit 1b5cbf1

Browse files
authored
Remove deprecated "utils.lookupFiles()" (#4636)
1 parent 356ecf4 commit 1b5cbf1

File tree

3 files changed

+2
-84
lines changed

3 files changed

+2
-84
lines changed

lib/cli/lookup-files.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
var fs = require('fs');
99
var path = require('path');
1010
var glob = require('glob');
11-
var {format} = require('util');
1211
var errors = require('../errors');
1312
var createNoFilesMatchPatternError = errors.createNoFilesMatchPatternError;
1413
var createMissingArgumentError = errors.createMissingArgumentError;
15-
var {sQuote, dQuote} = require('../utils');
1614
const debug = require('debug')('mocha:cli:lookup-files');
1715

1816
/**
@@ -91,7 +89,7 @@ module.exports = function lookupFiles(
9189
files.push(...glob.sync(pattern, {nodir: true}));
9290
if (!files.length) {
9391
throw createNoFilesMatchPatternError(
94-
'Cannot find any files matching pattern ' + dQuote(filepath),
92+
`Cannot find any files matching pattern "${filepath}"`,
9593
filepath
9694
);
9795
}
@@ -127,11 +125,7 @@ module.exports = function lookupFiles(
127125
}
128126
if (!extensions.length) {
129127
throw createMissingArgumentError(
130-
format(
131-
'Argument %s required when argument %s is a directory',
132-
sQuote('extensions'),
133-
sQuote('filepath')
134-
),
128+
`Argument '${extensions}' required when argument '${filepath}' is a directory`,
135129
'extensions',
136130
'array'
137131
);

lib/utils.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const {nanoid} = require('nanoid/non-secure');
1313
var path = require('path');
1414
var util = require('util');
1515
var he = require('he');
16-
const errors = require('./errors');
1716

1817
const MOCHA_ID_PROP_NAME = '__mocha_id__';
1918

@@ -650,35 +649,6 @@ exports.isBrowser = function isBrowser() {
650649
return Boolean(process.browser);
651650
};
652651

653-
/**
654-
* Lookup file names at the given `path`.
655-
*
656-
* @description
657-
* Filenames are returned in _traversal_ order by the OS/filesystem.
658-
* **Make no assumption that the names will be sorted in any fashion.**
659-
*
660-
* @public
661-
* @alias module:lib/cli.lookupFiles
662-
* @param {string} filepath - Base path to start searching from.
663-
* @param {string[]} [extensions=[]] - File extensions to look for.
664-
* @param {boolean} [recursive=false] - Whether to recurse into subdirectories.
665-
* @return {string[]} An array of paths.
666-
* @throws {Error} if no files match pattern.
667-
* @throws {TypeError} if `filepath` is directory and `extensions` not provided.
668-
* @deprecated Moved to {@link module:lib/cli.lookupFiles}
669-
*/
670-
exports.lookupFiles = (...args) => {
671-
if (exports.isBrowser()) {
672-
throw errors.createUnsupportedError(
673-
'lookupFiles() is only supported in Node.js!'
674-
);
675-
}
676-
errors.deprecate(
677-
'`lookupFiles()` in module `mocha/lib/utils` has moved to module `mocha/lib/cli` and will be removed in the next major revision of Mocha'
678-
);
679-
return require('./cli').lookupFiles(...args);
680-
};
681-
682652
/*
683653
* Casts `value` to an array; useful for optionally accepting array parameters
684654
*

test/unit/utils.spec.js

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
'use strict';
33

44
var utils = require('../../lib/utils');
5-
const errors = require('../../lib/errors');
65
var sinon = require('sinon');
76

87
describe('lib/utils', function() {
@@ -779,51 +778,6 @@ describe('lib/utils', function() {
779778
});
780779
});
781780

782-
describe('lookupFiles()', function() {
783-
beforeEach(function() {
784-
sinon.stub(errors, 'deprecate');
785-
});
786-
787-
describe('when run in Node.js', function() {
788-
before(function() {
789-
if (process.browser) {
790-
return this.skip();
791-
}
792-
});
793-
794-
beforeEach(function() {
795-
sinon.stub(utils, 'isBrowser').returns(false);
796-
sinon.stub(require('../../lib/cli'), 'lookupFiles').returns([]);
797-
});
798-
799-
it('should print a deprecation message', function() {
800-
utils.lookupFiles();
801-
expect(errors.deprecate, 'was called once');
802-
});
803-
804-
it('should delegate to new location of lookupFiles()', function() {
805-
utils.lookupFiles(['foo']);
806-
expect(
807-
require('../../lib/cli').lookupFiles,
808-
'to have a call satisfying',
809-
[['foo']]
810-
).and('was called once');
811-
});
812-
});
813-
814-
describe('when run in browser', function() {
815-
beforeEach(function() {
816-
sinon.stub(utils, 'isBrowser').returns(true);
817-
});
818-
819-
it('should throw', function() {
820-
expect(() => utils.lookupFiles(['foo']), 'to throw', {
821-
code: 'ERR_MOCHA_UNSUPPORTED'
822-
});
823-
});
824-
});
825-
});
826-
827781
describe('uniqueID()', function() {
828782
it('should return a non-empty string', function() {
829783
expect(utils.uniqueID(), 'to be a string').and('not to be empty');

0 commit comments

Comments
 (0)