Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated "utils.lookupFiles()" #4636

Merged
merged 2 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions lib/cli/lookup-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

/**
Expand Down Expand Up @@ -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
);
}
Expand Down Expand Up @@ -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'
);
Expand Down
30 changes: 0 additions & 30 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__';

Expand Down Expand Up @@ -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
*
Expand Down
46 changes: 0 additions & 46 deletions test/unit/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
'use strict';

var utils = require('../../lib/utils');
const errors = require('../../lib/errors');
var sinon = require('sinon');

describe('lib/utils', function() {
Expand Down Expand Up @@ -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');
Expand Down