0
我有2个数据库;第一个用于开发和生产,第二个用于测试。 knexfile.js:如何设置另一个数据库以测试knexfile?
const config = require('config');
const knexConfig = config.get('knexConfig');
module.exports = {
development: {
client: knexConfig.client,
connection: {
host: knexConfig.host,
database: knexConfig.database,
user: knexConfig.user,
password: knexConfig.password,
},
pool: {
min: knexConfig.min,
max: knexConfig.max,
},
},
test: {
client: 'sqlite3',
connection: {
filename: './file.db',
},
},
};
route.test.js:
const的模型=要求( '异议')模型;
const provider = require('../../../server/models/provider');
const Knex = require('knex');
const knexConfig = require('../../../knexfile');
const knex = Knex(knexConfig.test);
Model.knex(knex);
describe('Should test provider Model',() => {
test('should return provider',() => {
provider
.query()
.then((providers) => {
expect(providers).toBe('array');
});
});
});
我得到这个错误:
Test suite failed to run
ProcessTerminatedError: cancel after 2 retries!
at Farm.<anonymous> (node_modules/worker-farm/lib/farm.js:87:25)
at Array.forEach (<anonymous>)
at Farm.<anonymous> (node_modules/worker-farm/lib/farm.js:81:36)
at ontimeout (timers.js:469:11)
at tryOnTimeout (timers.js:304:5)
at Timer.listOnTimeout (timers.js:264:5)
A worker process has quit unexpectedly! Most likely this is an initialization error.
我想连接到SQLite数据库的测试,但我不能这样做,通过我tests.How可以解决呢?
哪些测试运行,你使用不包含查询?看起来你并没有等待异步代码在测试用例退出之前终止。 –