Reputation: 4029
I wrote the some unit test in sails with waterline(defaultI orm) That's working fine, but when I tried with sequelize orm I'm getting the error.
I'm using the following:
My Folder structure is:
./myApp ├── api ├── assets ├── ... ├── test │ ├── unit │ │ ├── controllers │ │ │ └── UsersController.test.js │ │ ├── models │ │ │ └── Users.test.js │ │ └── ... │ ├── fixtures │ ├── ... │ ├── bootstrap.test.js │ └── mocha.opts └── views
my bootstrap.test.js file is:
var Sails = require('sails'),sails;
before(function(done) {
this.timeout(5000);
Sails.lift({
}, function(err, server) {
sails = server;
if (err) return done(err);
done(err, sails);
});
});
after(function(done) {
Sails.lower(done);
});
my connection/config file is:
somePostgresqlServer: {
user: 'postgres',
password: 'mypassword',
database: 'postgres',
dialect: 'postgres',
options: {
dialect: 'postgres',
host : 'localhost',
port : 5432,
logging: true
}
}
and in config/model.js file is:
connection:"somePostgresqlServer"
and my .sailsrc is :
"hooks": {
"blueprints": false,
"orm": false,
"pubsub": false
}
I wrote some test in User.test.js
when I'm running the mocha test/bootstrap.test.js test/unit/**/*.test.js
I'm getting the error:
error: In model (user), invalid connection :: { user: 'postgres',
password: 'mypassword',
database: 'postgres',
dialect: 'postgres',
options:
{ dialect: 'postgres',
host: 'localhost',
port: 5432,
logging: [Function: _writeLogToConsole] } }
error: Must contain an `adapter` key referencing the adapter to use.
npm ERR! Test failed. See above for more details.
what I'm doing the wrong any Idea.
Upvotes: 3
Views: 564
Reputation: 358
Alexis N-o's question is actually a good hint.
if you have a look in app.js (the one sails generated). It will load rc before trying to lift :) So just add the same code in your test bootstrap js will fix it.
var rc;
try {
rc = require('rc');
} catch (e0) {
try {
rc = require('sails/node_modules/rc');
} catch (e1) {
console.error('Could not find dependency: `rc`.');
console.error('Your `.sailsrc` file(s) will be ignored.');
console.error('To resolve this, run:');
console.error('npm install rc --save');
rc = function () { return {}; };
}
}
// Start server
sails.lift(rc('sails'));
Upvotes: 2