☕️ Classic, reliable, trusted test framework for Node.js and the browser
ignore files files which are not found by files() (#2538)
Ville Saukkonen4a2e85a5b88c
diff --git a/karma.conf.js b/karma.conf.jsindex 8a85bf35..84195cbf 100644--- a/karma.conf.js+++ b/karma.conf.js@@ -23,7 +23,7 @@ module.exports = function (config) {exclude: ['test/acceptance/http.spec.js','test/acceptance/fs.spec.js',- 'test/acceptance/lookup-files.spec.js',+ 'test/acceptance/file-utils.spec.js','test/acceptance/require/**/*.js','test/acceptance/misc/**/*.js'],diff --git a/lib/utils.js b/lib/utils.jsindex 2af3aac4..bf430b91 100644--- a/lib/utils.js+++ b/lib/utils.js@@ -16,6 +16,7 @@ var join = path.join;var readdirSync = require('fs').readdirSync;var statSync = require('fs').statSync;var watchFile = require('fs').watchFile;+var lstatSync = require('fs').lstatSync;var toISOString = require('./to-iso-string');/**@@ -252,7 +253,7 @@ exports.files = function (dir, ext, ret) {.filter(ignored).forEach(function (path) {path = join(dir, path);- if (statSync(path).isDirectory()) {+ if (lstatSync(path).isDirectory()) {exports.files(path, ext, ret);} else if (path.match(re)) {ret.push(path);diff --git a/test/acceptance/file-utils.spec.js b/test/acceptance/file-utils.spec.jsnew file mode 100644index 00000000..12dbddf8--- /dev/null+++ b/test/acceptance/file-utils.spec.js@@ -0,0 +1,112 @@+'use strict';++var utils = require('../../lib/utils');+var fs = require('fs');+var path = require('path');+var os = require('os');+var mkdirp = require('mkdirp');+var rimraf = require('rimraf');++describe('file utils', function () {+ var tmpDir = path.join(os.tmpDir(), 'mocha-file-lookup');+ var existsSync = fs.existsSync;+ var tmpFile = path.join.bind(path, tmpDir);+ var symlinkSupported = false;++ (function testSymlinkSupport () {+ makeTempDir();++ fs.writeFileSync(tmpFile('mocha-utils.js'), 'yippy skippy ying yang yow');+ try {+ fs.symlinkSync(tmpFile('mocha-utils.js'), tmpFile('mocha-utils-link.js'));+ symlinkSupported = true;+ } catch (ignored) {+ // ignored+ } finally {+ removeTempDir();+ }+ }());++ beforeEach(function () {+ makeTempDir();++ fs.writeFileSync(tmpFile('mocha-utils.js'), 'yippy skippy ying yang yow');+ if (symlinkSupported) {+ fs.symlinkSync(tmpFile('mocha-utils.js'), tmpFile('mocha-utils-link.js'));+ }+ });++ describe('.lookupFiles', function () {+ (symlinkSupported ? it : it.skip)('should not return broken symlink file path', function () {+ expect(utils.lookupFiles(tmpDir, ['js'], false))+ .to+ .contain(tmpFile('mocha-utils-link.js'))+ .and+ .contain(tmpFile('mocha-utils.js'))+ .and+ .have+ .length(2);+ expect(existsSync(tmpFile('mocha-utils-link.js')))+ .to+ .be(true);+ fs.renameSync(tmpFile('mocha-utils.js'), tmpFile('bob'));+ expect(existsSync(tmpFile('mocha-utils-link.js')))+ .to+ .be(false);+ expect(utils.lookupFiles(tmpDir, ['js'], false))+ .to+ .eql([]);+ });++ it('should accept a glob "path" value', function () {+ var res = utils.lookupFiles(tmpFile('mocha-utils*'), ['js'], false)+ .map(path.normalize.bind(path));++ var expectedLength = 0;+ var ex = expect(res)+ .to+ .contain(tmpFile('mocha-utils.js'));+ expectedLength++;++ if (symlinkSupported) {+ ex = ex.and+ .contain(tmpFile('mocha-utils-link.js'));+ expectedLength++;+ }++ ex.and+ .have+ .length(expectedLength);+ });+ });++ describe('.files', function () {+ (symlinkSupported ? it : it.skip)('should return broken symlink file path', function () {+ expect(utils.files(tmpDir, ['js']))+ .to.contain(tmpFile('mocha-utils-link.js'))+ .and.contain(tmpFile('mocha-utils.js'))+ .and.have.length(2);++ expect(existsSync(tmpFile('mocha-utils-link.js')))+ .to.be(true);++ fs.renameSync(tmpFile('mocha-utils.js'), tmpFile('bob'));++ expect(existsSync(tmpFile('mocha-utils-link.js')))+ .to.be(false);++ expect(utils.files(tmpDir, ['js']))+ .to.eql([tmpFile('mocha-utils-link.js')]);+ });+ });++ afterEach(removeTempDir);++ function makeTempDir () {+ mkdirp.sync(tmpDir);+ }++ function removeTempDir () {+ rimraf.sync(tmpDir);+ }+});diff --git a/test/acceptance/lookup-files.spec.js b/test/acceptance/lookup-files.spec.jsdeleted file mode 100644index faf31b13..00000000--- a/test/acceptance/lookup-files.spec.js+++ /dev/null@@ -1,90 +0,0 @@-'use strict';--var utils = require('../../lib/utils');-var fs = require('fs');-var path = require('path');-var os = require('os');-var mkdirp = require('mkdirp');-var rimraf = require('rimraf');--describe('lookupFiles', function () {- var tmpDir = path.join(os.tmpDir(), 'mocha-lookup-files');- var existsSync = fs.existsSync;- var tmpFile = path.join.bind(path, tmpDir);- var symlinkSupported = false;-- (function testSymlinkSupport () {- makeTempDir();-- fs.writeFileSync(tmpFile('mocha-utils.js'), 'yippy skippy ying yang yow');- try {- fs.symlinkSync(tmpFile('mocha-utils.js'), tmpFile('mocha-utils-link.js'));- symlinkSupported = true;- } catch (ignored) {- // ignored- } finally {- removeTempDir();- }- }());-- beforeEach(function () {- makeTempDir();-- fs.writeFileSync(tmpFile('mocha-utils.js'), 'yippy skippy ying yang yow');- if (symlinkSupported) {- fs.symlinkSync(tmpFile('mocha-utils.js'), tmpFile('mocha-utils-link.js'));- }- });-- (symlinkSupported ? it : it.skip)('should not choke on symlinks', function () {- expect(utils.lookupFiles(tmpDir, ['js'], false))- .to- .contain(tmpFile('mocha-utils-link.js'))- .and- .contain(tmpFile('mocha-utils.js'))- .and- .have- .length(2);- expect(existsSync(tmpFile('mocha-utils-link.js')))- .to- .be(true);- fs.renameSync(tmpFile('mocha-utils.js'), tmpFile('bob'));- expect(existsSync(tmpFile('mocha-utils-link.js')))- .to- .be(false);- expect(utils.lookupFiles(tmpDir, ['js'], false))- .to- .eql([]);- });-- it('should accept a glob "path" value', function () {- var res = utils.lookupFiles(tmpFile('mocha-utils*'), ['js'], false)- .map(path.normalize.bind(path));-- var expectedLength = 0;- var ex = expect(res)- .to- .contain(tmpFile('mocha-utils.js'));- expectedLength++;-- if (symlinkSupported) {- ex = ex.and- .contain(tmpFile('mocha-utils-link.js'));- expectedLength++;- }-- ex.and- .have- .length(expectedLength);- });-- afterEach(removeTempDir);-- function makeTempDir () {- mkdirp.sync(tmpDir);- }-- function removeTempDir () {- rimraf.sync(tmpDir);- }-});