0

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.

Dida
  • 941
  • 1
  • 9
  • 22

1 Answers1

1

The example you're referring to was updated for the new Barrels API and it's passing the tests.

Otherwise, check if the objects are in the fixtures variable: if it's empty, make sure you're providing the correct path to the JSON files (you're passing process.cwd() + '/tests/fixtures', but your helper is in <Project>/test/specHelper.js, also, you have <Project>/tests/EntitySpec.js; is it test or tests?).

If the fixtures are present, make sure you're passing the correct configuration to Sails.lift and your connection is configured correctly (see the mentioned example for details).

bredikhin
  • 8,875
  • 3
  • 40
  • 44
  • Thanks for answering. Understand it was updated. I also stated that is also based on the updated one. The `fixtures` variable is not empty so the setup path is correct (it is in `tests`). As for `Sails.lift` configuration, I follow the same config as the [Barrels's test setup](https://github.com/bredikhin/barrels/blob/master/test/index.test.js) – Dida Sep 19 '14 at 04:14
  • I updated the example just yesterday, after reading your question, so yours couldn't be based on the updated one. Check it out. Also, make sure you're using Waterline's promise API properly: try using `exec` instead of `then` (http://sailsjs.org/#/documentation/concepts/ORM/Models.html?q=using-models). – bredikhin Sep 19 '14 at 12:11