如何使用 Scheduler Extension 为 Probot 正确配置单元测试?

How to correctly configure unit tests for Probot with Scheduler Extension?

我正在使用以下最小的 probot 应用程序并尝试为其编写 Mocha 单元测试。

不幸的是,它导致以下错误,这表明我的一些私钥或安全令牌设置没有被提取。

我假设我的 .env 文件的配置是正确的,因为当我通过 probot-run.js.

启动 probot 时我没有得到同样的错误

与 Mocha 一起使用时,是否需要任何额外的步骤来配置 probot? 关于为什么使用调度程序扩展可能会导致此类问题的任何建议都很好。

下面的代码和错误:

app.ts

import createScheduler from "probot-scheduler";
import { Application } from "probot";

export = (app: Application) => {

  createScheduler(app, {
    delay: !!process.env.DISABLE_DELAY, // delay is enabled on first run
    interval: 24 * 60 * 60 * 1000 // 1 day
  });

  app.on("schedule.repository", async function (context) {
    app.log.info("schedule.repository");
    const result = await context.github.pullRequests.list({owner: "owner", repo: "test"});
    app.log.info(result);
  });
};

test.ts

import createApp from "../src/app";

import nock from "nock";
import { Probot } from "probot";

nock.disableNetConnect();

describe("my scenario", function() {
  let probot: Probot;
  beforeEach(function() {
    probot = new Probot({});
    const app = probot.load(createApp);
  });

  it("basic feature", async function() {
    await probot.receive({name: "schedule.repository", payload: {action: "foo"}});
  });
});

不幸的是,这会导致以下错误:

 Error: secretOrPrivateKey must have a value
  at Object.module.exports [as sign] (node_modules/jsonwebtoken/sign.js:101:20)
  at Application.app (node_modules/probot/lib/github-app.js:15:39)
  at Application.<anonymous> (node_modules/probot/lib/application.js:260:72)
  at step (node_modules/probot/lib/application.js:40:23)
  at Object.next (node_modules/probot/lib/application.js:21:53)

事实证明,new Probot({}); 按照文档中的建议初始化了没有任何参数的 Probot 对象(给定的选项对象 {} 毕竟是空的)。

为避免错误,可以手动提供信息:

new Probot({
  cert: "...",
  secret: "...",
  id: 12345
});