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可以解決呢?
哪些測試運行,你使用不包含查詢?看起來你並沒有等待異步代碼在測試用例退出之前終止。 –