Very strange behavior, multer freezes when used in testing with mock Date
See original GitHub issueHere’s a simple standalone example demonstrating this problem. The await upload(ctx)
function call freezes indefinitely when using in testing with a mock Date. If you run this code you’ll see before
printed to the console but not after
.
sinon.useFakeTimers({ shouldAdvanceTime: false })
is the trigger of the problem. If you change false
to true
, then it works. Both before
and after
will appear on the console immediately.
Why does multer depend on the time advancing, rather than having a static fixed time? It doesn’t seem like the time should cause any change in the behavior of multer.
This demo shows it using koa
and koa-multer
, but the same problem exists when using express
and multer
directly.
const Koa = require('koa')
const multer = require('koa-multer')
const request = require('supertest')
const sinon = require('sinon')
const pathToFile = '/tmp/file.txt'
let app = new Koa()
app.use(async (ctx) => {
const upload = multer().single('file')
await upload(ctx)
})
app = app.listen();
(async function run() {
sinon.useFakeTimers({ shouldAdvanceTime: false })
console.log('before')
await request(app)
.post('/')
.attach('file', pathToFile)
console.log('after')
})()
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
node.js - How to mock multer using jest/enzyme to file upload ...
When you use jest.mock('multer') , Jest automatically mocks the module and returns undefined when it gets called in the test.
Read more >postman request body file undefined - You.com | The search engine ...
I checked it because I used a mock endpoint to inspect the request payload ... I am using multer to do so, but...
Read more >How to upload a file in the React application with Node ...
Let's build the server with Node, Express, MongoDB and Multer for React file upload tutorial. Create the backend folder inside the React project....
Read more >Untitled
Sacramento 31 news channel, Love relationship test, Le voyage d oregon tapuscrit, ... 2015 bmw 7 series black, Cyndi lauper she's so unusual...
Read more >Railroad Grade Crossings: A Literature Review from 1990–2006
update a 1990 literature review titled, Driver Behavior at Rail-Highway ... Freight car reflectorization pattern used in the in-service revenue test ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
hi, I was able to reproduce the issue. Branch created here https://github.com/helio-frota/hold-my-file/tree/multer-558
But after search for it, this I found: https://github.com/sinonjs/sinon/issues/1925#issuecomment-429106284
So it seems to be an issue related to the sinon/lolex usage only. So I think this issue can be closed 👍
No problem. Maybe it’s an issue in the underlying
busboy
rather thanmulter
itself, but I guess you’ll be able to see that. 😃