You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to use visionmedia/supertest to test our rendr app, but have a problem: Supertest takes the express app function and creates a server itself, which is convenient:
So, I thought I could test the rendr app like this:
varsupertest=require('supertest'),server=require('../../server/server');//...server.init(function(err){supertest(server.app).get('/products/1').end(function(err,response){// assertions on response heredone(err);});});
This works as long as I only call urls which go to views which do not use models to fetch data. As soon as a fetch is done, it bails because backbone does not have $ and in the stacktrace we see that clientSync is used:
TypeError: Cannot read property 'ajax' of undefined
at Object.Backbone.ajax (/Users/cnr/Documents/dev/lusini/1up-mario/node_modules/rendr/node_modules/backbone/backbone.js:1202:22)
at Object.Backbone.sync (/Users/cnr/Documents/dev/lusini/1up-mario/node_modules/rendr/node_modules/backbone/backbone.js:1185:38)
at clientSync [as sync] (/Users/cnr/Documents/dev/lusini/1up-mario/node_modules/rendr/shared/syncer.js:33:19)
at _.extend.fetch (/Users/cnr/Documents/dev/lusini/1up-mario/node_modules/rendr/node_modules/backbone/backbone.js:442:19)
at Fetcher.fetchFromApi (/Users/cnr/Documents/dev/lusini/1up-mario/node_modules/rendr/shared/fetcher.js:220:9)
at Fetcher.<anonymous> (/Users/cnr/Documents/dev/lusini/1up-mario/node_modules/rendr/shared/fetcher.js:146:14)
at /Users/cnr/Documents/dev/lusini/1up-mario/node_modules/rendr/node_modules/async/lib/async.js:467:25
The only difference between starting the server through index.js and this approach of requiring the server and using server.initServer is that server.start is not called, but I don't understand where this makes a difference:
exports.start=functionstart(options){options=options||{};varport=options.port||3030;app.listen(port);console.log("server pid "+process.pid+" listening on port "+port+" in "+app.settings.env+" mode");}
The text was updated successfully, but these errors were encountered:
We debugged this further down and made sure it is not even a problem with supertest: Starting the server ourselves in index.js like this:
server.init(function(err){varhttpServer=require('http').createServer(server.app).listen();console.log("Running on port"+httpServer.address().port();});
and running it using 'node index.js', we can sucessfully request pages with data. But if we copy that same initialization code into a mocha test:
it('should allow us to test against the running server',function(done){server.init(function(err){varhttpServer=require('http').createServer(server.app).listen();request('http://localhost:'+httpServer.address().port+'/product/foo',function(error,response,body){// assertsdone(err);});});});
Will cause the exception on any request trying to fetch something.
To be clear: All the initialization of rendr seems to work: The routes are matched and our controller is executed and we can make requests against routes which use controllers which do not fetch() when running through mocha, but as soon as fetch is called, it fails.
Okay, got it: We executed unit tests and this functional test in the same test run (which probably is a bad idea anyway, just playing around) and one of our models got included before the server.init() was called.
I'd like to use visionmedia/supertest to test our rendr app, but have a problem: Supertest takes the express app function and creates a server itself, which is convenient:
So, I thought I could test the rendr app like this:
This works as long as I only call urls which go to views which do not use models to fetch data. As soon as a fetch is done, it bails because backbone does not have
$
and in the stacktrace we see thatclientSync
is used:The only difference between starting the server through index.js and this approach of requiring the server and using server.initServer is that server.start is not called, but I don't understand where this makes a difference:
The text was updated successfully, but these errors were encountered: