-
-
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. This commit contains the following changes: - Add quotation marks to Makefile variables for programs. The variables use POSIX-style paths, which cannot be used on Windows to launch a program except when quoted. Using double quotation marks instead of single since the latter is not available on Windows - Use os-tmpdir module to get an acceptable directory for temporary usage instead of relying on the POSIX /tmp - Use process.execPath as an authoritative path for Node.js executable - Detect whether symbolic links are supported on the platform before testing. On Windows, creating symlinks can fail since it needs additional user permissions - Fix hook tests. The tests parse output of the "dot" reporter to separate output of individual tests. The "dot" reporter uses "·" symbol (U+2024 ONE DOT LEADER) under POSIX environments and "." symbol (U+002E FULL STOP) under Windows, which means that having "." in the echoed message makes it ambiguous to be parsed in Windows. To fix this issue, two separate changes are necessary: - Use a dynamically created regular expression to split the tests based on the specific dot character used on the platform - Replace "." with "-" in echoed messages in fixtures for hook tests to avoid ambiguity with the character output by the reporter Changes from #1814 include: - Rebasing - Use process.execPath as an authoritative path for Node.js executable - Avoid external dependencies for child_process.spawn() - Detect whether symbol links are supported on the platform before testing. On Windows, creating symlinks can fail since it needs additional user permissions Fixes #1813.
- Loading branch information
Showing
12 changed files
with
190 additions
and
144 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
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,83 @@ | ||
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')(), | ||
tmpFile = path.join.bind(path, tmpDir), | ||
symlinkSupported = false; | ||
|
||
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) { | ||
} | ||
|
||
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(tmpFile('mocha-utils.js'), 'yippy skippy ying yang yow'); | ||
if (symlinkSupported) { | ||
fs.symlinkSync(tmpFile('mocha-utils.js'), tmpFile('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(tmpFile('mocha-utils-link.js')) | ||
.and | ||
.contain('/tmp/mocha-utils.js') | ||
.contain(tmpFile('mocha-utils.js')) | ||
.and | ||
.have | ||
.length(2); | ||
expect(existsSync('/tmp/mocha-utils-link.js')) | ||
expect(existsSync(tmpFile('mocha-utils-link.js'))) | ||
.to | ||
.be(true); | ||
fs.renameSync('/tmp/mocha-utils.js', '/tmp/bob'); | ||
expect(existsSync('/tmp/mocha-utils-link.js')) | ||
fs.renameSync(tmpFile('mocha-utils.js'), tmpFile('bob')); | ||
expect(existsSync(tmpFile('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(tmpFile('mocha-utils*'), ['js'], false) | ||
.map(path.normalize.bind(path)); | ||
|
||
var expectedLength = 0; | ||
var ex = expect(res) | ||
.to | ||
.contain('/tmp/mocha-utils-link.js') | ||
.and | ||
.contain('/tmp/mocha-utils.js') | ||
.and | ||
.contain(tmpFile('mocha-utils.js')); | ||
expectedLength++; | ||
|
||
if (symlinkSupported) { | ||
ex = ex.and | ||
.contain(tmpFile('mocha-utils-link.js')); | ||
expectedLength++; | ||
} | ||
|
||
ex.and | ||
.have | ||
.length(2); | ||
.length(expectedLength); | ||
}); | ||
|
||
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(tmpFile(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.