首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何告诉firebase-admin停止(在运行测试时)?

如何告诉firebase-admin停止(在运行测试时)?
EN

Stack Overflow用户
提问于 2018-09-20 06:55:43
回答 2查看 364关注 0票数 1

是的,我可以在我的摩卡测试中运行process.exit()--exit,但这似乎是错误的。

我在维护的一些代码中使用了firebase-admin,并且我正在尝试运行mocha测试,但根据wtfnode:

代码语言:javascript
复制
wtfnode node_modules/.bin/_mocha --compilers coffee:coffee-script/register

Firebase负责让我的进程保持打开状态:

代码语言:javascript
复制
- 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。这是令人沮丧的。我可以修复数据库部分:

代码语言:javascript
复制
db = app.database();
db.goOffline();

轰隆隆。好了。现在我只看到计时器,不会die.How,我会杀了它吗?我试着看了一下源代码,它将我带到了这个小地方:

代码语言:javascript
复制
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

EN

Stack Overflow用户

发布于 2020-06-30 10:42:02

@Wayne Werner正确回答了他自己的问题。

我为使用firebase管理SDK和firestore的人提供了更多的背景信息。这个GitHub issue帮助回答了我的问题。

您需要确保使用before()在mocha上下文中初始化firebase,然后使用after()在Mocha上下文中删除应用程序

代码语言:javascript
复制
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 () => {
    });
});
票数 2
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52415214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档