Starting from this example (using Sails 0.9.x) from the Barrels author himself with slight modification based on in Barrels' repo (using Sails 0.10.x) and my project setup, here's my configuration:
<Project>/test/specHelper.js
(which is the test bootstrap):
'use strict';
var Sails = require('sails')
, Barrels = require('barrels')
, barrels, fixtures;
before(function(done) {
Sails.lift(
{
// Configuration for testing
environment: 'test',
log: {
level: 'error'
},
connections: {
test: {
adapter: 'sails-memory'
}
},
models: {
connection: 'test'
},
port: 98765
},
function(err, sails) {
if (err)
return done(err);
// Load fixtures
barrels = new Barrels(process.cwd() + '/tests/fixtures');
fixtures = barrels.data;
barrels.populate(function(err) {
done(err, sails);
});
}
);
});
after(function(done) {
// Clear fixtures, etc.
Sails.lower(done);
});
and here's a spec file <Project>/tests/EntitySpec.js
var chai = require('chai');
, expect = chai.expect;
describe('Entity', function() {
describe('class methods', function() {
describe('#a_method', function() {
it('does something', function(done) {
Entity.find().then(function(results) {
console.log('in database', results);
done();
}).catch(done);
});
});
});
});
But the test database is empty. Running barrels.populate
in the spec file doesn't solve this (though specs doesn't throw any error). I'm open for other fixture solution for Sails.js. Thanks.