【问题标题】:Sails unit test with sails-hook-sequelizeSails 单元测试与sails-hook-sequelize
【发布时间】:2016-07-25 07:16:51
【问题描述】:

我在我的sails 应用程序中使用sails-sequelize-hook。我正在关注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.

我在这里缺少什么?我应该提供什么适配器名称?我想我迷路了。

【问题讨论】:

  • 我也遇到了同样的问题,你找到解决方法了吗? Fuking 风帆,我讨厌这该死的胆量。
  • 是的,我做到了。请参考下面我的回答,如果它解决了您的问题,请告诉我
  • 是的,找到了相同的解决方案。谢谢;)

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


【解决方案1】:

把它放在我的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);
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-09
    相关资源
    最近更新 更多