-
-
Notifications
You must be signed in to change notification settings - Fork 770
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
Stubbing fs.readFileSync fails since 1.8.1 #458
Comments
This pull request closes issue sinonjs#458 by implementing a test that shows that it is possible to stub fs.readFileSync. I've run the tests on node 0.10.25 and 0.10.29 and cannot reproduce the bug.
This pull request closes issue sinonjs#458 by implementing a test that shows that it is possible to stub fs.readFileSync. I've run the tests on node 0.10.25 and 0.10.29 and cannot reproduce the bug.
Close #458 by proving that there is no failure
Thanks for the test case.... I'll check again on my side to see if I can still reproduce it. |
I can recreate this everytime - it is specific to coffee script....
crashes with coffee, but not node. CoffeeScript v1.7.1 Stack trace... TypeError: Cannot call method 'charCodeAt' of undefined |
… in coffeescript
I also get this issue, in javascript... what should I add to usefully prove this? |
Is the code open source? Have you tried upgrading to a later version of sinon? |
@fearphage didn't have any free time to reproduce this until now. Here's an example with |
@roc Your test case is broken. There are no passing tests. Fix it and I'll check it out. ➜ sinon-filesync git:(master) mocha
loading a file and printing it
1) should say hello m8
replace file contents
2) "before all" hook
0 passing (13ms)
2 failing
1) loading a file and printing it should say hello m8:
TypeError: Cannot read property 'charCodeAt' of undefined
at Object.stripBOM (internal/module.js:48:14)
at require (internal/module.js:20:19)
at Context.it (test/index.js:11:17)
2) replace file contents "before all" hook:
TypeError: Cannot read property 'charCodeAt' of undefined
at Object.stripBOM (internal/module.js:48:14)
at Object.require.extensions.(anonymous function) (node_modules/proxyquire/lib/proxyquire.js:259:43)
at Proxyquire._withoutCache (node_modules/proxyquire/lib/proxyquire.js:179:12)
at Proxyquire.load (node_modules/proxyquire/lib/proxyquire.js:136:15)
at Context.before (test/index.js:22:11) |
'use strict'
const file = require('fs').readFileSync(
__dirname + '/file.txt', 'utf8'
);
module.exports = `hello ${file}`; The way your code is written you'll never be able to mock it out without something like const fs = require('fs');
module.exports = function() {
return `hello ${fs.readFileSync(...)}`;
}; Here's an example of it working for someone else: http://stackoverflow.com/questions/18044737/mock-fs-readdir-for-testing |
In Sinon
1.7.0
, the following works as expected:Later versions seem to throw:
Unfortunately I can't seem to get a real stack trace for the error. Stubbing
fs.readFile
(not sync) works fine, and I'm running Nodev0.10.25
.The text was updated successfully, but these errors were encountered: