-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix extension and spec handling; closes #3808 #3834
Conversation
lib/utils.js
Outdated
return true; | ||
} | ||
}) | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason this was here was to allow the historical usage of "test.js" via the default spec "test". IMO, we should not propagate this further.
The "Handle directory" code below already handles extensions for "test/*".
lib/cli/options.js
Outdated
@@ -10,7 +10,8 @@ const fs = require('fs'); | |||
const yargsParser = require('yargs-parser'); | |||
const {types, aliases} = require('./run-option-metadata'); | |||
const {ONE_AND_DONE_ARGS} = require('./one-and-dones'); | |||
const mocharc = require('../mocharc.json'); | |||
// paranoia | |||
const mocharc = Object.freeze(require('../mocharc.json')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const rcDefaults = Object.freeze(require('../mocharc.json'));
Rebase |
I think there is a standard yargs way to achieve this, using the "default" option. I just did some short testing, nevertheless it seems to work. // line 109
const result = yargsParser.detailed(args, {
default: {extension: ["js"]}, // set default values with "mocharc"
configuration,
configObjects,
coerce: coerceOpts,
narg: nargOpts,
alias: aliases,
string: types.string,
array: types.array,
number: types.number,
boolean: types.boolean.concat(nodeArgs.map(pair => pair[0]))
}); // line 326
args = parse(
args._,
args,
rcConfig || {},
pkgConfig || {},
optsConfig || {},
//mocharc don't set default values here
); |
@juergba Hmm, you're right. I think instead of this strategy, I'll change it so that we can still keep the default config in our |
Also in "lib/cli/run-helpers.js" the default extension of "js" is set hardcoded several times. |
@boneskull is it ok for you, if I work on this one? |
253100d
to
847a331
Compare
@juergba yes, go ahead |
03da22c
to
9a18cd7
Compare
utils.js: fix lookupFiles()
9a18cd7
to
2d1dc34
Compare
@juergba second time now you merged without any review (despite prior request to do otherwise) and this time you introduced bug... |
Corrected code... "lib/utils.js" /**
* 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
* @memberof Mocha.utils
* @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 file pathnames.
* @throws {Error} if no files match pattern.
* @throws {TypeError} if `filepath` is directory and `extensions` not provided or empty.
*/
exports.lookupFiles = function lookupFiles(filepath, extensions, recursive) {
var files = [];
var stat;
if (extensions === undefined) {
extensions = [];
}
if (recursive === undefined) {
recursive = false;
}
if (!fs.existsSync(filepath)) {
// Check all extensions, using first match found (if any)
if (
!(extensions.some(function(ext) {
var filepathWithExtname = filepath + '.' + ext;
if (fs.existsSync(filepathWithExtname)) {
filepath = filepathWithExtname;
return true;
}
})
) {
// Handle glob
files = glob.sync(filepath);
if (!files.length) {
throw createNoFilesMatchPatternError(
'Cannot find any files matching pattern ' + exports.dQuote(filepath),
filepath
);
}
return files;
}
}
// ...no further changes to merged code...
} |
@plroebuck
|
As I commented originally in his PR, the part of the code that added ".js" should probably have been left alone as an anachronism; it allows "test.js" to satisfy Mocha's default, rather than just putting spec files in a "test" directory. But To bust your PR, create a directory named "test.js" and run Please use the corrected code above to fix this. |
True, but almost no PRs here are ever critical; they can sit until needed. Create your PR and add "NeedsReview" tag when ready; make sure and add reviewers (especially ones who might actually do so). Then give it a week. If no one reviewed it by that point, make comment on the PR announcing intent to merge within |
You are right, a directory named "test.js" will fail. I will open a PR and use your proposition. I don't agree completely, though. With two files (eg. "unit.ts" and "unit.js") a call "unit" plus extension: ['ts', 'js'] should return both files, not just some/the first one. EDIT: the glob returns files and directories, so this function has never really worked correctly. The directories could be skipped with see #3905
I can live with that procedure. |
The If a package is exporting functions in more than one language, its specifications should live in the "test" directory -- the simplistic specification scheme above shouldn't apply. |
Also fixes some issues in the options unit tests and adds coverage around
spec
handling.This needs some manual testing, as I had to monkey with
watch
a bit.cc @dedene