0

I'm trying to write a mocha test for a sails installable hook (myhook) that is dependent on a particular sails app (myapp). I'd like the bootstrap.test.js to lift myapp with myhook. Thus, I have myapp a devDependency in myhook project.

My bootstrap.test.js has something like this:

var myapp = require('myapp');

// put it in global (special case) for npm test only
global.thehook = require('../api/hooks/myhook/index');

before(function(done) {

  this.timeout(10000);

  console.log("Bootstrap lifting sails...");

  myapp.lift({
      hooks: {
         "myhook": global.thehook,
         "grunt": false
      },
      log: {level: "error"},
  }, function(err) {
      if (err) return done(err);
      // here you can load fixtures, etc.
      done(err, sails);
  });
});
after(function(done) {
  myapp.lower(done);
});

Thinking .lift() and .lower would apply to the sails app. But, that doesn't seem to be the case.

How do I make this work?

eyn
  • 778
  • 2
  • 10
  • 21

1 Answers1

0

You will need to use the sails dependency in place of myapp.

var sails = require('sails');

before(function(done) {
  sails.lift({
    // test configuration
  }, function (error) {
    // ...

    done();
  });
});

after(function(done) {
  sails.lower(function (error) {
    //...

    done();
  });
})

The sails dependency starts in the root of the project directory and will lift the application, so there's no need to require app.js for lifting the app.

Jason
  • 109
  • 4
  • thanks. I've tried this and it doesn't lift myapp, it lifts a generic sails app which does not contain what the hook needs to be fully tested. Or am I misunderstanding something. myapp is a sails app, but it is not in the root of the hook project. – eyn Feb 05 '18 at 11:49