diff options
Diffstat (limited to 'tests/lib/mocha-3.1.0/test/acceptance/lookup-files.spec.js')
-rw-r--r-- | tests/lib/mocha-3.1.0/test/acceptance/lookup-files.spec.js | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/lib/mocha-3.1.0/test/acceptance/lookup-files.spec.js b/tests/lib/mocha-3.1.0/test/acceptance/lookup-files.spec.js new file mode 100644 index 0000000000..5d4a48d8af --- /dev/null +++ b/tests/lib/mocha-3.1.0/test/acceptance/lookup-files.spec.js @@ -0,0 +1,90 @@ +'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); + } +}); |