Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unit testing with sails.js using sequelize.js

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:

  1. sequelize orm
  2. sails-sequelize-hook
  3. mocha and chai
  4. supertest
  5. "pg-hstore": "^2.3.2"
  6. "pg": "^4.4.1"

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.

like image 710
Vishnu Mishra Avatar asked Dec 02 '25 16:12

Vishnu Mishra


1 Answers

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'));
like image 156
Ming Avatar answered Dec 04 '25 06:12

Ming



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!