-
-
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.
Based on work by Tyler Waters <tyler.waters@gmail.com> in #1814. Changes from #1814 include: - Rebasing - Use process.argv[0] as an authoritative path for Node.js executable - Support having spaces in path of Node.js executable - Avoid external dependencies for child_process.spawn() - Fix symlink tests on Windows. On Windows, creating symlinks can fail since it needs additional user permissions Fixes #1813.
- Loading branch information
Showing
11 changed files
with
173 additions
and
137 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
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 |
---|---|---|
@@ -1,56 +1,79 @@ | ||
var utils = require('../../lib/utils'); | ||
|
||
describe('lookupFiles', function() { | ||
var fs = require('fs'), path = require('path'), existsSync = fs.existsSync || | ||
path.existsSync; | ||
var fs = require('fs'), | ||
path = require('path'), | ||
existsSync = fs.existsSync || path.existsSync, | ||
tmpdir = require('os-tmpdir')(), | ||
t = path.join.bind(path, tmpdir), | ||
symlinkSupported = false; | ||
|
||
fs.writeFileSync(t('mocha-utils.js'), 'yippy skippy ying yang yow'); | ||
try { | ||
fs.symlinkSync(t('mocha-utils.js'), t('mocha-utils-link.js')); | ||
symlinkSupported = true; | ||
} catch (ignored) { | ||
} | ||
|
||
cleanup(); | ||
|
||
beforeEach(function() { | ||
fs.writeFileSync('/tmp/mocha-utils.js', 'yippy skippy ying yang yow'); | ||
fs.symlinkSync('/tmp/mocha-utils.js', '/tmp/mocha-utils-link.js'); | ||
fs.writeFileSync(t('mocha-utils.js'), 'yippy skippy ying yang yow'); | ||
if (symlinkSupported) { | ||
fs.symlinkSync(t('mocha-utils.js'), t('mocha-utils-link.js')); | ||
} | ||
}); | ||
|
||
it('should not choke on symlinks', function() { | ||
expect(utils.lookupFiles('/tmp', ['js'], false)) | ||
(symlinkSupported ? it : it.skip)('should not choke on symlinks', function() { | ||
expect(utils.lookupFiles(tmpdir, ['js'], false)) | ||
.to | ||
.contain('/tmp/mocha-utils-link.js') | ||
.contain(t('mocha-utils-link.js')) | ||
.and | ||
.contain('/tmp/mocha-utils.js') | ||
.contain(t('mocha-utils.js')) | ||
.and | ||
.have | ||
.length(2); | ||
expect(existsSync('/tmp/mocha-utils-link.js')) | ||
expect(existsSync(t('mocha-utils-link.js'))) | ||
.to | ||
.be(true); | ||
fs.renameSync('/tmp/mocha-utils.js', '/tmp/bob'); | ||
expect(existsSync('/tmp/mocha-utils-link.js')) | ||
fs.renameSync(t('mocha-utils.js'), t('bob')); | ||
expect(existsSync(t('mocha-utils-link.js'))) | ||
.to | ||
.be(false); | ||
expect(utils.lookupFiles('/tmp', ['js'], false)) | ||
expect(utils.lookupFiles(tmpdir, ['js'], false)) | ||
.to | ||
.eql([]); | ||
}); | ||
|
||
it('should accept a glob "path" value', function() { | ||
expect(utils.lookupFiles('/tmp/mocha-utils*', ['js'], false)) | ||
var res = utils.lookupFiles(t('mocha-utils*'), ['js'], false) | ||
.map(path.normalize.bind(path)); | ||
var ex = expect(res) | ||
.to | ||
.contain('/tmp/mocha-utils-link.js') | ||
.and | ||
.contain('/tmp/mocha-utils.js') | ||
.and | ||
.contain(t('mocha-utils.js')); | ||
|
||
if (symlinkSupported) { | ||
ex = ex.and | ||
.contain(t('mocha-utils-link.js')); | ||
} | ||
|
||
ex.and | ||
.have | ||
.length(2); | ||
.length(1 + (+symlinkSupported)); | ||
}); | ||
|
||
afterEach(function() { | ||
afterEach(cleanup); | ||
|
||
function cleanup() { | ||
[ | ||
'/tmp/mocha-utils.js', | ||
'/tmp/mocha-utils-link.js', | ||
'/tmp/bob' | ||
'mocha-utils.js', | ||
'mocha-utils-link.js', | ||
'bob' | ||
].forEach(function(path) { | ||
try { | ||
fs.unlinkSync(path); | ||
fs.unlinkSync(t(path)); | ||
} catch (ignored) { | ||
} | ||
}); | ||
}); | ||
} | ||
}); |
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
Oops, something went wrong.