1

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

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

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

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

下面的代码和错误:

应用程序.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);
  });
};

测试.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)
4

1 回答 1

0

事实证明,new Probot({});正如文档中所建议的那样,在没有任何参数的情况下初始化 Probot 对象(给定的选项对象{}毕竟是空的)。

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

new Probot({
  cert: "...",
  secret: "...",
  id: 12345
});
于 2018-12-04T21:51:24.783 回答