-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ignore files files which are not found by files() (#2538)
* rename lookup-files.spec.js to file-utils.spec.js * .files should not choke on broken symlinks
- Loading branch information
Showing
4 changed files
with
115 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.