Skip to content

Commit b216fcd

Browse files
Support multipart extensions like ".test.js" (#4442)
* failing test to support multipart extensions * support multipart extensions * test against non-extension suffix * ensure an extension is being matched
1 parent 1aa182b commit b216fcd

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

lib/cli/lookup-files.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ function isHiddenOnUnix(pathname) {
4545
* hasMatchingExtname('foo.html', ['js', 'css']); // => false
4646
*/
4747
function hasMatchingExtname(pathname, exts) {
48-
var suffix = path.extname(pathname).slice(1);
4948
return exts.some(function(element) {
50-
return suffix === element;
49+
return pathname.endsWith('.' + element);
5150
});
5251
}
5352

test/integration/file-utils.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,34 @@ describe('file utils', function() {
9393
).and('to have length', 2);
9494
});
9595

96+
it('should return ".test.js" files', function() {
97+
fs.writeFileSync(
98+
tmpFile('mocha-utils.test.js'),
99+
'i have a multipart extension'
100+
);
101+
var res = lookupFiles(tmpDir, ['test.js'], false).map(
102+
path.normalize.bind(path)
103+
);
104+
expect(res, 'to contain', tmpFile('mocha-utils.test.js')).and(
105+
'to have length',
106+
1
107+
);
108+
});
109+
110+
it('should return not return "*test.js" files', function() {
111+
fs.writeFileSync(
112+
tmpFile('mocha-utils-test.js'),
113+
'i do not have a multipart extension'
114+
);
115+
var res = lookupFiles(tmpDir, ['test.js'], false).map(
116+
path.normalize.bind(path)
117+
);
118+
expect(res, 'not to contain', tmpFile('mocha-utils-test.js')).and(
119+
'to have length',
120+
0
121+
);
122+
});
123+
96124
it('should require the extensions parameter when looking up a file', function() {
97125
var dirLookup = function() {
98126
return lookupFiles(tmpFile('mocha-utils'), undefined, false);

0 commit comments

Comments
 (0)