node.js - Mocha/Chai 测试失败,因为 oracledb 节点模块耗时太长
问题描述
我有一个初始化 oracledb 连接池的节点 Web 服务。这是我的项目结构
应用程序.ts
import { ConnectionDB } from "./dBConnections/DBConnection";
async function initilizeApp(){
try{
console.log("Initializing Application");
await Promise.all([ ConnectionDB.initilize() ]);
DBConnection.ts
const oracledb = require('oracledb');
export class ConnectionDB{
private constructor(){}
static async initilize(){
try{
await oracledb.createPool({
user: USERNAME,
password: PASSWORD,
connectString: CONNECTION_STRING,
poolMin: 20,
poolMax: 20,
poolIncrement: 0
});
在我的某些模块的代码中,我直接从这样的方法调用 SQL 查询
测试控制器.ts
export class TestControllers{
async getSomething(test: IGetSome){
query = `SELECT * from table;`;
let getS = await ConnectionDB.executeSimpleQuery(query, bind);
现在,当我尝试运行大致这样的测试时
测试类.ts
import {expect} from 'chai';
import {TestController} from '../src/controllers/TestController';
describe("Sample test ", () => {
it('Simple test', async () => {
var x = await getSomething(req);
我收到这个错误
ERROR:ConnectionDB.executeSimpleQuery:Error: NJS-047: poolAlias "default" not found in the connection pool cache
有时我看到对查询的调用在 2000 毫秒或类似的时间后超时。
所以我的问题是两部分。
1> 有没有办法在测试套件开始运行之前建立数据库连接?我尝试了一些随机的事情,包括在 mocha.opts 中添加设置脚本,但似乎没有任何帮助。2> 如果我无法弄清楚数据库连接部分,有没有办法可以模拟这些具有查询的方法,这样我就可以避免运行数据库部分?
如果我要模拟数据库部分,我不确定模块导入将如何工作,因为每当我从测试中导入模块方法并运行它时,它都会默认运行查询。不确定如何为我的代码库编写详尽的测试用例。
解决方案
推荐阅读
- json - JSON Object 的尾随逗号有什么问题
- python - 有没有办法使用 OpenCV 和 Python 返回图像中不同颜色的像素数量的值
- python-3.x - 如何为 Python 生成的 Outlook 电子邮件草稿创建正确的电子邮件地址?
- android - 如何无限期滚动TextView中的长文本
- cordova - ionic cordova run android 失败并出现错误任务':app:processDebugResources'的执行失败
- kendo-ui - KendoUI 中的明细图可行性
- java - 如何在 Firebase Android 中获取所有活动的实时监听器
- python - 使用 numpy 替换数据框值时出错
- perl - Perl 从文件中读取数据并提取某些行内容
- java - 如何从表单中检索我的 jsp Web 项目中的 json obj 值