是的,我可以在我的摩卡测试中运行process.exit()或--exit,但这似乎是错误的。
我在维护的一些代码中使用了firebase-admin,并且我正在尝试运行mocha测试,但根据wtfnode:
wtfnode node_modules/.bin/_mocha --compilers coffee:coffee-script/registerFirebase负责让我的进程保持打开状态:
- Timers:
- (3300000 ~ 55 min) (anonymous) @ /home/wayne/programming/universe/library/server/node_modu
les/firebase-admin/lib/firebase-app.js:147
- Intervals:
- (45000 ~ 45 s) (anonymous) @ /home/wayne/programming/universe/library/server/node_modules/
firebase-admin/lib/database/database.js:199非常感谢,Firebase。这是令人沮丧的。我可以修复数据库部分:
db = app.database();
db.goOffline();轰隆隆。好了。现在我只看到计时器,不会die.How,我会杀了它吗?我试着看了一下源代码,它将我带到了这个小地方:
FirebaseAppInternals.prototype.setTokenRefreshTimeout = function (delayInMilliseconds, numRetries) {
var _this = this;
this.tokenRefreshTimeout_ = setTimeout(function () {
_this.getToken(/* forceRefresh */ true)
.catch(function (error) {
// Ignore the error since this might just be an intermittent failure. If we really cannot
// refresh the token, an error will be logged once the existing token expires and we try
// to fetch a fresh one.
if (numRetries > 0) {
_this.setTokenRefreshTimeout(60 * 1000, numRetries - 1);
}
});
}, delayInMilliseconds);
};不幸的是,我不确定如何获得tokenRefreshTimeout_,以便我可以cancelTimer。
有没有办法告诉firebase-admin我已经完成了,它真的需要现在停止,或者我坚持使用--exit
发布于 2020-06-30 10:42:02
@Wayne Werner正确回答了他自己的问题。
我为使用firebase管理SDK和firestore的人提供了更多的背景信息。这个GitHub issue帮助回答了我的问题。
您需要确保使用before()在mocha上下文中初始化firebase,然后使用after()在Mocha上下文中删除应用程序
const admin = require("firebase-admin");
describe('', () => {
let app;
let db;
before(async () => {
app = await admin.initializeApp(config);
db = app.firestore();
});
after(() => {
app.app().delete();
});
it('....', async () => {
});
});https://stackoverflow.com/questions/52415214
复制相似问题