0

When I try to run something as simple as this, I get an error: 'static() root path required'.

If only one 'it' is run, it will pass.

Anyone knows what's the catch?

var Sails = require('sails');

describe("Crud tests:", function() {

    var app;

    beforeEach(function(done) {
        // Lift Sails and start the server
        Sails.lift({
                log: {
                    level: 'error'
                },
            }, function(err, sails) {
                console.log("sails lifted");
                app = sails;
                done(err, sails);
            });
    });

    afterEach(function(done) {
        Sails.lower(done);
        console.log('sails down');
    });


    it("1", function(done) {
        expect(1).toEqual(1);
        done();
    });

    it("2", function (done) {
        expect(2).toEqual(2);
        done();
    });

});
gazdac
  • 189
  • 2
  • 11

2 Answers2

0

See https://github.com/balderdashy/sails/issues/1860, quoted below:

Looking at the core tests, even in the ones where we lift / lower for each individual test, it's always with a fresh instance of Sails. I don't think a lot of testing has gone into lowering / re-lifting the same instance, and I wouldn't be shocked to find out that some globals are hanging around that screw up the lift sequence. So unless there's a reason why you need it to be the same Sails, rather than a new Sails with the same options, I'd follow the example of the core tests and create a fresh instance. To do so, you require the Sails factory, instead of the full Sails module:

var Sails = require('Sails/lib/app') 
var sailsInstance = new Sails();
sailsInstance.lift(...);
sgress454
  • 24,870
  • 4
  • 74
  • 92
  • Tried that approach, and at the first glance it behaves the same. Will try to debug it and see if something else is causing this. Which test framework you recommend? It doesn't have to be Jasmine at all - I just need a solid and documented way to do proper testing. – gazdac Jun 26 '14 at 18:52
  • Hi, thanks for the quick answer. Here are some details about the approach above - new error this time, on a newly created sails app with a single controller/model called 'lol': http://i.imgur.com/KtqkgtB.png?1 – gazdac Jun 26 '14 at 19:27
  • You're still using the same instance for each test. Put the `sailsInstance = new Sails()` *inside* the `beforeEach` function. – sgress454 Jun 26 '14 at 21:26
  • just wanted to let you know - I was able to start from scratch with your testing docs for mocha without any problems - without even needing to use sailsInstance and lifting before each test. Mocha obviously plays well with Sails. Only problem I had/have is with that bootstrap test file you guys mentioned, but I don't even need to bother with it, because when I place it all in a spec file, it works flawlessly. – gazdac Jul 05 '14 at 09:48
0

I think that the sails v0.10 should be lifted differently. The code bellow is from my project which runs on rc9.

# test/support/sails.coffee

process.env.NODE_ENV = 'test'
process.env.PORT = 1338

Sails = require('sails/lib/app')
app = Sails()

beforeEach (done) ->
  app.lift 
    models: 
      migrate: 'drop' # rebuild database (optional)
  , done

afterEach (done) ->
  app.lower done

describe ...

I hope it helps.

xpepermint
  • 35,055
  • 30
  • 109
  • 163