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

Support multipart extensions like ".test.js" #4442

Merged
merged 4 commits into from
Oct 9, 2020
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
3 changes: 1 addition & 2 deletions lib/cli/lookup-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ function isHiddenOnUnix(pathname) {
* hasMatchingExtname('foo.html', ['js', 'css']); // => false
*/
function hasMatchingExtname(pathname, exts) {
var suffix = path.extname(pathname).slice(1);
return exts.some(function(element) {
return suffix === element;
return pathname.endsWith('.' + element);
});
}

Expand Down
28 changes: 28 additions & 0 deletions test/integration/file-utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,34 @@ describe('file utils', function() {
).and('to have length', 2);
});

it('should return ".test.js" files', function() {
fs.writeFileSync(
tmpFile('mocha-utils.test.js'),
'i have a multipart extension'
);
var res = lookupFiles(tmpDir, ['test.js'], false).map(
path.normalize.bind(path)
);
expect(res, 'to contain', tmpFile('mocha-utils.test.js')).and(
'to have length',
1
);
});

it('should return not return "*test.js" files', function() {
fs.writeFileSync(
tmpFile('mocha-utils-test.js'),
'i do not have a multipart extension'
);
var res = lookupFiles(tmpDir, ['test.js'], false).map(
path.normalize.bind(path)
);
expect(res, 'not to contain', tmpFile('mocha-utils-test.js')).and(
'to have length',
0
);
});

it('should require the extensions parameter when looking up a file', function() {
var dirLookup = function() {
return lookupFiles(tmpFile('mocha-utils'), undefined, false);
Expand Down