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

Not working after upgrade to 1.1.6 in integration testing with mocha and supertest #187

Closed
Ks89 opened this issue Jan 2, 2020 · 9 comments

Comments

@Ks89
Copy link

Ks89 commented Jan 2, 2020

I'm having a weird issue after upgrading from 1.1.5 to 1.1.6.
I can't share the code, because it's closed and copyrighted but I'll try to explain a little bit the situation.

I'm having this issue while running tests with mocha and supertest.

This is my env:
macOS Catalina 10.15.2
iTerm2 with zsh as terminal
nodejs 12.14.0 and npm 6.13.4
All node modules are updated to the latest versions.

If I run npm test with version 1.1.5 everything is ok, but with 1.1.6 I receive this error:

 Uncaught TypeError: Cannot read property 'length' of undefined
      at parseFileName (node_modules/express-fileupload/lib/utilities.js:242:29)
      at Busboy.<anonymous> (node_modules/express-fileupload/lib/processMultipart.js:44:22)
      at Busboy.emit (node_modules/busboy/lib/main.js:37:33)
      at PartStream.<anonymous> (node_modules/busboy/lib/types/multipart.js:214:13)
      at HeaderParser.<anonymous> (node_modules/dicer/lib/Dicer.js:50:16)
      at HeaderParser._finish (node_modules/dicer/lib/HeaderParser.js:68:8)
      at SBMH.<anonymous> (node_modules/dicer/lib/HeaderParser.js:40:12)
      at SBMH._sbmh_feed (node_modules/streamsearch/lib/sbmh.js:159:14)
      at SBMH.push (node_modules/streamsearch/lib/sbmh.js:56:14)
      at HeaderParser.push (node_modules/dicer/lib/HeaderParser.js:46:19)
      at Dicer._oninfo (node_modules/dicer/lib/Dicer.js:196:25)
      at SBMH.<anonymous> (node_modules/dicer/lib/Dicer.js:126:10)
      at SBMH._sbmh_feed (node_modules/streamsearch/lib/sbmh.js:159:14)
      at SBMH.push (node_modules/streamsearch/lib/sbmh.js:56:14)
      at Dicer._write (node_modules/dicer/lib/Dicer.js:108:17)
      at doWrite (_stream_writable.js:431:12)
      at writeOrBuffer (_stream_writable.js:415:5)
      at Dicer.Writable.write (_stream_writable.js:305:11)
      at Multipart.write (node_modules/busboy/lib/types/multipart.js:291:24)
      at Busboy._write (node_modules/busboy/lib/main.js:80:16)
      at doWrite (_stream_writable.js:431:12)
      at writeOrBuffer (_stream_writable.js:415:5)
      at Busboy.Writable.write (_stream_writable.js:305:11)
      at IncomingMessage.ondata (_stream_readable.js:727:22)
      at IncomingMessage.Readable.read (_stream_readable.js:525:10)
      at flow (_stream_readable.js:1000:34)
      at resume_ (_stream_readable.js:981:3)
      at processTicksAndRejections (internal/process/task_queues.js:80:21)

I defined express-fileupload in my app.js as express middleware, as alway.
Also, in my tests I'm using this code to upload files:

rest_api_with_supertest.attach('file', FILE_AS_A_BUFFER).expect(200)

I'm sure that is something related to your package, because if I force version "=1.1.5" in my package.json everything works as expected, but not with version 1.1.6.

@Ks89
Copy link
Author

Ks89 commented Jan 2, 2020

some tests fails with the error above, but others with this one:

TypeError: Cannot read property 'call' of undefined
      at processImmediate (internal/timers.js:439:21)

@Ks89
Copy link
Author

Ks89 commented Jan 2, 2020

Probably it's something related to file uploads as "Buffer".
I need to use buffer and with supertest, it seems impossible to specify a file name in this case.

@JackHull
Copy link

JackHull commented Jan 6, 2020

I'm encountering the same error. When in debug mode on a local machine, everything works fine. When running the application as production inside a Docker container, I get this exact error message. I have been using the latest version, will try downgrading to 1.1.5 now.

Update: On 1.1.5 everything is working as expected. This definitely is a bug in the newest version.

@RomanBurunkov
Copy link
Collaborator

Hi @Ks89 ,

From trace you shared it looks that you send empty file name.
Did I understand that correct?

@RomanBurunkov
Copy link
Collaborator

I have two ideas regarding to this issue:

  1. Set name to empty string if it hasn't been set.
  2. Set name to temporary file name like tmp-1-15464564546456

@Ks89
Copy link
Author

Ks89 commented Jan 6, 2020

Yes, probably it's because I didn't set the name, but the problem is that I don't know how to set the name in case of integration testing with supertest. Filename is something in the header of the request?

@r3wt
Copy link
Contributor

r3wt commented Jan 6, 2020 via email

@Ks89
Copy link
Author

Ks89 commented Jan 6, 2020

Do you have any suggestion about the name of this header to set it manually into supertest?

@RomanBurunkov
Copy link
Collaborator

PR #207 fixes this issue.
Now parseFileName function return a temporary file name if no file name specified.

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

No branches or pull requests

4 participants