Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

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

Jordan Stephensb216fcd9b30c
diff --git a/lib/cli/lookup-files.js b/lib/cli/lookup-files.js
index c4920484..81e9c261 100644
--- a/lib/cli/lookup-files.js
+++ b/lib/cli/lookup-files.js
@@ -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);
});
}
diff --git a/test/integration/file-utils.spec.js b/test/integration/file-utils.spec.js
index 9b8f86e7..3075bbfe 100644
--- a/test/integration/file-utils.spec.js
+++ b/test/integration/file-utils.spec.js
@@ -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);