mercredi 3 juin 2015

Loading fixtures in sails tests

The docs just say

// here you can load fixtures, etc.

I've worked out that I can include

var fixtures = require('./fixtures/models.js');

in the bootstrap script, so the full bootstrap script is:

/*
 * Lifts Sails before testing comenses.
 */

var Sails = require('sails');
var sails;

before(function(done) {
  this.timeout(5000);

  Sails.lift({
    // configuration for testing purposes
    environment: 'test',
  }, function(err, server) {
    sails = server;
    if (err) {
      return done(err);
    }

    // here you can load fixtures, etc.
    var fixtures = require('./fixtures/models.js');
    done(err, sails);
  });
});

after(function(done) {
  // here you can clear fixtures, etc.
  Sails.lower(done);
});

I can then reference the fixtures var in the boot script, but I can't reference it in a test. I just get undefined.

Aucun commentaire:

Enregistrer un commentaire