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

ignore files which are not found by files() #2538

Merged
merged 3 commits into from
Nov 24, 2016
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
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
],
Expand Down
3 changes: 2 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

/**
Expand Down Expand Up @@ -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);
Expand Down
112 changes: 112 additions & 0 deletions test/acceptance/file-utils.spec.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
90 changes: 0 additions & 90 deletions test/acceptance/lookup-files.spec.js

This file was deleted.