Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikermcneil/aaa901ae1d1eea5866c3 to your computer and use it in GitHub Desktop.
Save mikermcneil/aaa901ae1d1eea5866c3 to your computer and use it in GitHub Desktop.
// Require the default sails singleton (this is the same Sails instance you use globally in your app)
var sails = require('sails');
// setup
before(function(done) {
sails.lift({
// You can customize the port if you want (or use sails.load instead if you are testing using the VRI/sails.request() or just need access to the ORM, etc.)
// port: 4000,
// We usually disable the grunt hook because you don't need it when testing and it slows things down
hooks: {
grunt: false
},
// You might also want to set the log to "silent"-- usually a good idea to leave it on "error" or even "warn" though.
log: {
level: 'error'
},
// Instead of using migrate:drop, you can also use the memory adapter (if you want to test with the actual database, use `migrate: drop` instead.)
connections: {
memory: {
adapter: 'sails-memory'
}
},
models: {
connection: 'memory'
},
// Utility routes to make writing your tests easier
routes: {
// Shortcut route to log user in without using the actual "/me/login" endpoint,
// which has its own test suite.
'GET /_login': function(req, res) {
User.findOne(req.param('id')).exec(function(err, user) {
if (err) return res.serverError();
if (!user) return res.notFound();
var _user = user.toJSON();
req.session.user = _user;
res.ok();
});
},
'GET /_logout': function(req, res) {
delete req.session.user;
return res.ok();
},
// more utility routes here
},
bootstrap: function(cb) {
cb();
// async.auto({
// // Load fixtures here...
// // e.g.
// // users: require('./fixtures/users.js'),
// // pets: require('./fixtures/pets.js'),
// users: require('./fixtures/users')
// }, function (err) {
// if (err) {
// console.error('ERROR IN BOOTSTRAP DURING TESTS:',err);
// return cb(err);
// }
// return cb();
// });
}
}, function(err) {
if (err) {
console.log('ERROR OCCURRED DURING LIFT:', err);
return done(err);
}
return done();
});
});
// teardown
after(function(done) {
// Tear down sails server
sails.lower(function() {
return done();
});
});
@luislobo
Copy link

luislobo commented Feb 4, 2016

Check my fork if you need fixtures

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