I've asked this question on stackoverflow without any luck yet:
http://stackoverflow.com/questions/36306505/supertest-restify-gzipresponse-file-upload
I'm getting
TypeError: Cannot read property 'status' of undefined
when attempting to upload a file using supertest to a simple restify server, with gzipResponse turned on.
Versions etc:
$ npm list | grep 'super\|mocha\|restify'
├─┬ [email protected]
├─┬ [email protected]
└─┬ [email protected]
└─┬ [email protected]
$ node -v
v5.5.0
The server:
const restify = require('restify');
const server = restify.createServer();
server.use(restify.gzipResponse());
server.put('image', (req, res) => {
res.send(200);
});
module.exports = server;
The test:
const request = require('supertest');
const server = require('./index');
const path = require('path');
describe('insertImage', function () {
it('should send an image', done => {
request(server)
.put('/image')
.attach('image', path.join(__dirname, 'pc.png'))
.expect(200, done);
});
});
The test will pass when gzipResponse is disabled, and it will also pass if no file is attached.
I'm not sure whether this issue is superagent/supertest related, or whether the problem lies with restify/gzip. Any help is appreciated.
Perhaps there is an issue with gzipping an empty response body? Can you try sending more than just the status code?
server.put('image', (req, res) => {
res.send(200, 'OK!');
});
That still fails the tests, with the same error message.
I tried your test code and cannot repro your issue. I assume you're using mocha, can you run your tests with --full-trace to get the full stack trace? If I had to guess, supertest is probably throwing an assertion somewhere.
You should also be able to test your server directly by using curl, this would tell you if it's an issue with supertest itself or maybe a config somewhere:
$ curl -X PUT -F image=@./pc.png localhost:3000/image
Hi @DonutEspresso,
Here's the full stack trace:
$ mocha test.js --full-trace
insertImage
1) should send an image
double callback!
0 passing (55ms)
1 failing
1) insertImage should send an image:
TypeError: Cannot read property 'status' of undefined
at Test._assertStatus (/home/edo/Desktop/archief/supertest/node_modules/supertest/lib/test.js:229:10)
at Test._assertFunction (/home/edo/Desktop/archief/supertest/node_modules/supertest/lib/test.js:247:11)
at Test.assert (/home/edo/Desktop/archief/supertest/node_modules/supertest/lib/test.js:148:18)
at Server.assert (/home/edo/Desktop/archief/supertest/node_modules/supertest/lib/test.js:127:12)
at Server.g (events.js:273:16)
at emitNone (events.js:85:20)
at Server.emit (events.js:179:7)
at emitCloseNT (net.js:1523:8)
at nextTickCallbackWith1Arg (node.js:463:9)
at process._tickDomainCallback (node.js:426:17)
And yeah, you were right, sending the image using curl totally works! So it should be supertest then, I'll create an issue there.
Hi @edorivai, did you ever get this sorted?
Hi @DonutEspresso, I opened an issue at supertest: https://github.com/visionmedia/supertest/issues/328.
So someone there recreated the test, and couldn't reproduce the problem. I ran his tests, and did have the issue. We haven't resolved it. Anything else I can do to figure this thing out?
Hey @edorivai,
I'd really like to see this resolved but, unfortunately, without having a clear repro case, there isn't much we can do to debug the issue. I've marked this as unconfirmed for now. Have you tried running your test against the 5.x branch?
Hey sorry for the radio silence. I'll take a look tomorrow!
On Sat, Apr 29, 2017, 16:52 William Blankenship notifications@github.com
wrote:
Hey @edorivai https://github.com/edorivai,
I'd really like to see this resolved but, unfortunately, without having a
clear repro case, there isn't much we can do to debug the issue. I've
marked this as unconfirmed for now. Have you tried running your test
against the 5.x branch?—
You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub
https://github.com/restify/node-restify/issues/1054#issuecomment-298173657,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAutrg_vnjBytCwrTqLe6ESCwCVlLo3cks5r006ugaJpZM4H851w
.
I'm afraid the problem still persists on my system. I've put the test in a repo:
https://github.com/edorivai/supertest-restify-upload
The master branch has the old testing setup, the one that corresponds to when I originally created this issue. The v5 branch has updated dependencies (including restify v5), and the test is still failing with the same error. Let me know if you need any other info!
Thanks for the repro case @edorivai!
Just ran through the example using longjohn, which gives stack traces that cross breaks in the event loop.
> @ test /home/wblankenship/Development/supertest-restify-upload
> mocha --full-trace test.js
insertImage
1) should send an image
0 passing (79ms)
1 failing
1) insertImage should send an image:
TypeError: Cannot read property 'status' of undefined
at Test._assertStatus (/home/wblankenship/Development/supertest-restify-upload/node_modules/supertest/lib/test.js:229:10)
at Test._assertFunction (/home/wblankenship/Development/supertest-restify-upload/node_modules/supertest/lib/test.js:247:11)
at Test.assert (/home/wblankenship/Development/supertest-restify-upload/node_modules/supertest/lib/test.js:148:18)
at Server.assert (/home/wblankenship/Development/supertest-restify-upload/node_modules/supertest/lib/test.js:127:12)
at emitNone (events.js:91:20)
at Server.emit (events.js:185:7)
at emitCloseNT (net.js:1554:8)
at _combinedTickCallback (internal/process/next_tick.js:77:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
---------------------------------------------
at Server.once (events.js:302:8)
at Server.close (net.js:1511:12)
at /home/wblankenship/Development/supertest-restify-upload/node_modules/supertest/lib/test.js:122:49
at Test.Request.callback (/home/wblankenship/Development/supertest-restify-upload/node_modules/superagent/lib/node/index.js:687:12)
at ClientRequest.<anonymous> (/home/wblankenship/Development/supertest-restify-upload/node_modules/superagent/lib/node/index.js:639:10)
at emitOne (events.js:101:20)
at ClientRequest.emit (events.js:188:7)
at Socket.socketErrorListener (_http_client.js:309:9)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at emitErrorNT (net.js:1277:8)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
---------------------------------------------
at Test.Request.request (/home/wblankenship/Development/supertest-restify-upload/node_modules/superagent/lib/node/index.js:631:7)
at Test.Request.end (/home/wblankenship/Development/supertest-restify-upload/node_modules/superagent/lib/node/index.js:743:18)
at Test.end (/home/wblankenship/Development/supertest-restify-upload/node_modules/supertest/lib/test.js:121:7)
at Test.expect (/home/wblankenship/Development/supertest-restify-upload/node_modules/supertest/lib/test.js:84:36)
at Context.done (/home/wblankenship/Development/supertest-restify-upload/test.js:12:10)
at callFnAsync (/home/wblankenship/Development/supertest-restify-upload/node_modules/mocha/lib/runnable.js:338:8)
at Test.Runnable.run (/home/wblankenship/Development/supertest-restify-upload/node_modules/mocha/lib/runnable.js:290:7)
at Runner.runTest (/home/wblankenship/Development/supertest-restify-upload/node_modules/mocha/lib/runner.js:422:10)
at /home/wblankenship/Development/supertest-restify-upload/node_modules/mocha/lib/runner.js:533:12
at next (/home/wblankenship/Development/supertest-restify-upload/node_modules/mocha/lib/runner.js:342:14)
at /home/wblankenship/Development/supertest-restify-upload/node_modules/mocha/lib/runner.js:352:7
at next (/home/wblankenship/Development/supertest-restify-upload/node_modules/mocha/lib/runner.js:284:14)
at Immediate.<anonymous> (/home/wblankenship/Development/supertest-restify-upload/node_modules/mocha/lib/runner.js:320:5)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)
It doesn't look like restify is on the path of this exception, I'm fairly certain this issue is down inside of supertest. _assertStatus inside of lib/test.js expects to be given a res object and it doesn't appear one is being passed in. Hope that helps!
@retrohacker Thanks! I'll ping them over there.
Seems like the conversation has stalled in all threads.. Closing this for now, if people still experience the issue and it can be traced back to restify we would be happy to re-open and revisit this :heart: