Skip to content
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

Using mock-fs to mock posting an image #58

Open
roc opened this issue Aug 26, 2015 · 2 comments
Open

Using mock-fs to mock posting an image #58

roc opened this issue Aug 26, 2015 · 2 comments

Comments

@roc
Copy link

roc commented Aug 26, 2015

I'm using mock-fs with supertest to test file uploads in an express application. I get hit with Error: ENOENT, no such file or directory messages from the endpoint, though in the context of the test the file is definitely present.

I've made a sample of my problem here: https://github.com/roc/mock-fs-supertest-express-example

Example response:

Error: ENOENT, no such file or directory 'public/images/c92a0180e347a9730417596326f3d166'
    at Binding.<anonymous> (mock-fs-supertest-express-example/node_modules/mock-fs/lib/binding.js:287:15)
    at maybeCallback (mock-fs-supertest-express-example/node_modules/mock-fs/lib/binding.js:27:18)
    at Binding.open (mock-fs-supertest-express-example/node_modules/mock-fs/lib/binding.js:274:10)
    at Object.fs.open (mock-fs-supertest-express-example/node_modules/mock-fs/node/fs-0.12.0.js:493:11)
    at WriteStream.open (mock-fs-supertest-express-example/node_modules/mock-fs/node/fs-0.12.0.js:1774:6)
    at new WriteStream (mock-fs-supertest-express-example/node_modules/mock-fs/node/fs-0.12.0.js:1764:10)
    at Object.fs.createWriteStream (mock-fs-supertest-express-example/node_modules/mock-fs/node/fs-0.12.0.js:1728:10)
    at mock-fs-supertest-express-example/node_modules/multer/storage/disk.js:38:26
    at Object.ondone (mock-fs-supertest-express-example/node_modules/multer/storage/disk.js:9:5)

I feel like I'm missing something fairly obvious (perhaps I just need to spy on the writing of the temporary file and return the same value?) though I'm unsure of the answer. Apologies if this turns out to not be directly to issues with mock-fs itself. I have working tests for actual files, but swapping out the large image file with a mocked file fails.

I will gladly contribute an idiots guide/express example PR if I can make sense of it, as I imagine this will be a fairly common use case for the library.

@jsonmaur
Copy link

@roc Did you ever figure this out? I'm having the same problem.

@junderhill
Copy link

@roc Having this same problem. Anyone know what we're doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants