node.js - How to generate a payload at runtime for a request in javascript? -
i'm new javascript/nodejs , need test payload within limits of 4mb via mocha/nodejs , i've used function generate string of characters of length ~4mb+ simulate payload , pass within request payload. however, i'm getting timeout exception error: timeout of 2000ms exceeded. async tests , hooks, ensure "done()" called; if returning promise, ensure resolves.. because approach not valid request generation taking long ... tried increasing wait time in vain.
it('expected: handle request made payload exceeding request_limit of 4mb', (done) => { chai.request(server).post('/payload').send({ data: payload(4520000) }) // payload exceeds rate_limit of 4mb .set('content-type', 'plain/text') .end((error, response) => { expect(response).to.have.status(500); // return expect(response).to.eventually.have.status(500); done(); }); }); note have used chai-as-promised , didn't work me:
return expect(response).to.eventually.have.status(500);
i recommend returning promise chai.request produces , not using done @ because complicate error handling you:
it('expected: handle request made payload exceeding request_limit of 4mb', () => chai.request(server).post('/payload').send({ data: payload(4520000) }) .set('content-type', 'plain/text') .end((error, response) => { expect(response).to.have.status(500); })); (i've used "concise body" instead of "block body" arrow function above. return implied.)
if need increase timeout because payload generation takes long, you'd have change above proper function , use this.timeout(....) value large enough.
Comments
Post a Comment