From 1b5cbf131eff4e1858cdfe7a1a7d201664c767dc Mon Sep 17 00:00:00 2001 From: Juerg B <44573692+juergba@users.noreply.github.com> Date: Thu, 27 May 2021 15:00:39 +0200 Subject: [PATCH] Remove deprecated "utils.lookupFiles()" (#4636) --- lib/cli/lookup-files.js | 10 ++------- lib/utils.js | 30 --------------------------- test/unit/utils.spec.js | 46 ----------------------------------------- 3 files changed, 2 insertions(+), 84 deletions(-) diff --git a/lib/cli/lookup-files.js b/lib/cli/lookup-files.js index 0ad957c4b2..00b98a7a7e 100644 --- a/lib/cli/lookup-files.js +++ b/lib/cli/lookup-files.js @@ -8,11 +8,9 @@ var fs = require('fs'); var path = require('path'); var glob = require('glob'); -var {format} = require('util'); var errors = require('../errors'); var createNoFilesMatchPatternError = errors.createNoFilesMatchPatternError; var createMissingArgumentError = errors.createMissingArgumentError; -var {sQuote, dQuote} = require('../utils'); const debug = require('debug')('mocha:cli:lookup-files'); /** @@ -91,7 +89,7 @@ module.exports = function lookupFiles( files.push(...glob.sync(pattern, {nodir: true})); if (!files.length) { throw createNoFilesMatchPatternError( - 'Cannot find any files matching pattern ' + dQuote(filepath), + `Cannot find any files matching pattern "${filepath}"`, filepath ); } @@ -127,11 +125,7 @@ module.exports = function lookupFiles( } if (!extensions.length) { throw createMissingArgumentError( - format( - 'Argument %s required when argument %s is a directory', - sQuote('extensions'), - sQuote('filepath') - ), + `Argument '${extensions}' required when argument '${filepath}' is a directory`, 'extensions', 'array' ); diff --git a/lib/utils.js b/lib/utils.js index c2c5a9573e..e46eac8d1a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -13,7 +13,6 @@ const {nanoid} = require('nanoid/non-secure'); var path = require('path'); var util = require('util'); var he = require('he'); -const errors = require('./errors'); const MOCHA_ID_PROP_NAME = '__mocha_id__'; @@ -650,35 +649,6 @@ exports.isBrowser = function isBrowser() { return Boolean(process.browser); }; -/** - * Lookup file names at the given `path`. - * - * @description - * Filenames are returned in _traversal_ order by the OS/filesystem. - * **Make no assumption that the names will be sorted in any fashion.** - * - * @public - * @alias module:lib/cli.lookupFiles - * @param {string} filepath - Base path to start searching from. - * @param {string[]} [extensions=[]] - File extensions to look for. - * @param {boolean} [recursive=false] - Whether to recurse into subdirectories. - * @return {string[]} An array of paths. - * @throws {Error} if no files match pattern. - * @throws {TypeError} if `filepath` is directory and `extensions` not provided. - * @deprecated Moved to {@link module:lib/cli.lookupFiles} - */ -exports.lookupFiles = (...args) => { - if (exports.isBrowser()) { - throw errors.createUnsupportedError( - 'lookupFiles() is only supported in Node.js!' - ); - } - errors.deprecate( - '`lookupFiles()` in module `mocha/lib/utils` has moved to module `mocha/lib/cli` and will be removed in the next major revision of Mocha' - ); - return require('./cli').lookupFiles(...args); -}; - /* * Casts `value` to an array; useful for optionally accepting array parameters * diff --git a/test/unit/utils.spec.js b/test/unit/utils.spec.js index a04495a09a..53d4f20f32 100644 --- a/test/unit/utils.spec.js +++ b/test/unit/utils.spec.js @@ -2,7 +2,6 @@ 'use strict'; var utils = require('../../lib/utils'); -const errors = require('../../lib/errors'); var sinon = require('sinon'); describe('lib/utils', function() { @@ -779,51 +778,6 @@ describe('lib/utils', function() { }); }); - describe('lookupFiles()', function() { - beforeEach(function() { - sinon.stub(errors, 'deprecate'); - }); - - describe('when run in Node.js', function() { - before(function() { - if (process.browser) { - return this.skip(); - } - }); - - beforeEach(function() { - sinon.stub(utils, 'isBrowser').returns(false); - sinon.stub(require('../../lib/cli'), 'lookupFiles').returns([]); - }); - - it('should print a deprecation message', function() { - utils.lookupFiles(); - expect(errors.deprecate, 'was called once'); - }); - - it('should delegate to new location of lookupFiles()', function() { - utils.lookupFiles(['foo']); - expect( - require('../../lib/cli').lookupFiles, - 'to have a call satisfying', - [['foo']] - ).and('was called once'); - }); - }); - - describe('when run in browser', function() { - beforeEach(function() { - sinon.stub(utils, 'isBrowser').returns(true); - }); - - it('should throw', function() { - expect(() => utils.lookupFiles(['foo']), 'to throw', { - code: 'ERR_MOCHA_UNSUPPORTED' - }); - }); - }); - }); - describe('uniqueID()', function() { it('should return a non-empty string', function() { expect(utils.uniqueID(), 'to be a string').and('not to be empty');