gpt4 book ai didi

node.js - 使用sails-hook-sequelize进行Sails单元测试

转载 作者:行者123 更新时间:2023-12-03 22:28:39 26 4
gpt4 key购买 nike

我在我的 sails-sequelize-hook 应用程序中使用 sails。我正在按照 this 文档为我的应用程序编写我的第一个 Controller 单元测试。我的 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.

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

最佳答案

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

关于node.js - 使用sails-hook-sequelize进行Sails单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38561740/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com