Skip to content

Commit

Permalink
Support multipart extensions like ".test.js" (#4442)
Browse files Browse the repository at this point in the history
* failing test to support multipart extensions

* support multipart extensions

* test against non-extension suffix

* ensure an extension is being matched
  • Loading branch information
jordanstephens committed Oct 9, 2020
1 parent 1aa182b commit b216fcd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/cli/lookup-files.js
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
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

0 comments on commit b216fcd

Please sign in to comment.