-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Support test suite on Windows #2270
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
}); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the expected length, I'd rather see something like: // at start of test
var expectedLength = 0;
//...after the .contain(t('mocha-utils.js'));
expectedLength += 1;
//...after the .contain(t('mocha-utils-link.js'));
expectedLength += 1;
//...instead of .length(1 + (+symlinkSupported));
.length(expectedLength); This is, in my opinion, clearer than using the unary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In agreement. |
||
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) { | ||
} | ||
}); | ||
}); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: go through the test suites and find things like this that are failure-tests but either commented out or otherwise unusually handled and if possible change them to assert that the failure throws or passes an error to a callback or whatever the expectable failure mode is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YES ^
Edit: I've pointed this out every now and then. Tests that we have to manually check / uncomment => please no.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this into its own issue, since it's nothing to do with this PR: #2309