Sailing单元测试用sails-hook-sequelize

时间:2016-07-25 07:16:52

标签: node.js sails.js sequelize.js

我在sails-sequelize-hook应用中使用sails。我正在关注this文档,为我的应用程序编写第一个控制器单元测试。我的bootstrap.test.js看起来像这样。

var sails = require('sails');

before(function(done) {

    // Increase the Mocha timeout so that Sails has enough time to lift.
    this.timeout(5000);

    sails.lift({
    }, function(err, server) {
        if (err) return done(err);
        // here you can load fixtures, etc.
        done(err, sails);
    });
});

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

我的联系如下

module.exports.connections = {

    dbTest: {
        user: 'root',
        password: 'root',
        database: 'myappdb',
        options: {
            host: 'localhost',
            dialect: 'mysql',
            pool: {
                max: 5,
                min: 0,
                idle: 10000
            }
        }
    },
}

当我运行npm test时,我收到以下错误

error: In model (myfirstmodel), invalid connection :: { user: 'root',
  password: 'root',
  database: 'myappdb',
  options: 
   { host: 'localhost',
     dialect: 'mysql',
     pool: { max: 5, min: 0, idle: 10000 },
     logging: [Function: _writeLogToConsole] } }
error: Must contain an `adapter` key referencing the adapter to use.
npm ERR! Test failed.  See above for more details.

我在这里缺少什么?我给的是什么适配器名称?我想我已经迷路了。

1 个答案:

答案 0 :(得分:0)

将其放入我的bootstrap.test.js解决了我的问题

var sails = require('sails');

before(function(done) {

    // Increase the Mocha timeout so that Sails has enough time to lift.
    this.timeout(10000);

    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')
        , function(err, server) {
        if (err) return done(err);
        // here you can load fixtures, etc.
        done(err, sails);
    });

});

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