question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Very strange behavior, multer freezes when used in testing with mock Date

See original GitHub issue

Here’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:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
helio-frotacommented, Nov 6, 2019

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 👍

1reaction
rightawaycommented, Nov 6, 2019

No problem. Maybe it’s an issue in the underlying busboy rather than multer itself, but I guess you’ll be able to see that. 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found